Decompression: How to determine the size of the output buffer?
MartinHaeusler opened this issue · 1 comments
MartinHaeusler commented
I'm trying out this library for snappy compression and decompression. Currently I'm using the Xerial Snappy library. This may be a very dumb question, but I can't seem to figure this out:
How do we know the required size of the output buffer?
public ByteArray decompress(ByteArray compressed){
var decompressor = SnappyDecompressor();
var outputBuffer = ByteBuffer.allocate(?????);
decompressor.decompress(ByteBuffer.wrap(compressed), outputBuffer);
return outputBuffer.array()
}
ByteBuffer
s by design cannot resize dynamically. And I don't know anything about the input array, except that it has been previously compressed by snappy. So... how should I size the output buffer?
MartinHaeusler commented
Ah, nevermind, found it in the tests! It's:
SnappyDecompressor.getUncompressedLength(bytes, 0)
Just got confused because for the compressor, maxCompressedLength(...)
is an instance method, whereas getUncompressedLength(...)
is a static
method and the IDE didn't show it to me.