src/share/classes/java/util/zip/Inflater.java
Print this page
@@ -76,10 +76,12 @@
private final ZStreamRef zsRef;
private byte[] buf = defaultBuf;
private int off, len;
private boolean finished;
private boolean needDict;
+ private long bytesRead;
+ private long bytesWritten;
private static final byte[] defaultBuf = new byte[0];
static {
/* Zip library is loaded from System.initializeSystemClass */
@@ -251,11 +253,15 @@
if (off < 0 || len < 0 || off > b.length - len) {
throw new ArrayIndexOutOfBoundsException();
}
synchronized (zsRef) {
ensureOpen();
- return inflateBytes(zsRef.address(), b, off, len);
+ int thisLen = this.len;
+ int n = inflateBytes(zsRef.address(), b, off, len);
+ bytesWritten += n;
+ bytesRead += (thisLen - this.len);
+ return n;
}
}
/**
* Uncompresses bytes into specified buffer. Returns actual number
@@ -305,11 +311,11 @@
* @since 1.5
*/
public long getBytesRead() {
synchronized (zsRef) {
ensureOpen();
- return getBytesRead(zsRef.address());
+ return bytesRead;
}
}
/**
* Returns the total number of uncompressed bytes output so far.
@@ -331,11 +337,11 @@
* @since 1.5
*/
public long getBytesWritten() {
synchronized (zsRef) {
ensureOpen();
- return getBytesWritten(zsRef.address());
+ return bytesWritten;
}
}
/**
* Resets inflater so that a new set of input data can be processed.
@@ -346,10 +352,11 @@
reset(zsRef.address());
buf = defaultBuf;
finished = false;
needDict = false;
off = len = 0;
+ bytesRead = bytesWritten = 0;
}
}
/**
* Closes the decompressor and discards any unprocessed input.
@@ -393,10 +400,8 @@
private native static void setDictionary(long addr, byte[] b, int off,
int len);
private native int inflateBytes(long addr, byte[] b, int off, int len)
throws DataFormatException;
private native static int getAdler(long addr);
- private native static long getBytesRead(long addr);
- private native static long getBytesWritten(long addr);
private native static void reset(long addr);
private native static void end(long addr);
}