Search in sources :

Example 41 with StringReader

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());
}
Also used : StringReader(java.io.StringReader) File(java.io.File)

Example 42 with StringReader

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) StringReader(java.io.StringReader) IOException(java.io.IOException) Properties(java.util.Properties)

Example 43 with StringReader

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);
    }
}
Also used : UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper) StringReader(java.io.StringReader)

Example 44 with StringReader

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]);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) IOException(java.io.IOException) LexerNoViableAltException(org.antlr.v4.runtime.LexerNoViableAltException) StringReader(java.io.StringReader) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 45 with StringReader

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();
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120