Package dk.netarkivet.common.utils
Class LargeFileGZIPInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.util.zip.InflaterInputStream
-
- java.util.zip.GZIPInputStream
-
- dk.netarkivet.common.utils.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
-
-
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
Constructors Constructor Description LargeFileGZIPInputStream(InputStream in)
Creates a new input stream with a default buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
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 classGZIPInputStream
- Parameters:
buf
- the buffer into which the data is readoff
- the start offset of the datalen
- 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
-
-