Closed zhangjiajie023 closed 6 years ago
Someone suggested that set the dest.length to be src.length * 3 or more, is it suitable, or any other better solution ?
There is no easy way to guess the decompressed length in lz4. The maximum possible compression ratio is 255, but it is too large for the decompressed buffer allocation.
I meet the same problem. LZ4BlockInputStream may solve your problem as stream can be read in multi times.
You can also use LZ4FrameInputStream (1.4.0 or later) or LZ4DecompressorWithLength (1.5.0 or later). Please reopen this issue if you need further assistance.
byte[] restored = new byte[decompressedLength]; // - method 2: when the compressed length is known (a little slower) // the destination buffer needs to be over-sized LZ4SafeDecompressor decompressor2 = factory.safeDecompressor(); int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);
this example has initial a correct length for restored to decompress.
But when i don't know the decompressed length, how should I initial the length fordest byte[]?
I tried to byte[] restored = new byte[1]; failed, definitely; I used the decompress(ByteBuffer src, ByteBuffer dest), initial the capacity of dest to be 1, failed too;
so the dest must be set a longer length than it should be, right? could u tell me how to use the safeDecompress(..)? tks for your answer