org.sape.carbon.core.util.jar
Class JarEntryOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.ByteArrayOutputStream
              |
              +--org.sape.carbon.core.util.jar.JarEntryOutputStream

public class JarEntryOutputStream
extends ByteArrayOutputStream

An output stream that is used by EnhancedJarFile to write entries to a jar. This implementation uses a ByteArrayOutputStream to buffer the output until the stream is closed. When the stream is closed, the output is written to the jar. Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.9 $($Author: dvoet $ / $Date: 2003/05/05 21:21:23 $)
Author:
Douglas Voet, April 2002

Field Summary
private  EnhancedJarFile jar
           
private  String jarEntryName
           
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
JarEntryOutputStream(EnhancedJarFile jar, String jarEntryName)
          Constructor
 
Method Summary
 void close()
          Closes the stream and writes entry to the jar
private  void writeToJar()
          Writes the entry to a the jar file.
 
Methods inherited from class java.io.ByteArrayOutputStream
reset, size, toByteArray, toString, toString, toString, write, write, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jar

private EnhancedJarFile jar

jarEntryName

private String jarEntryName
Constructor Detail

JarEntryOutputStream

public JarEntryOutputStream(EnhancedJarFile jar,
                            String jarEntryName)
Constructor

Parameters:
jar - the EnhancedJarFile that this instance will write to
jarEntryName - the name of the entry to be written
Method Detail

close

public void close()
           throws IOException
Closes the stream and writes entry to the jar

Overrides:
close in class ByteArrayOutputStream
IOException

writeToJar

private void writeToJar()
                 throws IOException
Writes the entry to a the jar file. This is done by creating a temporary jar file, copying the contents of the existing jar to the temp jar, skipping the entry named by this.jarEntryName if it exists. Then, if the stream was written to, then contents are written as a new entry. Last, a callback is made to the EnhancedJarFile to swap the temp jar in for the old jar.

IOException


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.