SUGGESTED FIX
---- src/share/classes/java/util/zip/ZipFile.java
*** /tmp/23124aaa Tue Jan 2 09:01:52 2001
--- ZipFile.java Mon Jan 1 15:37:58 2001
***************
*** 192,203 ****
if (jzentry == 0) {
return null;
}
! InputStream in = new ZipFileInputStream(jzfile, jzentry, this);
switch (getMethod(jzentry)) {
case STORED:
! return in;
case DEFLATED:
! return new InflaterInputStream(in, getInflater()) {
private boolean isClosed = false;
public void close() throws IOException {
--- 192,204 ----
if (jzentry == 0) {
return null;
}
! final ZipFileInputStream zfin
! = new ZipFileInputStream(jzfile, jzentry, this);
switch (getMethod(jzentry)) {
case STORED:
! return zfin;
case DEFLATED:
! return new InflaterInputStream(zfin, getInflater()) {
private boolean isClosed = false;
public void close() throws IOException {
***************
*** 227,233 ****
public int available() throws IOException {
if (super.available() != 0) {
! return this.in.available();
} else {
return 0;
}
--- 228,234 ----
public int available() throws IOException {
if (super.available() != 0) {
! return zfin.size() - inf.getTotalOut();
} else {
return 0;
}
***************
*** 367,374 ****
}
}
! /*
! * Inner class implementing the input stream used to read a zip file entry.
*/
private static class ZipFileInputStream extends InputStream {
private long jzfile; // address of jzfile data
--- 368,375 ----
}
}
! /* Inner class implementing the input stream used to read a
! * (possibly compressed) zip file entry.
*/
private static class ZipFileInputStream extends InputStream {
private long jzfile; // address of jzfile data
***************
*** 383,389 ****
this.jzentry = jzentry;
pos = 0;
rem = getCSize(jzentry);
! size = getSize(jzentry);
this.handle = zf;
}
--- 384,390 ----
this.jzentry = jzentry;
pos = 0;
rem = getCSize(jzentry);
! size = getSize(jzentry);
this.handle = zf;
}
***************
*** 428,435 ****
}
public int available() {
! return size;
}
private void cleanup() {
rem = 0;
--- 429,440 ----
}
public int available() {
! return rem;
}
+
+ public int size() {
+ return size;
+ }
private void cleanup() {
rem = 0;
---- src/share/classes/java/util/zip/ZipInputStream.java
*** /tmp/23133aaa Tue Jan 2 09:01:52 2001
--- ZipInputStream.java Mon Jan 1 15:49:34 2001
***************
*** 107,117 ****
*/
public int available() throws IOException {
ensureOpen();
! if (entryEOF) {
! return 0;
! } else {
! return 1;
! }
}
/**
--- 107,116 ----
*/
public int available() throws IOException {
ensureOpen();
! if (entryEOF)
! return 0;
! return (int)entry.getSize() - inf.getTotalOut();
! // ## Fix spec
}
/**
---- test/java/util/zip/Available.java
*** /tmp/23160aaa Tue Jan 2 09:01:52 2001
--- Available.java Mon Jan 1 15:38:27 2001
***************
*** 1,34 ****
/* @test %I% %E%
! @bug 4028605 4109069 4234207
! @summary Make sure ZipInputStream/InflaterInputStream.available() will
! return 0 after EOF has reached and 1 otherwise.
! */
!
import java.io.*;
import java.util.zip.*;
public class Available {
! static void test(InputStream in) throws Exception {
byte[] buf = new byte[1024];
! int n;
! while ((n = in.read(buf)) != -1);
! if (in.available() != 0) {
! throw new Exception("available should return 0 after EOF");
! }
}
public static void main(String[] args) throws Exception {
! File f = new File(System.getProperty("test.src", "."), "input.jar");
// test ZipInputStream
! ZipInputStream z = new ZipInputStream(new FileInputStream(f));
! z.getNextEntry();
! test(z);
!
// test InflaterInputStream
! ZipFile zfile = new ZipFile(f);
! test(zfile.getInputStream(zfile.getEntry("Available.java")));
}
}
--- 1,68 ----
/* @test %I% %E%
! @bug 4028605 4109069 4234207 4400697
! @summary Make sure ZipInputStream/InflaterInputStream.available()
! returns zero just before, and after, EOF is reached
! */
import java.io.*;
import java.util.zip.*;
+
public class Available {
!
! private static interface InputStreamMaker {
! public InputStream make() throws IOException;
! }
!
! static void test(InputStreamMaker ism) throws Exception {
byte[] buf = new byte[1024];
! int n, t = 0;
!
! // Test behavior after EOF, and note length of entry
! InputStream in = ism.make();
! System.err.println(in + ": " + in.available());
! while ((n = in.read(buf)) != -1)
! t += n;
! if ((n = in.available()) != 0)
! throw new Exception("available() returned " + n + " after EOF");
! // Ensure that available() never exceeds the number of bytes remaining
! in = ism.make();
! int r = t;
! for (;;) {
! if ((n = in.available()) > r)
! throw new Exception("available() returned " + n
! + " with only " + r + " bytes remaining");
! if ((n = in.read(buf, 0, 1)) == -1)
! break;
! r -= n;
! }
! if (r != 0)
! throw new Exception("Did not read entire entry");
}
public static void main(String[] args) throws Exception {
! final File f;
! if (args.length > 0)
! f = new File(args[0]);
! else
! f = new File(System.getProperty("test.src", "."), "input.jar");
// test ZipInputStream
! test(new InputStreamMaker() {
! public InputStream make() throws IOException {
! ZipInputStream z
! = new ZipInputStream(new FileInputStream(f));
! z.getNextEntry();
! return z;
! }});
!
// test InflaterInputStream
! test(new InputStreamMaker() {
! public InputStream make() throws IOException {
! ZipFile zf = new ZipFile(f);
! return zf.getInputStream(zf.getEntry("Available.java"));
! }});
}
+
}
|