Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.InflaterDataAccess


    byte[] signature = new byte[6];
    if (da.length() > 6) {
      da.readBytes(signature, 0, 6);
      if (signature[0] == 'H' && signature[1] == 'G' && signature[2] == '1' && signature[3] == '0') {
        if (signature[4] == 'G' && signature[5] == 'Z') {
          return new InflaterDataAccess(da, 6, da.length() - 6);
        }
        if (signature[4] == 'B' && signature[5] == 'Z') {
          throw Internals.notImplemented();
        }
        if (signature[4] != 'U' || signature[5] != 'N') {
View Full Code Here


  }
 
  @Test
  public void testLength() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length());
    //
    ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    byte[] dummy = new byte[30];
    ida.readBytes(dummy, 0, dummy.length);
    errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length());
    //
    ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    // consume most of the stream, so that all original compressed data is already read
    dummy = new byte[testContent1.length - 1];
    ida.readBytes(dummy, 0, dummy.length);
    errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length());
    //
    errorCollector.assertFalse(ida.isEmpty()); // check InflaterDataAccess#available() positive
  }
View Full Code Here

  }

  @Test
  public void testReadBytes() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    ida.skip(10);
    byte[] chunk1 = new byte[22];
    ida.readBytes(chunk1, 0, 20);
    chunk1[20] = ida.readByte();
    chunk1[21] = ida.readByte();
    ida.skip(5);
    byte[] chunk2 = new byte[12];
    chunk2[0] = ida.readByte();
    chunk2[1] = ida.readByte();
    ida.readBytes(chunk2, 2, 10);
    errorCollector.assertTrue(new ByteArraySlice(testContent1, 10, 22).equalsTo(chunk1));
    errorCollector.assertTrue(new ByteArraySlice(testContent1, 10+22+5, 12).equalsTo(chunk2));
    int consumed = 10+22+5+12;
    //
    // check that even when original content is completely unpacked, leftovers in the outBuffer are recognized  
    ida.readBytes(ByteBuffer.allocate(testContent1.length - consumed - 2)); // unpack up to an end (almost)
    errorCollector.assertFalse(ida.isEmpty()); // check InflaterDataAccess#available() positive
    //
    ByteBuffer chunk3 = ByteBuffer.allocate(10);
    ida.readBytes(chunk3);
    errorCollector.assertEquals(2, chunk3.flip().remaining());
  }
View Full Code Here

  }
 
  @Test
  public void testSeek() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    ida.seek(20);
    final int bufferCapacity = 10;
    ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity);
    ida.readBytes(chunk1);
    errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array()));
    ida.skip(-bufferCapacity);
    ByteBuffer chunk2 = ByteBuffer.allocate(bufferCapacity);
    ida.readBytes(chunk2);
    errorCollector.assertEquals(chunk1, chunk2);
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.InflaterDataAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.