BrotliDeCompressor { public final int deCompress(byte[] in, byte[] out) throws BrotliException { return deCompress(in, 0, in.length, out, 0, out.length); }  final int deCompress(byte[] in, byte[] out); final int deCompress(byte[] in, int inPosition, int inLength, byte[] out, int outPosition, int outLength); final int deCompress(ByteBuffer in, ByteBuffer out);  }
@Test public void decompress_with_byte_array() throws Exception { byte[] in = A_BYTES_COMPRESSED; byte[] out = new byte[100]; int outLen = decompressor.deCompress(in, out); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(out).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_using_position_and_length_on_input() throws Exception { byte[] in = BufferTestHelper.createFilledByteArray(100, 'x'); byte[] out = new byte[100]; int testPosition = 23; int testLength = A_BYTES_COMPRESSED.length; System.arraycopy(A_BYTES_COMPRESSED, 0, in, testPosition, testLength); int outLen = decompressor.deCompress(in, testPosition, testLength, out, 0, out.length); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(out).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_using_position_and_length_on_output() throws Exception { byte[] out = new byte[100]; int testPosition = 23; int outLen = decompressor.deCompress(A_BYTES_COMPRESSED, 0, A_BYTES_COMPRESSED.length, out, testPosition, A_BYTES.length); assertThat(outLen).isEqualTo(A_BYTES.length); byte[] outCopiedRange = Arrays.copyOfRange(out, testPosition, testPosition + outLen); assertThat(outCopiedRange).isEqualTo(A_BYTES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void using_negative_position_on_input_throws_IllegalArgumentException() throws Exception { byte[] in = A_BYTES_COMPRESSED; byte[] out = new byte[2048]; decompressor.deCompress(in, -1, in.length, out, 0, out.length); }
@Test(expectedExceptions = IllegalArgumentException.class) public void using_negative_position_on_output_throws_IllegalArgumentException() throws Exception { byte[] in = A_BYTES_COMPRESSED; byte[] out = new byte[2048]; decompressor.deCompress(in, 0, in.length, out, -1, out.length); }
@Test(expectedExceptions = IllegalArgumentException.class) public void using_negative_length_on_input_throws_IllegalArgumentException() throws Exception { byte[] in = A_BYTES_COMPRESSED; byte[] out = new byte[2048]; decompressor.deCompress(in, 0, -1, out, 0, out.length); }
@Test(expectedExceptions = IllegalArgumentException.class) public void using_negative_length_on_output_throws_IllegalArgumentException() throws Exception { byte[] in = A_BYTES_COMPRESSED; byte[] out = new byte[2048]; decompressor.deCompress(in, 0, in.length, out, 0, -1); }
@Test public void decompress_with_direct_ByteBuffer() throws Exception { ByteBuffer inBuf = ByteBuffer.allocateDirect(A_BYTES_COMPRESSED.length); inBuf.put(A_BYTES_COMPRESSED); inBuf.position(0); ByteBuffer outBuf = ByteBuffer.allocateDirect(100); int outLen = decompressor.deCompress(inBuf, outBuf); assertThat(outLen).isEqualTo(A_BYTES.length); byte[] out = new byte[A_BYTES.length]; outBuf.get(out); assertThat(out).isEqualTo(A_BYTES); }
@Test public void decompress_with_direct_ByteBuffer_using_position_and_length_on_input() throws Exception { ByteBuffer inBuffer = ByteBuffer.allocateDirect(100); ByteBuffer outBuffer = ByteBuffer.allocateDirect(100); inBuffer.put(BufferTestHelper.createFilledByteArray(100, 'x')); int testPosition = 23; inBuffer.position(testPosition); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.position(testPosition); inBuffer.limit(testPosition + A_BYTES_COMPRESSED.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(0); assertThat(outBuffer.limit()).isEqualTo(outLen); assertThat(inBuffer.position()).isEqualTo(testPosition + A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }
@Test public void decompress_with_direct_ByteBuffer_using_position_and_length_on_output() throws Exception { ByteBuffer inBuffer = ByteBuffer.allocateDirect(100); ByteBuffer outBuffer = ByteBuffer.allocateDirect(100); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.limit(A_BYTES_COMPRESSED.length); inBuffer.position(0); int testPosition = 23; outBuffer.position(testPosition); outBuffer.limit(testPosition + A_BYTES.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(testPosition); assertThat(outBuffer.limit()).isEqualTo(testPosition + outLen); assertThat(inBuffer.position()).isEqualTo(A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_wrapped_ByteBuffer() throws Exception { ByteBuffer inBuf = ByteBuffer.wrap(A_BYTES_COMPRESSED); ByteBuffer outBuf = ByteBuffer.allocate(100); int outLen = decompressor.deCompress(inBuf, outBuf); assertThat(outLen).isEqualTo(A_BYTES.length); byte[] out = new byte[A_BYTES.length]; outBuf.get(out); assertThat(out).isEqualTo(A_BYTES); }
@Test public void decompress_with_byte_array_wrapped_ByteBuffer_using_position_and_length_on_input() throws Exception { ByteBuffer inBuffer = ByteBuffer.wrap(BufferTestHelper.createFilledByteArray(100, 'x')); ByteBuffer outBuffer = ByteBuffer.allocate(100); int testPosition = 23; inBuffer.position(testPosition); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.position(testPosition); inBuffer.limit(testPosition + A_BYTES_COMPRESSED.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(0); assertThat(outBuffer.limit()).isEqualTo(outLen); assertThat(inBuffer.position()).isEqualTo(testPosition + A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_wrapped_ByteBuffer_using_position_and_length_on_output() throws Exception { ByteBuffer inBuffer = ByteBuffer.allocate(100); ByteBuffer outBuffer = ByteBuffer.allocate(100); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.limit(A_BYTES_COMPRESSED.length); inBuffer.position(0); int testPosition = 23; outBuffer.position(testPosition); outBuffer.limit(testPosition + A_BYTES.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(testPosition); assertThat(outBuffer.limit()).isEqualTo(testPosition + outLen); assertThat(inBuffer.position()).isEqualTo(A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_wrapped_ByteBuffer_using_arrayOffset_and_length_on_input() throws Exception { ByteBuffer inBuffer = ByteBuffer.wrap(BufferTestHelper.createFilledByteArray(100, 'x')); ByteBuffer outBuffer = ByteBuffer.allocate(100); int testPosition = 23; inBuffer.position(testPosition); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.position(testPosition); inBuffer = inBuffer.slice(); inBuffer.limit(A_BYTES_COMPRESSED.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(0); assertThat(outBuffer.limit()).isEqualTo(outLen); assertThat(inBuffer.position()).isEqualTo(A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }
@Test public void decompress_with_byte_array_wrapped_ByteBuffer_using_arrayOffset_and_length_on_output() throws Exception { ByteBuffer inBuffer = ByteBuffer.allocate(100); ByteBuffer outBuffer = ByteBuffer.allocate(100); inBuffer.put(A_BYTES_COMPRESSED); inBuffer.limit(A_BYTES_COMPRESSED.length); inBuffer.position(0); int testPosition = 23; outBuffer.position(testPosition); outBuffer = outBuffer.slice(); outBuffer.limit(A_BYTES.length); int outLen = decompressor.deCompress(inBuffer, outBuffer); assertThat(outLen).isEqualTo(A_BYTES.length); assertThat(outBuffer.position()).isEqualTo(0); assertThat(outBuffer.limit()).isEqualTo(outLen); assertThat(inBuffer.position()).isEqualTo(A_BYTES_COMPRESSED.length); byte[] buf = new byte[A_BYTES.length]; outBuffer.get(buf); assertThat(buf).startsWith(A_BYTES); }