annotate 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
rev   line source
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.ByteArrayOutputStream;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.IOException;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.nio.ByteBuffer;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.zip.DeflaterOutputStream;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.zip.Inflater;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
25 import org.junit.Rule;
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.junit.Test;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.ByteArrayDataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.internal.DataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.internal.InflaterDataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 /**
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * @author Artem Tikhomirov
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * @author TMate Software Ltd.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 */
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 public class TestInflaterDataAccess {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
37 @Rule
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
38 public final ErrorCollectorExt errorCollector = new ErrorCollectorExt();
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final byte[] testContent1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.".getBytes();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private DataAccess zip(byte[] source) throws IOException {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 ByteArrayOutputStream bos = new ByteArrayOutputStream();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 DeflaterOutputStream dos = new DeflaterOutputStream(bos);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 dos.write(source);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 dos.flush();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 dos.close();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 return new ByteArrayDataAccess(bos.toByteArray());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public void testSeek() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 DataAccess zip = zip(testContent1);
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
54 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 ida.seek(20);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 final int bufferCapacity = 10;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 ida.readBytes(chunk1);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array()));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 ida.skip(-bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 ByteBuffer chunk2 = ByteBuffer.allocate(bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 ida.readBytes(chunk2);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 errorCollector.assertEquals(chunk1, chunk2);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 public void testLength() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 DataAccess zip = zip(testContent1);
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
69 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 //
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
72 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 byte[] dummy = new byte[30];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 ida.readBytes(dummy, 0, dummy.length);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 //
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
77 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 // consume most of the stream, so that all original compressed data is already read
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
79 dummy = new byte[testContent1.length - 1];
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
80 ida.readBytes(dummy, 0, dummy.length);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length());
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
82 //
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
83 errorCollector.assertFalse(ida.isEmpty()); // check InflaterDataAccess#available() positive
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 public void testReadBytes() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 DataAccess zip = zip(testContent1);
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
89 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 ida.skip(10);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 byte[] chunk1 = new byte[22];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 ida.readBytes(chunk1, 0, 20);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 chunk1[20] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 chunk1[21] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 ida.skip(5);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 byte[] chunk2 = new byte[12];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 chunk2[0] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 chunk2[1] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 ida.readBytes(chunk2, 2, 10);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 errorCollector.assertTrue(new ByteArraySlice(testContent1, 10, 22).equalsTo(chunk1));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 errorCollector.assertTrue(new ByteArraySlice(testContent1, 10+22+5, 12).equalsTo(chunk2));
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
102 int consumed = 10+22+5+12;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
103 //
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
104 // check that even when original content is completely unpacked, leftovers in the outBuffer are recognized
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
105 ida.readBytes(ByteBuffer.allocate(testContent1.length - consumed - 2)); // unpack up to an end (almost)
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
106 errorCollector.assertFalse(ida.isEmpty()); // check InflaterDataAccess#available() positive
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
107 //
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
108 ByteBuffer chunk3 = ByteBuffer.allocate(10);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
109 ida.readBytes(chunk3);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
110 errorCollector.assertEquals(2, chunk3.flip().remaining());
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 private static class ByteArraySlice {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 public final byte[] array;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 public final int offset, length;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 public ByteArraySlice(byte[] array, int offset, int length) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 this.array = array;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 this.offset = offset;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 this.length = length;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 public boolean equalsTo(byte[] another) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 if (another == null || another.length != length) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 return false;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 for (int i = 0; i < length; i++) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 if (array[offset + i] != another[i]) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 return false;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 return true;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }