use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testparseBackupSchemeFromXml_onlyInclude.
public void testparseBackupSchemeFromXml_onlyInclude() throws Exception {
mXpp.setInput(new StringReader("<full-backup-content>" + "<include path=\"onlyInclude.txt\" domain=\"file\"/>" + "</full-backup-content>"));
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
assertEquals("Excluding files when there was no <exclude/> tag.", 0, excludesSet.size());
assertEquals("Unexpected number of <include/>s", 1, includeMap.size());
Set<String> fileDomainIncludes = includeMap.get(FullBackup.FILES_TREE_TOKEN);
assertEquals("Didn't find expected file domain include.", 1, fileDomainIncludes.size());
assertEquals("Invalid path parsed for <include/>", new File(mContext.getFilesDir(), "onlyInclude.txt").getCanonicalPath(), fileDomainIncludes.iterator().next());
}
use of java.io.StringReader in project platformlayer by platformlayer.
the class ConfigMap method read.
public static Properties read(OpsTarget target, File path) throws OpsException {
String contents = target.readTextFile(path);
if (contents == null) {
return null;
}
Properties properties = new Properties();
try {
properties.load(new StringReader(contents));
} catch (IOException e) {
throw new OpsException("Error reading properties file: " + path, e);
}
// return new ConfigMap(properties);
return properties;
}
use of java.io.StringReader in project platformlayer by platformlayer.
the class CloneHelpers method cloneViaJaxb.
public static <T> T cloneViaJaxb(T o) {
try {
Class<T> objectClass = (Class<T>) o.getClass();
JaxbHelper jaxbHelper = JaxbHelper.get(objectClass);
String xml = JaxbHelper.toXml(o, false);
return jaxbHelper.deserialize(new StringReader(xml), objectClass);
} catch (UnmarshalException e) {
throw new IllegalStateException("Error while cloning object", e);
} catch (JAXBException e) {
throw new IllegalStateException("Error while cloning object", e);
}
}
use of java.io.StringReader in project antlr4 by antlr.
the class XPath method split.
// TODO: check for invalid token/rule names, bad syntax
public XPathElement[] split(String path) {
ANTLRInputStream in;
try {
in = new ANTLRInputStream(new StringReader(path));
} catch (IOException ioe) {
throw new IllegalArgumentException("Could not read path: " + path, ioe);
}
XPathLexer lexer = new XPathLexer(in) {
@Override
public void recover(LexerNoViableAltException e) {
throw e;
}
};
lexer.removeErrorListeners();
lexer.addErrorListener(new XPathLexerErrorListener());
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
try {
tokenStream.fill();
} catch (LexerNoViableAltException e) {
int pos = lexer.getCharPositionInLine();
String msg = "Invalid tokens or characters at index " + pos + " in path '" + path + "'";
throw new IllegalArgumentException(msg, e);
}
List<Token> tokens = tokenStream.getTokens();
// System.out.println("path="+path+"=>"+tokens);
List<XPathElement> elements = new ArrayList<XPathElement>();
int n = tokens.size();
int i = 0;
loop: while (i < n) {
Token el = tokens.get(i);
Token next = null;
switch(el.getType()) {
case XPathLexer.ROOT:
case XPathLexer.ANYWHERE:
boolean anywhere = el.getType() == XPathLexer.ANYWHERE;
i++;
next = tokens.get(i);
boolean invert = next.getType() == XPathLexer.BANG;
if (invert) {
i++;
next = tokens.get(i);
}
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
i++;
break;
case XPathLexer.TOKEN_REF:
case XPathLexer.RULE_REF:
case XPathLexer.WILDCARD:
elements.add(getXPathElement(el, false));
i++;
break;
case Token.EOF:
break loop;
default:
throw new IllegalArgumentException("Unknowth path element " + el);
}
}
return elements.toArray(new XPathElement[0]);
}
use of java.io.StringReader in project platform_frameworks_base by android.
the class BaseTestRunner method getFilteredTrace.
// END android-changed
/**
* Filters stack frames from internal JUnit classes
*/
public static String getFilteredTrace(String stack) {
if (showStackRaw())
return stack;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
StringReader sr = new StringReader(stack);
// BEGIN android-changed
// Use a sensible default buffer size
BufferedReader br = new BufferedReader(sr, 1000);
// END android-changed
String line;
try {
while ((line = br.readLine()) != null) {
if (!filterLine(line))
pw.println(line);
}
} catch (Exception IOException) {
// return the stack unfiltered
return stack;
}
return sw.toString();
}
Aggregations