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;
}
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);
}
}
}
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;
}
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);
}
}
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
}
}
Aggregations