Search in sources :

Example 16 with PushbackReader

use of java.io.PushbackReader in project zm-mailbox by Zimbra.

the class BodyTest method contains.

private boolean contains(Reader reader, boolean caseSensitive, String substring) throws IOException {
    int matchIndex = 0;
    if (!caseSensitive)
        substring = substring.toLowerCase();
    PushbackReader pb = new PushbackReader(reader, substring.length());
    char[] substringArray = substring.toCharArray();
    int c;
    while ((c = getNextChar(pb)) > 0) {
        if ((!caseSensitive && substring.charAt(matchIndex) == Character.toLowerCase(c)) || (caseSensitive && substring.charAt(matchIndex) == c)) {
            matchIndex++;
            if (matchIndex == substring.length())
                return true;
        } else if (matchIndex > 0) {
            // unread this non-matching char
            pb.unread(c);
            // unread matched chars except the first char that matched
            pb.unread(substringArray, 1, matchIndex - 1);
            matchIndex = 0;
        }
    }
    return false;
}
Also used : PushbackReader(java.io.PushbackReader)

Example 17 with PushbackReader

use of java.io.PushbackReader in project gerrit by GerritCodeReview.

the class PrologTestCase method consult.

protected void consult(BufferingPrologControl env, Class<?> clazz, String prologResource) throws CompileException, IOException {
    try (InputStream in = clazz.getResourceAsStream(prologResource)) {
        if (in == null) {
            throw new FileNotFoundException(prologResource);
        }
        SymbolTerm pathTerm = SymbolTerm.create(prologResource);
        JavaObjectTerm inTerm = new JavaObjectTerm(new PushbackReader(new BufferedReader(new InputStreamReader(in, UTF_8)), Prolog.PUSHBACK_SIZE));
        if (!env.execute(Prolog.BUILTIN, "consult_stream", pathTerm, inTerm)) {
            throw new CompileException("Cannot consult " + prologResource);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) CompileException(com.googlecode.prolog_cafe.exceptions.CompileException) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) PushbackReader(java.io.PushbackReader)

Example 18 with PushbackReader

use of java.io.PushbackReader in project chipKIT32-MAX by chipKIT32.

the class StdXMLReader method startNewStream.

/**
    * Starts a new stream from a Java reader. The new stream is used
    * temporary to read data from. If that stream is exhausted, control
    * returns to the parent stream.
    *
    * @param reader the non-null reader to read the new data from
    * @param isInternalEntity true if the reader is produced by resolving
    *                         an internal entity
    */
public void startNewStream(Reader reader, boolean isInternalEntity) {
    StackedReader oldReader = this.currentReader;
    this.readers.push(this.currentReader);
    this.currentReader = new StackedReader();
    if (isInternalEntity) {
        this.currentReader.lineReader = null;
        this.currentReader.pbReader = new PushbackReader(reader, 2);
    } else {
        this.currentReader.lineReader = new LineNumberReader(reader);
        this.currentReader.pbReader = new PushbackReader(this.currentReader.lineReader, 2);
    }
    this.currentReader.systemId = oldReader.systemId;
    this.currentReader.publicId = oldReader.publicId;
}
Also used : PushbackReader(java.io.PushbackReader) LineNumberReader(java.io.LineNumberReader)

Example 19 with PushbackReader

use of java.io.PushbackReader in project processdash by dtuma.

the class FindLastExpression method compileVal.

public static PValue compileVal(String expression) throws CompilationException {
    try {
        // Create a Parser instance.
        Parser p = new Parser(new Lexer(new PushbackReader(new StringReader("[foo] = " + expression + ";"), 1024)));
        // Parse the input
        Start tree = p.parse();
        // get the expression and return it
        FindLastExpression search = new FindLastExpression();
        tree.apply(search);
        return search.expression;
    } catch (Exception e) {
        throw new CompilationException("Error while compiling: " + e);
    }
}
Also used : Lexer(net.sourceforge.processdash.data.compiler.lexer.Lexer) StringReader(java.io.StringReader) Parser(net.sourceforge.processdash.data.compiler.parser.Parser) PushbackReader(java.io.PushbackReader)

Example 20 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_skip$J.

/**
     * @throws IOException
     * java.io.PushbackReader#skip(long)
     */
public void test_skip$J() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying);
    tobj.skip(6);
    tobj.skip(1000000);
    tobj.skip(1000000);
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.skip(1);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Aggregations

PushbackReader (java.io.PushbackReader)37 IOException (java.io.IOException)22 StringReader (java.io.StringReader)12 CompileException (com.googlecode.prolog_cafe.exceptions.CompileException)3 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)3 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)2 FileNotFoundException (java.io.FileNotFoundException)2 LineNumberReader (java.io.LineNumberReader)2 Lexer (net.sourceforge.processdash.data.compiler.lexer.Lexer)2 Parser (net.sourceforge.processdash.data.compiler.parser.Parser)2 SyntaxException (com.googlecode.prolog_cafe.exceptions.SyntaxException)1 TermException (com.googlecode.prolog_cafe.exceptions.TermException)1 BufferingPrologControl (com.googlecode.prolog_cafe.lang.BufferingPrologControl)1 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1