src/share/classes/java/util/zip/Deflater.java
Print this page
@@ -77,10 +77,12 @@
private byte[] buf = new byte[0];
private int off, len;
private int level, strategy;
private boolean setParams;
private boolean finish, finished;
+ private long bytesRead;
+ private long bytesWritten;
/**
* Compression method for the deflate algorithm (the only one currently
* supported).
*/
@@ -421,12 +423,17 @@
throw new ArrayIndexOutOfBoundsException();
}
synchronized (zsRef) {
ensureOpen();
if (flush == NO_FLUSH || flush == SYNC_FLUSH ||
- flush == FULL_FLUSH)
- return deflateBytes(zsRef.address(), b, off, len, flush);
+ flush == FULL_FLUSH) {
+ int thisLen = this.len;
+ int n = deflateBytes(zsRef.address(), b, off, len, flush);
+ bytesWritten += n;
+ bytesRead += (thisLen - this.len);
+ return n;
+ }
throw new IllegalArgumentException();
}
}
/**
@@ -460,11 +467,11 @@
* @since 1.5
*/
public long getBytesRead() {
synchronized (zsRef) {
ensureOpen();
- return getBytesRead(zsRef.address());
+ return bytesRead;
}
}
/**
* Returns the total number of compressed bytes output so far.
@@ -486,11 +493,11 @@
* @since 1.5
*/
public long getBytesWritten() {
synchronized (zsRef) {
ensureOpen();
- return getBytesWritten(zsRef.address());
+ return bytesWritten;
}
}
/**
* Resets deflater so that a new set of input data can be processed.
@@ -501,10 +508,11 @@
ensureOpen();
reset(zsRef.address());
finish = false;
finished = false;
off = len = 0;
+ bytesRead = bytesWritten = 0;
}
}
/**
* Closes the compressor and discards any unprocessed input.
@@ -541,10 +549,8 @@
private native static long init(int level, int strategy, boolean nowrap);
private native static void setDictionary(long addr, byte[] b, int off, int len);
private native int deflateBytes(long addr, byte[] b, int off, int len,
int flush);
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);
}