public void write(byte[] b,
int off,
int len) throws IOException {
// Sanity checks
ensureOpen();
if (b == null) {
throw new NullPointerException("Null buffer for read");
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
// Write uncompressed data to the output stream
try {
for (;;) {
int n;
// Fill the decompressor buffer with output data
if (inf.needsInput()) {
int part;
if (len < 1) {
break;
}
part = (len < 512 ? len : 512);
inf.setInput(b, off, part);
off += part;
len -= part;
}
// Decompress and write blocks of output data
do {
n = inf.inflate(buf, 0, buf.length);
if (n > 0) {
out.write(buf, 0, n);
}
} while (n > 0);
// Check the decompressor
if (inf.finished()) {
break;
}
if (inf.needsDictionary()) {
throw new ZipException("ZLIB dictionary missing");
}
}
} catch (DataFormatException ex) {
// Improperly formatted compressed (ZIP) data
String msg = ex.getMessage();
if (msg == null) {
msg = "Invalid ZLIB data format";
}
throw new ZipException(msg);
}
}
Writes an array of bytes to the uncompressed output stream. |