ZipInputStream.java (fill): New method.
* java/util/zip/ZipInputStream.java (fill): New method. (compressed_len): New instance variable. (getNextStream): Set it. (read): Reset inflater on EOF. Only read via `super' if entry is deflated. (skip): Only skip via `super' if entry is deflated. * java/util/zip/Deflater.java (last_input_count): Removed. * java/util/zip/natDeflater.cc (deflate): Return 0 if input array is length 0. (needsInput): Don't use last_input_count. (setInput): Don't set last_input_count. * java/util/zip/natInflater.cc (getRemaining): Return correct result. (inflate): Return 0 if input array is length 0. (setInput): Don't set last_input_count. * java/util/zip/Inflater.java (last_input_count): Removed. From-SVN: r27105
This commit is contained in:
parent
5256aa37b4
commit
93d627acaa
@ -1,3 +1,22 @@
|
||||
1999-05-22 Tom Tromey <tromey@cygnus.com>
|
||||
|
||||
* java/util/zip/ZipInputStream.java (fill): New method.
|
||||
(compressed_len): New instance variable.
|
||||
(getNextStream): Set it.
|
||||
(read): Reset inflater on EOF. Only read via `super' if entry is
|
||||
deflated.
|
||||
(skip): Only skip via `super' if entry is deflated.
|
||||
* java/util/zip/Deflater.java (last_input_count): Removed.
|
||||
* java/util/zip/natDeflater.cc (deflate): Return 0 if input array
|
||||
is length 0.
|
||||
(needsInput): Don't use last_input_count.
|
||||
(setInput): Don't set last_input_count.
|
||||
* java/util/zip/natInflater.cc (getRemaining): Return correct
|
||||
result.
|
||||
(inflate): Return 0 if input array is length 0.
|
||||
(setInput): Don't set last_input_count.
|
||||
* java/util/zip/Inflater.java (last_input_count): Removed.
|
||||
|
||||
1999-05-21 Tom Tromey <tromey@cygnus.com>
|
||||
|
||||
* Makefile.in: Rebuilt.
|
||||
|
@ -124,9 +124,6 @@ public class Deflater
|
||||
// True if finished.
|
||||
private boolean is_finished;
|
||||
|
||||
// Total number of bytes made available at last setInput.
|
||||
private int last_input_count;
|
||||
|
||||
// `Flush' flag to pass to next call to deflate.
|
||||
private int flush_flag;
|
||||
}
|
||||
|
@ -95,7 +95,4 @@ public class Inflater
|
||||
|
||||
// True if dictionary needed.
|
||||
private boolean dict_needed;
|
||||
|
||||
// Total number of bytes made available at last setInput.
|
||||
private int last_input_count;
|
||||
}
|
||||
|
@ -28,13 +28,9 @@ import java.io.*;
|
||||
|
||||
public class ZipInputStream extends InflaterInputStream
|
||||
{
|
||||
ZipEntry current;
|
||||
int current_flags;
|
||||
int avail;
|
||||
|
||||
public ZipInputStream (InputStream in)
|
||||
{
|
||||
super(in);
|
||||
super (in, new Inflater (true));
|
||||
}
|
||||
|
||||
public ZipEntry getNextEntry () throws IOException
|
||||
@ -101,15 +97,41 @@ public class ZipInputStream extends InflaterInputStream
|
||||
entry.time = ZipEntry.timeFromDOS(moddate, modtime);
|
||||
current = entry;
|
||||
avail = uncompressedSize;
|
||||
compressed_bytes = compressedSize;
|
||||
return entry;
|
||||
}
|
||||
|
||||
// We override fill to let us control how much data gets read from
|
||||
// the underlying input stream. This lets us avoid having to push
|
||||
// back data.
|
||||
protected void fill () throws IOException
|
||||
{
|
||||
int count = buf.length;
|
||||
if (count > compressed_bytes)
|
||||
count = compressed_bytes;
|
||||
len = in.read(buf, 0, count);
|
||||
if (len != -1)
|
||||
{
|
||||
compressed_bytes -= len;
|
||||
inf.setInput(buf, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public int read (byte[] b, int off, int len) throws IOException
|
||||
{
|
||||
if (len > avail)
|
||||
len = avail;
|
||||
int count = super.read(b, off, len);
|
||||
if (count > 0)
|
||||
int count;
|
||||
if (current.method == Deflater.DEFLATED)
|
||||
count = super.read(b, off, len);
|
||||
else
|
||||
count = in.read(b, off, len);
|
||||
if (count == -1 || avail == 0)
|
||||
{
|
||||
inf.reset();
|
||||
count = -1;
|
||||
}
|
||||
else
|
||||
avail -= count;
|
||||
return count;
|
||||
}
|
||||
@ -118,7 +140,11 @@ public class ZipInputStream extends InflaterInputStream
|
||||
{
|
||||
if (n > avail)
|
||||
n = avail;
|
||||
long count = super.skip(n);
|
||||
long count;
|
||||
if (current.method == Deflater.DEFLATED)
|
||||
count = super.skip(n);
|
||||
else
|
||||
count = in.skip(n);
|
||||
avail = avail - (int) count;
|
||||
return count;
|
||||
}
|
||||
@ -187,4 +213,11 @@ public class ZipInputStream extends InflaterInputStream
|
||||
current = null;
|
||||
super.close();
|
||||
}
|
||||
|
||||
private ZipEntry current;
|
||||
private int current_flags;
|
||||
// Number of uncompressed bytes to be read.
|
||||
private int avail;
|
||||
// Number of bytes we can read from underlying stream.
|
||||
private int compressed_bytes;
|
||||
}
|
||||
|
@ -41,6 +41,9 @@ java::util::zip::Deflater::deflate (jbyteArray buf, jint off, jint len)
|
||||
if (off < 0 || len < 0 || off + len > buf->length)
|
||||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
s->next_out = (Bytef *) (elements (buf) + off);
|
||||
s->avail_out = len;
|
||||
|
||||
@ -111,7 +114,7 @@ java::util::zip::Deflater::needsInput ()
|
||||
{
|
||||
JvSynchronize sync (this);
|
||||
z_streamp s = (z_streamp) zstream;
|
||||
return s->avail_in - last_input_count == 0;
|
||||
return s->avail_in == 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -150,7 +153,6 @@ java::util::zip::Deflater::setInput (jbyteArray buf, jint off, jint len)
|
||||
if (off < 0 || len < 0 || off + len > buf->length)
|
||||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||||
|
||||
last_input_count = len;
|
||||
s->next_in = (Bytef *) (elements (buf) + off);
|
||||
s->avail_in = len;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ java::util::zip::Inflater::getRemaining ()
|
||||
{
|
||||
JvSynchronize sync (this);
|
||||
z_streamp s = (z_streamp) zstream;
|
||||
return s->avail_in - last_input_count;
|
||||
return s->avail_in;
|
||||
}
|
||||
|
||||
jint
|
||||
@ -98,6 +98,9 @@ java::util::zip::Inflater::inflate (jbyteArray buf, jint off, jint len)
|
||||
if (off < 0 || len < 0 || off + len > buf->length)
|
||||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
s->next_out = (Bytef *) (elements (buf) + off);
|
||||
s->avail_out = len;
|
||||
|
||||
@ -169,7 +172,6 @@ java::util::zip::Inflater::setInput (jbyteArray buf, jint off, jint len)
|
||||
if (off < 0 || len < 0 || off + len > buf->length)
|
||||
_Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
|
||||
|
||||
last_input_count = len;
|
||||
s->next_in = (Bytef *) (elements (buf) + off);
|
||||
s->avail_in = len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user