dk.netarkivet.common.utils
Class LargeFileGZIPInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.util.zip.InflaterInputStream
              extended by java.util.zip.GZIPInputStream
                  extended by dk.netarkivet.common.utils.LargeFileGZIPInputStream
All Implemented Interfaces:
java.io.Closeable

public class LargeFileGZIPInputStream
extends java.util.zip.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

Field Summary
 
Fields inherited from class java.util.zip.GZIPInputStream
crc, eos, GZIP_MAGIC
 
Fields inherited from class java.util.zip.InflaterInputStream
buf, inf, len
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
LargeFileGZIPInputStream(java.io.InputStream in)
          Creates a new input stream with a default buffer size.
 
Method Summary
 int read(byte[] buf, int off, int len)
          Reads uncompressed data into an array of bytes.
 
Methods inherited from class java.util.zip.GZIPInputStream
close
 
Methods inherited from class java.util.zip.InflaterInputStream
available, fill, mark, markSupported, read, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LargeFileGZIPInputStream

public LargeFileGZIPInputStream(java.io.InputStream in)
                         throws java.io.IOException
Creates a new input stream with a default buffer size.

Parameters:
in - the input stream
Throws:
java.io.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 java.io.IOException
Reads uncompressed data into an array of bytes. Blocks until enough input is available for decompression.

Overrides:
read in class java.util.zip.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:
java.io.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