diff options
author | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-04-01 21:28:45 +0000 |
---|---|---|
committer | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-04-01 21:28:45 +0000 |
commit | 1e3cd04be9565704fb97be6d733636dea0442cf2 (patch) | |
tree | 9640fc2c26ad169c5b16796e5cb191e977dd682c /libjava/java/util/zip/DeflaterOutputStream.java | |
parent | a0844d0b2adf3473c349db54ab230588c4422551 (diff) | |
download | ppe42-gcc-1e3cd04be9565704fb97be6d733636dea0442cf2.tar.gz ppe42-gcc-1e3cd04be9565704fb97be6d733636dea0442cf2.zip |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@40988 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/util/zip/DeflaterOutputStream.java')
-rw-r--r-- | libjava/java/util/zip/DeflaterOutputStream.java | 48 |
1 files changed, 39 insertions, 9 deletions
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; |