The ZipInputStream class does not correctly implement the available method.
This method should return 0 after EOF has been reached, as implied by the
specification of the base InputStream class (JLS 22.3.5). After returning -1
to indicate the end of the current zip entry, the method returns what appears
to be the number of bytes remaining in the entire zip file. This inconsistency
breaks code that checks available() after EOF.
----
import java.io.*;
import java.util.zip.*;
class ZipReady {
public static void main(String[] args) {
try {
ZipInputStream z = new ZipInputStream(System.in);
ZipEntry e = z.getNextEntry();
byte[] buf = new byte[1024];
int n, s = 0;
while ((n = z.read(buf)) != -1)
s += n;
System.out.println("EOF: " + s + " bytes read, " +
z.available() + " bytes available");
}
catch (Exception x) {
x.printStackTrace();
}
}
}
----
This method should return 0 after EOF has been reached, as implied by the
specification of the base InputStream class (JLS 22.3.5). After returning -1
to indicate the end of the current zip entry, the method returns what appears
to be the number of bytes remaining in the entire zip file. This inconsistency
breaks code that checks available() after EOF.
----
import java.io.*;
import java.util.zip.*;
class ZipReady {
public static void main(String[] args) {
try {
ZipInputStream z = new ZipInputStream(System.in);
ZipEntry e = z.getNextEntry();
byte[] buf = new byte[1024];
int n, s = 0;
while ((n = z.read(buf)) != -1)
s += n;
System.out.println("EOF: " + s + " bytes read, " +
z.available() + " bytes available");
}
catch (Exception x) {
x.printStackTrace();
}
}
}
----
- relates to
-
JDK-4028327 bufferedReader bug
-
- Closed
-
-
JDK-4109069 java.util.zip.InflaterInputStream available() and read(byte[]) are broken
-
- Closed
-
-
JDK-4182189 Images loading differerntly from jar vs on disk
-
- Closed
-