Search in sources :

Example 1 with InputStreamBuffered

use of org.apache.jena.atlas.io.InputStreamBuffered in project jena by apache.

the class TestInputStreamBuffered method test_01.

@Test
public void test_01() throws IOException {
    InputStream in = stream("");
    InputStream in2 = new InputStreamBuffered(in);
    int x = count(in2);
    assertEquals(0, x);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamBuffered(org.apache.jena.atlas.io.InputStreamBuffered) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 2 with InputStreamBuffered

use of org.apache.jena.atlas.io.InputStreamBuffered in project jena by apache.

the class TestInputStreamBuffered method test_02.

@Test
public void test_02() throws IOException {
    InputStream in = stream(1, 2, 3, 4);
    InputStream in2 = new InputStreamBuffered(in);
    check(in2, 1, 2, 3, 4);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamBuffered(org.apache.jena.atlas.io.InputStreamBuffered) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 3 with InputStreamBuffered

use of org.apache.jena.atlas.io.InputStreamBuffered in project jena by apache.

the class TestInputStreamBuffered method test_03.

@Test
public void test_03() throws IOException {
    InputStream in = stream(1, 2, 3, 4);
    InputStream in2 = new InputStreamBuffered(in, 2);
    check(in2, 1, 2, 3, 4);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamBuffered(org.apache.jena.atlas.io.InputStreamBuffered) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 4 with InputStreamBuffered

use of org.apache.jena.atlas.io.InputStreamBuffered in project jena by apache.

the class utf8 method main.

/** Simple program to help hunt down bad UTF-8 encoded characters */
public static void main(String[] args) {
    long INIT_LINE = 1;
    long INIT_COL = 1;
    if (args.length == 0)
        args = new String[] { "-" };
    String label = "";
    for (String fn : args) {
        if (args.length > 1)
            label = fn + ": ";
        InputStream in = IO.openFile(fn);
        in = new InputStreamBuffered(in);
        long charCount = 0;
        long lineNum = INIT_LINE;
        long colNum = INIT_COL;
        InStreamUTF8 utf8 = null;
        try {
            utf8 = new InStreamUTF8(in);
            for (; ; ) {
                int ch = utf8.read();
                if (ch == -1)
                    break;
                charCount++;
                if (ch == '\n') {
                    lineNum++;
                    colNum = INIT_COL;
                } else
                    colNum++;
                if (!Character.isDefined(ch))
                    throw new AtlasException(String.format("No such codepoint: 0x%04X", ch));
            }
            System.out.printf("%s: chars = %d , lines = %d\n", fn, charCount, lineNum);
        } catch (AtlasException ex) {
            System.out.printf(label + "[line=%d, col=%d] %s\n", lineNum, colNum, ex.getMessage());
        } finally {
            IO.close(utf8);
        }
    }
}
Also used : InputStream(java.io.InputStream) InputStreamBuffered(org.apache.jena.atlas.io.InputStreamBuffered) AtlasException(org.apache.jena.atlas.AtlasException) InStreamUTF8(org.apache.jena.atlas.io.InStreamUTF8)

Example 5 with InputStreamBuffered

use of org.apache.jena.atlas.io.InputStreamBuffered in project jena by apache.

the class TestInputStreamBuffered method test_04.

@Test
public void test_04() throws IOException {
    InputStream in = stream(1, 2, 3, 4);
    InputStream in2 = new InputStreamBuffered(in, 1);
    check(in2, 1, 2, 3, 4);
    assertEquals(-1, in.read());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamBuffered(org.apache.jena.atlas.io.InputStreamBuffered) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)5 InputStreamBuffered (org.apache.jena.atlas.io.InputStreamBuffered)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BaseTest (org.apache.jena.atlas.junit.BaseTest)4 Test (org.junit.Test)4 AtlasException (org.apache.jena.atlas.AtlasException)1 InStreamUTF8 (org.apache.jena.atlas.io.InStreamUTF8)1