Пример #1
0
 @Test
 public void testReadAndWrite() throws Exception {
   byte[] fluff = constructFluff(132000);
   byte[] comp = LZFEncoder.encode(fluff);
   ByteArrayOutputStream bytes = new ByteArrayOutputStream(fluff.length);
   LZFInputStream in = new LZFInputStream(new ByteArrayInputStream(comp));
   in.readAndWrite(bytes);
   in.close();
   byte[] actual = bytes.toByteArray();
   Assert.assertEquals(actual.length, fluff.length);
   Assert.assertEquals(actual, fluff);
 }
  @Test
  public void testSimpleCompression() throws IOException {
    // produce multiple chunks, about 3 here:
    byte[] source = constructFluff(140000);
    LZFCompressingInputStream compIn =
        new LZFCompressingInputStream(new ByteArrayInputStream(source));
    byte[] comp = readAll(compIn);
    byte[] uncomp = LZFDecoder.decode(comp);
    Assert.assertEquals(uncomp, source);

    // and then check that size is about same as with static methods
    byte[] comp2 = LZFEncoder.encode(source);
    Assert.assertEquals(comp2.length, comp.length);
  }
Пример #3
0
  // Mostly for [Issue#19]
  @Test
  public void testLongSkips() throws Exception {
    // 64k per block, 200k gives 3 full, one small
    byte[] fluff = constructFluff(200000);
    byte[] comp = LZFEncoder.encode(fluff);

    // we get about 200k, maybe byte or two more, so:
    final int LENGTH = fluff.length;

    LZFInputStream in = new LZFInputStream(new ByteArrayInputStream(comp));
    // read one byte for fun
    Assert.assertEquals(in.read(), fluff[0] & 0xFF);
    // then skip all but one
    long amt = in.skip(LENGTH - 2);
    Assert.assertEquals(amt, (long) (LENGTH - 2));
    Assert.assertEquals(in.read(), fluff[LENGTH - 1] & 0xFF);

    Assert.assertEquals(in.read(), -1);
    in.close();
  }