コード例 #1
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();
  }
コード例 #2
0
 @Test
 public void testAvailable() throws IOException {
   ByteArrayInputStream bis = new ByteArrayInputStream(compressedBytes);
   LZFInputStream is = new LZFInputStream(bis);
   Assert.assertSame(is.getUnderlyingInputStream(), bis);
   Assert.assertEquals(0, is.available());
   // read one byte; should decode bunch more, make available
   is.read();
   int total = 1; // since we read one byte already
   Assert.assertEquals(is.available(), 65534);
   // and after we skip through all of it, end with -1 for EOF
   long count;
   while ((count = is.skip(16384L)) > 0L) {
     total += (int) count;
   }
   // nothing more available; but we haven't yet closed so:
   Assert.assertEquals(is.available(), 0);
   // and then we close it:
   is.close();
   Assert.assertEquals(is.available(), 0);
   Assert.assertEquals(total, compressableInputLength);
 }