I have a GZIPInputStream
that I constructed from another ByteArrayInputStream
. I want to know the original (uncompressed) length for the gzip data. Although I can read to the end of the GZIPInputStream
, then count the number, it will cost much time and waste CPU. I would like to know the size before read it.
Is there a similiar method like ZipEntry.getSize()
for GZIPInputStream
:
public long getSize ()
Since: API Level 1
Gets the uncompressed size of this ZipEntry.
A more compact version of the calculation based on the 4 tail bytes (avoids using a byte buffer, calls
Integer.reverseBytes
to reverse the byte order of read bytes).Based on @Alexander's answer: