The Carbon Java Framework  

The Carbon Utilities Subsystem

Enumerations Usage

Printer Friendly Version

Author: Douglas Voet (dvoet at
Version: $Revision: 1.2 $($Author: araman $ / $Date: 2003/05/05 07:44:12 $)
Created: May 2003


The classes in the java.util.jar package provide funtionality to read and write jar files. In order to read the contents of a specific entry of a jar file, the JarFile class has a method, getInputStream, that returns an input stream for a specific entry. There is no method, however, to get an output stream for a specific jar entry. The classes of the org.sape.carbon.core.util.jar package implement this functionality.


The EnhancedJarFile class behaves exactly like a java.util.jar.JarFile with the addition of the method getEntryOutputStream. This method returns a JarEntryOutputStream for given entry name. The JarEntryOutputStream buffers all data that is written to it until it is closed. When it is closed, the jar is rewritten entry for entry with the entry that is the target of the JarEntryOutputStream replaced with the new data. When the new jar is written, it is written to a temporary jar file first, then the original is replaced with the new. Note that this is not a thread-safe operation. In a multi-threaded environment, only one writer should be allowed at a time to avoid loss of data.

Copyright © 2001-2003, Sapient Corporation