Class LargeFileGZIPInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LargeFileGZIPInputStream
    extends GZIPInputStream
    Subclass of GZIPInputstream, including a workaround to support >2GB files.

    Java currently has a bug that does not allow unzipping Gzip files with contents larger than 2GB. The result will be an IOException with the message "Corrupt GZIP trailer". This class works around that bug by ignoring that message for all streams which are uncompressed larger than 2GB. This sacrifices CRC checks for those streams, though.

    See sun bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092263

    See Also:
    GZIPInputStream
    • Constructor Detail

      • LargeFileGZIPInputStream

        public LargeFileGZIPInputStream​(InputStream in)
                                 throws IOException
        Creates a new input stream with a default buffer size.
        Parameters:
        in - the input stream
        Throws:
        IOException - if an I/O error has occurred. Note: We usually don't allow IOException in our code, but this is done here to closely mimic GZIPInputStream
    • Method Detail

      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws IOException
        Reads uncompressed data into an array of bytes. Blocks until enough input is available for decompression.
        Overrides:
        read in class GZIPInputStream
        Parameters:
        buf - the buffer into which the data is read
        off - the start offset of the data
        len - the maximum number of bytes read
        Returns:
        the actual number of bytes read, or -1 if the end of the compressed input stream is reached
        Throws:
        IOException - if an I/O error has occurred or the compressed input data is corrupt. Note that size differences are ignored in this workaround class if size is larger than Integer.MAX_VALUE. Note: We usually don't allow IOException in our code, but this is done here to closely mimic GZIPInputStream