Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestInflaterDataAccess.java @ 655:bcbcc318f250
Performance: reuse unzip output buffer
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 18:36:38 +0200 |
parents | 3c4db86e8c1f |
children |
comparison
equal
deleted
inserted
replaced
654:12a4f60ea972 | 655:bcbcc318f250 |
---|---|
49 } | 49 } |
50 | 50 |
51 @Test | 51 @Test |
52 public void testSeek() throws Exception { | 52 public void testSeek() throws Exception { |
53 DataAccess zip = zip(testContent1); | 53 DataAccess zip = zip(testContent1); |
54 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]); | 54 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null); |
55 ida.seek(20); | 55 ida.seek(20); |
56 final int bufferCapacity = 10; | 56 final int bufferCapacity = 10; |
57 ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity); | 57 ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity); |
58 ida.readBytes(chunk1); | 58 ida.readBytes(chunk1); |
59 errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array())); | 59 errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array())); |
64 } | 64 } |
65 | 65 |
66 @Test | 66 @Test |
67 public void testLength() throws Exception { | 67 public void testLength() throws Exception { |
68 DataAccess zip = zip(testContent1); | 68 DataAccess zip = zip(testContent1); |
69 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]); | 69 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null); |
70 errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length()); | 70 errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length()); |
71 // | 71 // |
72 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]); | 72 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null); |
73 byte[] dummy = new byte[30]; | 73 byte[] dummy = new byte[30]; |
74 ida.readBytes(dummy, 0, dummy.length); | 74 ida.readBytes(dummy, 0, dummy.length); |
75 errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length()); | 75 errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length()); |
76 // | 76 // |
77 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]); | 77 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null); |
78 // consume most of the stream, so that all original compressed data is already read | 78 // consume most of the stream, so that all original compressed data is already read |
79 dummy = new byte[testContent1.length - 1]; | 79 dummy = new byte[testContent1.length - 1]; |
80 ida.readBytes(dummy, 0, dummy.length); | 80 ida.readBytes(dummy, 0, dummy.length); |
81 errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length()); | 81 errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length()); |
82 // | 82 // |
84 } | 84 } |
85 | 85 |
86 @Test | 86 @Test |
87 public void testReadBytes() throws Exception { | 87 public void testReadBytes() throws Exception { |
88 DataAccess zip = zip(testContent1); | 88 DataAccess zip = zip(testContent1); |
89 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]); | 89 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null); |
90 ida.skip(10); | 90 ida.skip(10); |
91 byte[] chunk1 = new byte[22]; | 91 byte[] chunk1 = new byte[22]; |
92 ida.readBytes(chunk1, 0, 20); | 92 ida.readBytes(chunk1, 0, 20); |
93 chunk1[20] = ida.readByte(); | 93 chunk1[20] = ida.readByte(); |
94 chunk1[21] = ida.readByte(); | 94 chunk1[21] = ida.readByte(); |