I was able to code a Java decompressor (and compressor) that was able to read lz4 files files created with the C++ code (and vice versa).
However the performance compared to the net.jpountz.lz4 was .... poor, really poor. Compressing was really slow, but fortunately, I only really need decompression in Java for now.
Is there something I can do boost the performance of the decompression ? This is my code for decompression :
public byte[] decompressUsingApacheCommonsCompressFramesStreams(byte[] data) {
byte[] decompressed = null;
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
try {
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(data, 0, data.length);
BufferedInputStream in = new BufferedInputStream(byteInputStream);
FramedLZ4CompressorInputStream lz4InputStream = new FramedLZ4CompressorInputStream(in, true);
int count = 0;
int totalCount = 0;
final byte[] buffer = new byte[bufferSize];
while ((count = lz4InputStream.read(buffer)) != -1) {
totalCount += count;
byteOutputStream.write(buffer, 0, count);
}
logger.info("total size decompressed : " + totalCount);
logger.info("number of compressed bytes decompressed into stream : " + lz4InputStream.getCompressedCount());
byteOutputStream.flush();
decompressed = byteOutputStream.toByteArray();
byteOutputStream.close();
lz4InputStream.close();
logger.info("input compressed length : " + data.length + ", output decompressed length : "
+ decompressed.length);
}
catch (IOException e) {
logger.error("Error ! IOException thrown by LZ4 buffer streams : " + e.getMessage());
}
catch (Exception e) {
logger.error("Error ! General exception thrown : " + e.getMessage());
}
return decompressed;
}