InflaterInputStreampublic class InflaterInputStream extends FilterInputStream This class provides an implementation of {@code FilterInputStream} that
uncompresses data that was compressed using the DEFLATE algorithm
(see specification).
Basically it wraps the {@code Inflater} class and takes care of the
buffering. |
Fields Summary |
---|
protected Inflater | infThe inflater used for this stream. | protected byte[] | bufThe input buffer used for decompression. | protected int | lenThe length of the buffer. | boolean | closed | boolean | eof | static final int | BUF_SIZE | int | nativeEndBufSize |
Constructors Summary |
---|
public InflaterInputStream(InputStream is)This is the most basic constructor. You only need to pass the {@code
InputStream} from which the compressed data is to be read from. Default
settings for the {@code Inflater} and internal buffer are be used. In
particular the Inflater expects a ZLIB header from the input stream.
// END android-added
this(is, new Inflater(), BUF_SIZE);
| public InflaterInputStream(InputStream is, Inflater inf)This constructor lets you pass a specifically initialized Inflater,
for example one that expects no ZLIB header.
this(is, inf, BUF_SIZE);
| public InflaterInputStream(InputStream is, Inflater inf, int bsize)This constructor lets you specify both the {@code Inflater} as well as
the internal buffer size to be used.
super(is);
if (is == null || inf == null) {
throw new NullPointerException();
}
if (bsize <= 0) {
throw new IllegalArgumentException();
}
this.inf = inf;
// BEGIN android-changed
if (is instanceof ZipFile.RAFStream) {
nativeEndBufSize = bsize;
} else {
buf = new byte[bsize];
}
// END android-changed
|
Methods Summary |
---|
public int | available()Returns whether data can be read from this stream.
if (closed) {
// archive.1E=Stream is closed
throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
}
if (eof) {
return 0;
}
return 1;
| public void | close()Closes the input stream.
if (!closed) {
inf.end();
closed = true;
eof = true;
super.close();
}
| protected void | fill()Fills the input buffer with data to be decompressed.
if (closed) {
throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
}
// BEGIN android-changed
if (nativeEndBufSize > 0) {
ZipFile.RAFStream is = (ZipFile.RAFStream)in;
synchronized (is.mSharedRaf) {
long len = is.mLength - is.mOffset;
if (len > nativeEndBufSize) len = nativeEndBufSize;
int cnt = inf.setFileInput(is.mSharedRaf.getFD(), is.mOffset, (int)nativeEndBufSize);
is.skip(cnt);
}
} else {
if ((len = in.read(buf)) > 0) {
inf.setInput(buf, 0, len);
}
}
// END android-changed
| public void | mark(int readlimit)This implementation overrides the super type implementation to do nothing
at all.
// do nothing
| public boolean | markSupported()Returns whether the receiver implements {@code mark} semantics. This type
does not support {@code mark()}, so always responds {@code false}.
return false;
| public int | read()Reads a single byte of decompressed data.
byte[] b = new byte[1];
if (read(b, 0, 1) == -1) {
return -1;
}
return b[0] & 0xff;
| public int | read(byte[] buffer, int off, int nbytes)Reads up to {@code nbytes} of decompressed data and stores it in
{@code buffer} starting at {@code off}.
/* archive.1E=Stream is closed */
if (closed) {
throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
}
if (null == buffer) {
throw new NullPointerException();
}
if (off < 0 || nbytes < 0 || off + nbytes > buffer.length) {
throw new IndexOutOfBoundsException();
}
if (nbytes == 0) {
return 0;
}
if (inf.finished()) {
eof = true;
return -1;
}
// avoid int overflow, check null buffer
if (off <= buffer.length && nbytes >= 0 && off >= 0
&& buffer.length - off >= nbytes) {
do {
if (inf.needsInput()) {
fill();
}
int result;
try {
result = inf.inflate(buffer, off, nbytes);
} catch (DataFormatException e) {
if (len == -1) {
throw new EOFException();
}
throw (IOException)(new IOException().initCause(e));
}
if (result > 0) {
return result;
} else if (inf.finished()) {
eof = true;
return -1;
} else if (inf.needsDictionary()) {
return -1;
} else if (len == -1) {
throw new EOFException();
// If result == 0, fill() and try again
}
} while (true);
}
throw new ArrayIndexOutOfBoundsException();
| public void | reset()Reset the position of the stream to the last marked position. This
implementation overrides the supertype implementation and always throws
an {@link IOException IOException} when called.
throw new IOException();
| public long | skip(long nbytes)Skips up to n bytes of uncompressed data.
if (nbytes >= 0) {
long count = 0, rem = 0;
while (count < nbytes) {
int x = read(buf, 0,
(rem = nbytes - count) > buf.length ? buf.length
: (int) rem);
if (x == -1) {
eof = true;
return count;
}
count += x;
}
return count;
}
throw new IllegalArgumentException();
|
|