From f44b63ae02d689ccf33f66022228ee8d7145cfd8 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Sun, 1 Apr 2001 14:28:45 -0700 Subject: DeflaterOutputStream.java (deflate): Loop while def.needsInput. * DeflaterOutputStream.java (deflate): Loop while def.needsInput. (finish): def.deflate needs to be called in a loop. (inbuf, inbufLength): New private fields. (write(int)): Use inbuf. (write(byte[],int,int): Check if pending output in inbuf. * ZipOutputStream.java: Don't use Deflater if stored. Use a Checksum object directly, not via a CheckedOutputStream. (uncompressed_size): New field, (closeEntry): Only write data_directory if needed. (write): If STORED, write directly. Always update crc, and uncompressed_size. (write_entry): Fix lots of protocol erors. From-SVN: r40988 --- libjava/java/util/zip/DeflaterOutputStream.java | 48 ++++++++++++++++++++----- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'libjava/java/util/zip/DeflaterOutputStream.java') diff --git a/libjava/java/util/zip/DeflaterOutputStream.java b/libjava/java/util/zip/DeflaterOutputStream.java index d4218fa5cc5..7a1dbb2cf66 100644 --- a/libjava/java/util/zip/DeflaterOutputStream.java +++ b/libjava/java/util/zip/DeflaterOutputStream.java @@ -50,13 +50,13 @@ public class DeflaterOutputStream extends FilterOutputStream protected void deflate () throws IOException { - while (true) + do { int len = def.deflate(buf, 0, buf.length); - if (len == 0 || len == -1) - break; - out.write(buf, 0, len); - } + if (len > 0) + out.write(buf, 0, len); + } + while (! def.needsInput()); } public DeflaterOutputStream (OutputStream out) @@ -78,23 +78,53 @@ public class DeflaterOutputStream extends FilterOutputStream public void finish () throws IOException { + if (inbufLength > 0) + { + def.setInput (inbuf, 0, inbufLength); + deflate (); + inbufLength = 0; + } def.finish(); - deflate (); + while (! def.finished ()) + { + int len = def.deflate(buf, 0, buf.length); + if (len > 0) + out.write(buf, 0, len); + } } public void write (int bval) throws IOException { - byte[] b = new byte[1]; - b[0] = (byte) bval; - write (b, 0, 1); + if (inbuf == null) + { + inbuf = new byte[128]; + } + else if (inbufLength == inbuf.length) + { + def.setInput (inbuf, 0, inbufLength); + deflate (); + inbufLength = 0; + } + inbuf[inbufLength++] = (byte) bval; } public void write (byte[] buf, int off, int len) throws IOException { + if (inbufLength > 0) + { + def.setInput (inbuf, 0, inbufLength); + deflate (); + inbufLength = 0; + } def.setInput (buf, off, len); deflate (); } + // Used, if needed, for write(int). + private byte[] inbuf; + // Used length of inbuf. + private int inbufLength; + // The retrieval buffer. protected byte[] buf; -- cgit v1.2.3