|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream java.util.zip.InflaterInputStream java.util.zip.GZIPInputStream org.archive.io.GzippedInputStream
public class GzippedInputStream
Subclass of GZIPInputStream that can handle a stream made of multiple concatenated GZIP members/records. This class is needed because GZIPInputStream only finds the first GZIP member in the file even if the file is made up of multiple GZIP members.
Takes an InputStream stream that implements
RepositionableStream
interface so it can backup over-reads done
by the zlib Inflater class.
Use the iterator()
method to get a gzip member iterator.
Calls to Iterator.next()
returns the next gzip member in the
stream. Cast return from Iterator.next()
to InputStream.
Use gzipMemberSeek(long)
to position stream before reading
a gzip member if doing random accessing of gzip members. Pass it offset
at which gzip member starts.
If you need to know position at which a gzip member starts, call
position()
just after a call to Iterator.hasNext()
and before you call Iterator.next()
.
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 | |
---|---|
GzippedInputStream(java.io.InputStream is)
|
|
GzippedInputStream(java.io.InputStream is,
int size)
|
Method Summary | |
---|---|
protected static java.io.InputStream |
checkStream(java.io.InputStream is)
|
protected boolean |
compareBytes(int a,
int b)
|
protected GzipHeader |
getGzipHeader()
|
protected java.util.zip.Inflater |
getInflater()
|
protected java.io.InputStream |
getInputStream()
|
long |
gotoEOR()
Exhaust current GZIP member content. |
long |
gotoEOR(int ignore)
Exhaust current GZIP member content. |
static byte[] |
gzip(byte[] bytes)
Gzip passed bytes. |
void |
gzipMemberSeek()
|
void |
gzipMemberSeek(long position)
Seek to a gzip member. |
static boolean |
isCompressedRepositionableStream(it.unimi.dsi.fastutil.io.RepositionableStream rs)
Tests passed stream is GZIP stream by reading in the HEAD. |
static boolean |
isCompressedStream(java.io.InputStream is)
Tests passed stream is gzip stream by reading in the HEAD. |
java.util.Iterator |
iterator()
Returns a GZIP Member Iterator. |
protected boolean |
moveToNextGzipMember()
|
long |
position()
|
void |
position(long position)
Seek to passed offset. |
protected void |
readHeader()
Read in the gzip header. |
protected void |
resetInflater()
Move to next gzip member in the file. |
Methods inherited from class java.util.zip.GZIPInputStream |
---|
close, read |
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 |
---|
public GzippedInputStream(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public GzippedInputStream(java.io.InputStream is, int size) throws java.io.IOException
is
- An InputStream that implements RespositionableStream and
returns true
when we call
InputStream.markSupported()
(Latter is needed so can setup
an Iterator
against the Gzip stream).size
- Size of blocks to use reading.
java.io.IOException
Method Detail |
---|
protected static java.io.InputStream checkStream(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public long gotoEOR(int ignore) throws java.io.IOException
ignore
- Character to ignore counting characters (Usually
trailing new lines).
java.io.IOException
public long gotoEOR() throws java.io.IOException
java.io.IOException
public java.util.Iterator iterator()
protected boolean moveToNextGzipMember()
protected boolean compareBytes(int a, int b)
protected java.util.zip.Inflater getInflater()
protected java.io.InputStream getInputStream()
protected GzipHeader getGzipHeader()
protected void resetInflater()
protected void readHeader() throws java.io.IOException
java.io.IOException
public void position(long position) throws java.io.IOException
position
in interface it.unimi.dsi.fastutil.io.RepositionableStream
position
- Absolute position of a gzip member start.
java.io.IOException
public long position() throws java.io.IOException
position
in interface it.unimi.dsi.fastutil.io.RepositionableStream
java.io.IOException
public void gzipMemberSeek(long position) throws java.io.IOException
position
- Absolute position of a gzip member start.
java.io.IOException
public void gzipMemberSeek() throws java.io.IOException
java.io.IOException
public static byte[] gzip(byte[] bytes) throws java.io.IOException
bytes
- What to gzip.
java.io.IOException
public static boolean isCompressedRepositionableStream(it.unimi.dsi.fastutil.io.RepositionableStream rs) throws java.io.IOException
rs
- An InputStream that is Repositionable.
java.io.IOException
public static boolean isCompressedStream(java.io.InputStream is) throws java.io.IOException
is
- An InputStream.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |