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
This commit is contained in:
Per Bothner 2001-04-01 14:28:45 -07:00 committed by Per Bothner
parent aa9de837a8
commit f44b63ae02
3 changed files with 110 additions and 51 deletions

View file

@ -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;