use of org.apache.jena.atlas.io.PeekReader in project jena by apache.
the class JSONParser method parse.
/** Parse to get a Json object */
public static void parse(InputStream input, JSONHandler handler) {
PeekReader r = PeekReader.makeUTF8(input);
TokenizerJSON t = new TokenizerJSON(r);
parse(t, handler);
}
use of org.apache.jena.atlas.io.PeekReader in project jena by apache.
the class AbstractTestPeekReader method position.
private void position(String contents) {
PeekReader r = make(contents);
int line = INIT_LINE;
int col = INIT_COL;
checkLineCol(r, line, col);
assertEquals(0, r.getPosition());
for (int i = 0; i < contents.length(); i++) {
int x = r.readChar();
if (x != -1) {
if (x == '\n') {
line++;
col = INIT_COL;
} else
col++;
}
assertEquals(contents.charAt(i), x);
assertEquals(i + 1, r.getPosition());
checkLineCol(r, line, col);
}
assertTrue(r.eof());
}
use of org.apache.jena.atlas.io.PeekReader in project jena by apache.
the class AbstractTestPeekReader method read3.
@Test
public void read3() {
String c = "abcde";
PeekReader r = make(c);
for (int i = 0; i < c.length(); i++) {
checkLineCol(r, INIT_LINE, i + INIT_COL);
assertEquals(i, r.getPosition());
assertEquals(c.charAt(i), r.readChar());
}
assertTrue(r.eof());
}
use of org.apache.jena.atlas.io.PeekReader in project jena by apache.
the class AbstractTestPeekReader method unread1.
@Test
public void unread1() {
PeekReader r = make("abc");
assertEquals('a', r.peekChar());
r.pushbackChar('Z');
assertEquals('Z', r.peekChar());
contains(r, "Zabc");
}
use of org.apache.jena.atlas.io.PeekReader in project jena by apache.
the class AbstractTestPeekReader method read2.
@Test
public void read2() {
// Assumes we start at (1,1)
PeekReader r = make("a");
checkLineCol(r, INIT_LINE, INIT_COL);
int x = r.peekChar();
assertEquals('a', x);
checkLineCol(r, INIT_LINE, INIT_COL);
x = r.readChar();
checkLineCol(r, INIT_LINE, INIT_COL + 1);
assertEquals('a', x);
x = r.peekChar();
assertEquals(-1, x);
x = r.readChar();
assertEquals(-1, x);
}
Aggregations