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

Append facility on zip archives (ZipOutputStream)

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • x86
    • windows_95



      Name: krT82822 Date: 05/01/99


      I'm sure this is well known already, so it's not really a
      bug, but it is definitely a pain.

      Here's code explaining the problem:

      // If I open a ZipOutputStream based on an existing File
      ZipOutputStream zip = new ZipOutputStream(
             new BufferedOutputStream(
             new FileOutputStream(
             new File( existingFileNameString ) ) ) );

      // and try to write additional data to it
      ZipEntry entry = new ZipEntry( "Another entry" );

      zip.putNextEntry( entry );
      zip.write( ( "StuffIWantToWrite" ).getBytes() );
      zip.closeEntry();
      zip.close();


      // Then I get ZipExceptions 'duplicate entry'.
      // This is no surprise.
      // But even if I open the ZipOutputStream with the
      // underlying FileOuputStream in append mode:

      ZipOutputStream zip = new ZipOutputStream(
             new BufferedOutputStream(
             new FileOutputStream( existingFileNameString, true ) ) );

      // ... then I get no Exceptions, but the resulting zip
      // archive is no good.

      What I think happens (I know nothing about the zip format,
      so this is a guess) is that the end of the file is found and the
      data appended, but the previous zip index data is not read and
      updated correctly. This is borne out by the way that the zip
      gets corrupted ie the file size increases by about the amount I
      would expect, but only the entries appended are correctly
      indexed. This means I can no longer get at the data originally
      in the archive.
      (Review ID: 57632)
      ======================================================================

            zlisunw Zhenghua Li (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: