Search in sources :

Example 1 with ReusableStringReader

use of org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader in project hive by apache.

the class TestReusableStringReader method testSkip.

@Test
public void testSkip() throws IOException {
    Reader reader = new ReusableStringReader();
    ((ReusableStringReader) reader).set(fox);
    // skip entire the data:
    long skipped = reader.skip(fox.length() + 1);
    assertEquals(fox.length(), skipped);
    assertEquals(-1, reader.read());
    // reset the data
    ((ReusableStringReader) reader).set(fox);
    char[] cc = new char[6];
    int read;
    read = reader.read(cc);
    assertEquals(6, read);
    assertEquals("Quick ", new String(cc));
    // skip some piece of data:
    skipped = reader.skip(30);
    assertEquals(30, skipped);
    read = reader.read(cc);
    assertEquals(4, read);
    assertEquals("dog.", new String(cc, 0, read));
    // skip when already at EOF:
    skipped = reader.skip(300);
    assertEquals(0, skipped);
    assertEquals(-1, reader.read());
    reader.close();
}
Also used : ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) Reader(java.io.Reader) Test(org.junit.Test)

Example 2 with ReusableStringReader

use of org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader in project hive by apache.

the class TestReusableStringReader method testEmpty.

/**
 * Test empty {@link ReusableStringReader}
 */
@Test
public void testEmpty() throws IOException {
    Reader reader = new ReusableStringReader();
    try {
        int ch = reader.read();
        fail("IOException expected.");
    } catch (IOException ioe) {
    // expected
    }
    try {
        boolean ready = reader.ready();
        fail("IOException expected.");
    } catch (IOException ioe) {
    // expected
    }
    reader.close();
}
Also used : ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) Reader(java.io.Reader) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ReusableStringReader

use of org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader in project hive by apache.

the class TestReusableStringReader method testMarkReset.

@Test
public void testMarkReset() throws IOException {
    Reader reader = new ReusableStringReader();
    if (reader.markSupported()) {
        ((ReusableStringReader) reader).set(fox);
        assertTrue(reader.ready());
        char[] cc = new char[6];
        int read;
        read = reader.read(cc);
        assertEquals(6, read);
        assertEquals("Quick ", new String(cc));
        reader.mark(100);
        read = reader.read(cc);
        assertEquals(6, read);
        assertEquals("brown ", new String(cc));
        reader.reset();
        read = reader.read(cc);
        assertEquals(6, read);
        assertEquals("brown ", new String(cc));
    }
    reader.close();
}
Also used : ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) ReusableStringReader(org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader) Reader(java.io.Reader) Test(org.junit.Test)

Aggregations

Reader (java.io.Reader)3 ReusableStringReader (org.apache.hadoop.hive.ql.udf.xml.UDFXPathUtil.ReusableStringReader)3 Test (org.junit.Test)3 IOException (java.io.IOException)1