United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4234739 : Append facility on zip archives (ZipOutputStream)

Details
Type:
Enhancement
Submit Date:
1999-05-01
Status:
Closed
Updated Date:
1999-09-09
Project Name:
JDK
Resolved Date:
1999-09-09
Component:
core-libs
OS:
windows_95
Sub-Component:
java.util
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.2.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

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

                                    

Comments
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
                                     
1999-09-09
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.
======================================================================
                                     
2004-06-11



Hardware and Software, Engineered to Work Together