public int read(byte[] b,
int off,
int len) throws IOException {
ensureOpen();
if (off < 0 || len < 0 || off > b.length - len) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
if (entry == null) {
return -1;
}
switch (entry.method) {
case DEFLATED:
len = super.read(b, off, len);
if (len == -1) {
readEnd(entry);
entryEOF = true;
entry = null;
} else {
crc.update(b, off, len);
}
return len;
case STORED:
if (remaining < = 0) {
entryEOF = true;
entry = null;
return -1;
}
if (len > remaining) {
len = (int)remaining;
}
len = in.read(b, off, len);
if (len == -1) {
throw new ZipException("unexpected EOF");
}
crc.update(b, off, len);
remaining -= len;
if (remaining == 0 && entry.crc != crc.getValue()) {
throw new ZipException(
"invalid entry CRC (expected 0x" + Long.toHexString(entry.crc) +
" but got 0x" + Long.toHexString(crc.getValue()) + ")");
}
return len;
default:
throw new ZipException("invalid compression method");
}
}
Reads from the current ZIP entry into an array of bytes.
If len is not zero, the method
blocks until some input is available; otherwise, no
bytes are read and 0 is returned. |
public long skip(long n) throws IOException {
if (n < 0) {
throw new IllegalArgumentException("negative skip length");
}
ensureOpen();
int max = (int)Math.min(n, Integer.MAX_VALUE);
int total = 0;
while (total < max) {
int len = max - total;
if (len > tmpbuf.length) {
len = tmpbuf.length;
}
len = read(tmpbuf, 0, len);
if (len == -1) {
entryEOF = true;
break;
}
total += len;
}
return total;
}
Skips specified number of bytes in the current ZIP entry. |