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

Clarify that ZipInputStream does not access the CEN fields for a ZipEntry

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 20
    • core-libs
    • None
    • behavioral
    • minimal
    • There is no change in behavior. The updates made to the class description are intended to document the long standing behavior of this class
    • Java API
    • SE

    Description

      Summary

      Update the ZipInputStream class description to indicate that read each Zip Entry by accessing the entry's LOC header and that the entry's CEN header is not accessed resulting in the CEN metadata not being available.

      Problem

      The ZipInputStream class description does not indicate how each Zip entry is accessed and therefore will not have access to all of its metadata such as the external file attributes which is stored in the CEN header for the Zip entry.

      Solution

      The class description will be updated to describe that each Zip Entry is accessed by reading its LOC header and not its CEN header.

      Specification

      The ZipInputStream Class description will be updated as follows:

      An input stream for reading compressed and uncompressed ZIP file entries from a stream of bytes in the ZIP file format. Reading Zip File Entries

      The getNextEntry() method is used to read the next ZIP file entry (Local file (LOC) header record in the ZIP format) and position the stream at the entry's file data. The file data may read using one of the ZipInputStream read methods such as read or readAllBytes(). For example:

      CopyCopy
        Path jar = Path.of("foo.jar");
        try (InputStream is = Files.newInputStream(jar);
             ZipInputStream zis = new ZipInputStream(is)) {
            ZipEntry ze;
            while((ze= zis.getNextEntry()) != null) {
               var bytes = zis.readAllBytes();
               System.out.printf("Entry: %s, bytes read: %s%n", ze.getName(),
                       bytes.length);
            }
        }

      API Note: The LOC header contains metadata about the Zip file entry. ZipInputStream does not read the Central directory (CEN) header for the entry and therefore will not have access to its metadata such as the external file attributes. ZipFile may be used when the information stored within the CEN header is required.

      Attachments

        Issue Links

          Activity

            People

              lancea Lance Andersen
              ihse Magnus Ihse Bursie
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: