Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4028605

ZipInputStream.available() incorrect after entry EOF

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.1
    • core-libs
    • None
    • 1.2fcs
    • sparc
    • solaris_2.5.1
    • Not verified

      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();
      }
          }
      }

      ----

            zlisunw Zhenghua Li (Inactive)
            mr Mark Reinhold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: