Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.InflaterDataAccess.readBytes()


    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);
  }
 
  @Test
  public void testLength() throws Exception {
View Full Code Here


    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];
View Full Code Here

    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

  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();
View Full Code Here

    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  
View Full Code Here

    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

    // 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());
  }

  private static class ByteArraySlice {
    public final byte[] array;
View Full Code Here

    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
Copyright © 2018 www.massapi.com. 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.