JDK-4234739 : Append facility on zip archives (ZipOutputStream)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1999-05-01
  • Updated: 1999-09-09
  • Resolved: 1999-09-09
Related Reports
Duplicate :  

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

// 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) 

WORK AROUND Name: krT82822 Date: 05/01/99 There are obvious workarounds but they're pretty painful, and slow the application down considerably because the data has to inflated and stored and all written out to file every time I to append some new results. ======================================================================

EVALUATION ZipOutputStream is a sequential stream, not meant for random access to a particular entry. ZipFile supports random access functionality. See bug 4129445 for more details. ###@###.### 1999-09-09