BZip2Decompressor implements OptionDecompressor<T> { @Override public T decompress(byte[] compressed) throws IOException { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(compressed); BZip2CompressorInputStream bzip2Input = new BZip2CompressorInputStream(inputStream)) { return inputStreamConverter.readStream(bzip2Input); } } BZip2Decompressor(InputStreamConverter<T> inputStreamConverter); @Override T decompress(byte[] compressed);  }
@Test public void shouldDecompressBZip2Stream() throws IOException { BZip2Decompressor<String> decompressor = new BZip2Decompressor<>( inputStream -> { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String output = reader.readLine(); reader.close(); return output; }); String originalString = "abc"; ByteArrayOutputStream compressedStream = new ByteArrayOutputStream(); try (BZip2CompressorOutputStream bzip2Output = new BZip2CompressorOutputStream(compressedStream)) { bzip2Output.write(originalString.getBytes()); } String decompressedString = decompressor.decompress(compressedStream.toByteArray()); assertEquals(originalString, decompressedString); }