Search in sources :

Example 1 with PeekReader

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);
}
Also used : PeekReader(org.apache.jena.atlas.io.PeekReader)

Example 2 with PeekReader

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());
}
Also used : PeekReader(org.apache.jena.atlas.io.PeekReader)

Example 3 with PeekReader

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());
}
Also used : PeekReader(org.apache.jena.atlas.io.PeekReader) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 4 with PeekReader

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");
}
Also used : PeekReader(org.apache.jena.atlas.io.PeekReader) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 5 with PeekReader

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);
}
Also used : PeekReader(org.apache.jena.atlas.io.PeekReader) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

PeekReader (org.apache.jena.atlas.io.PeekReader)22 BaseTest (org.apache.jena.atlas.junit.BaseTest)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)1 RiotException (org.apache.jena.riot.RiotException)1