Search in sources :

Example 11 with CountingInputStream

use of com.google.common.io.CountingInputStream in project hbase by apache.

the class TestCellCodec method testEmptyWorks.

@Test
public void testEmptyWorks() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    Codec codec = new CellCodec();
    Codec.Encoder encoder = codec.getEncoder(dos);
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    assertEquals(0, offset);
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = codec.getDecoder(dis);
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(0, cis.getCount());
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CountingInputStream(com.google.common.io.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 12 with CountingInputStream

use of com.google.common.io.CountingInputStream in project hbase by apache.

the class TestCellCodec method testThree.

@Test
public void testThree() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    Codec codec = new CellCodec();
    Codec.Encoder encoder = codec.getEncoder(dos);
    final KeyValue kv1 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
    final KeyValue kv2 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
    final KeyValue kv3 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
    encoder.write(kv1);
    encoder.write(kv2);
    encoder.write(kv3);
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = codec.getDecoder(dis);
    assertTrue(decoder.advance());
    Cell c = decoder.current();
    assertTrue(CellUtil.equals(c, kv1));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellUtil.equals(c, kv2));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellUtil.equals(c, kv3));
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(offset, cis.getCount());
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) DataOutputStream(java.io.DataOutputStream) CountingInputStream(com.google.common.io.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) CountingOutputStream(com.google.common.io.CountingOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 13 with CountingInputStream

use of com.google.common.io.CountingInputStream in project hbase by apache.

the class TestCellCodec method testOne.

@Test
public void testOne() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    Codec codec = new CellCodec();
    Codec.Encoder encoder = codec.getEncoder(dos);
    final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
    kv.setSequenceId(Long.MAX_VALUE);
    encoder.write(kv);
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = codec.getDecoder(dis);
    // First read should pull in the KV
    assertTrue(decoder.advance());
    // Second read should trip over the end-of-stream marker and return false
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(offset, cis.getCount());
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) KeyValue(org.apache.hadoop.hbase.KeyValue) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CountingInputStream(com.google.common.io.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 14 with CountingInputStream

use of com.google.common.io.CountingInputStream in project hbase by apache.

the class TestKeyValueCodec method testOne.

@Test
public void testOne() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    KeyValueCodec kvc = new KeyValueCodec();
    Codec.Encoder encoder = kvc.getEncoder(dos);
    final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
    final long length = kv.getLength() + Bytes.SIZEOF_INT;
    encoder.write(kv);
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    assertEquals(length, offset);
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = kvc.getDecoder(dis);
    // First read should pull in the KV
    assertTrue(decoder.advance());
    // Second read should trip over the end-of-stream  marker and return false
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(length, cis.getCount());
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) KeyValue(org.apache.hadoop.hbase.KeyValue) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CountingInputStream(com.google.common.io.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 15 with CountingInputStream

use of com.google.common.io.CountingInputStream in project hbase by apache.

the class TestKeyValueCodec method testThree.

@Test
public void testThree() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    KeyValueCodec kvc = new KeyValueCodec();
    Codec.Encoder encoder = kvc.getEncoder(dos);
    final KeyValue kv1 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
    final KeyValue kv2 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
    final KeyValue kv3 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
    final long length = kv1.getLength() + Bytes.SIZEOF_INT;
    encoder.write(kv1);
    encoder.write(kv2);
    encoder.write(kv3);
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    assertEquals(length * 3, offset);
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = kvc.getDecoder(dis);
    assertTrue(decoder.advance());
    KeyValue kv = (KeyValue) decoder.current();
    assertTrue(kv1.equals(kv));
    assertTrue(decoder.advance());
    kv = (KeyValue) decoder.current();
    assertTrue(kv2.equals(kv));
    assertTrue(decoder.advance());
    kv = (KeyValue) decoder.current();
    assertTrue(kv3.equals(kv));
    assertFalse(decoder.advance());
    dis.close();
    assertEquals((length * 3), cis.getCount());
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) KeyValue(org.apache.hadoop.hbase.KeyValue) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CountingInputStream(com.google.common.io.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

CountingInputStream (com.google.common.io.CountingInputStream)20 ByteArrayInputStream (java.io.ByteArrayInputStream)12 DataInputStream (java.io.DataInputStream)12 CountingOutputStream (com.google.common.io.CountingOutputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 DataOutputStream (java.io.DataOutputStream)11 Test (org.junit.Test)11 KeyValue (org.apache.hadoop.hbase.KeyValue)8 Cell (org.apache.hadoop.hbase.Cell)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)2 Tag (org.apache.hadoop.hbase.Tag)2 LazyInputStream (org.apache.jackrabbit.oak.commons.io.LazyInputStream)2 ParseContext (org.apache.tika.parser.ParseContext)2 WriteOutContentHandler (org.apache.tika.sax.WriteOutContentHandler)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 FileNotFoundException (java.io.FileNotFoundException)1 FilterInputStream (java.io.FilterInputStream)1