com.izforge.izpack.util
Class JarOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.apache.tools.zip.ZipOutputStream
              extended by com.izforge.izpack.util.JarOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class JarOutputStream
extends org.apache.tools.zip.ZipOutputStream

IzPack will be able to support different compression methods for the packs included in the installation jar file. For this a jar output stream will be needed with which the info data (size, CRC) can be written after the compressed data. This is not possible with the standard class java.util.jar.JarOutputStream. Therefore we create an own class which supports it. Really the hole work will be delegated to the ZipOutputStream from the apache team which solves the problem.

Author:
Klaus Bartz

Field Summary
private  boolean firstEntry
           
private static int JAR_MAGIC
           
private  boolean preventClose
           
 
Fields inherited from class org.apache.tools.zip.ZipOutputStream
buf, CFH_SIG, DD_SIG, def, DEFAULT_COMPRESSION, DEFLATED, EOCD_SIG, LFH_SIG, STORED
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
JarOutputStream(java.io.File arg0)
          Creates a new JarOutputStream with no manifest.
JarOutputStream(java.io.File fout, java.util.jar.Manifest man)
          Creates a new JarOutputStream with the specified Manifest.
JarOutputStream(java.io.OutputStream out)
          Creates a new JarOutputStream with no manifest.
 
Method Summary
 void close()
          Closes this output stream and releases any system resources associated with the stream if isPreventClose is not true.
 void closeAlways()
          Closes this output stream and releases any system resources associated with the stream also isPreventClose is true.
private static int get16(byte[] b, int off)
           
private static boolean hasMagic(byte[] edata)
           
 boolean isPreventClose()
           
 void putNextEntry(org.apache.tools.zip.ZipEntry ze)
          Begins writing a new JAR file entry and positions the stream to the start of the entry data.
private static void set16(byte[] b, int off, int value)
           
 void setPreventClose(boolean preventClose)
          Determine whether a call of the close method will be performed or not.
 
Methods inherited from class org.apache.tools.zip.ZipOutputStream
adjustToLong, closeEntry, deflate, finish, flush, getBytes, getEncoding, isSeekable, setComment, setEncoding, setLevel, setMethod, toDosTime, toDosTime, write, write, writeCentralDirectoryEnd, writeCentralFileHeader, writeDataDescriptor, writeLocalFileHeader, writeOut, writeOut
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAR_MAGIC

private static final int JAR_MAGIC
See Also:
Constant Field Values

firstEntry

private boolean firstEntry

preventClose

private boolean preventClose
Constructor Detail

JarOutputStream

public JarOutputStream(java.io.OutputStream out)
                throws java.io.IOException
Creates a new JarOutputStream with no manifest. Using this constructor it will be NOT possible to write data with compression format STORED to the stream without declare the info data (size, CRC) at putNextEntry.

Parameters:
out - the actual output stream
Throws:
java.io.IOException - if an I/O error has occurred

JarOutputStream

public JarOutputStream(java.io.File fout,
                       java.util.jar.Manifest man)
                throws java.io.IOException
Creates a new JarOutputStream with the specified Manifest. The manifest is written as the first entry to the output stream which will be created from the file argument.

Parameters:
fout - the file object with which the output stream should be created
man - the Manifest
Throws:
java.io.IOException - if an I/O error has occurred

JarOutputStream

public JarOutputStream(java.io.File arg0)
                throws java.io.IOException
Creates a new JarOutputStream with no manifest. Will use random access if possible.

Parameters:
arg0 - the file object with which the output stream should be created
Throws:
java.io.IOException
Method Detail

putNextEntry

public void putNextEntry(org.apache.tools.zip.ZipEntry ze)
                  throws java.io.IOException
Begins writing a new JAR file entry and positions the stream to the start of the entry data. This method will also close any previous entry. The default compression method will be used if no compression method was specified for the entry. The current time will be used if the entry has no set modification time.

Overrides:
putNextEntry in class org.apache.tools.zip.ZipOutputStream
Parameters:
ze - the ZIP/JAR entry to be written
Throws:
ZipException - if a ZIP error has occurred
java.io.IOException - if an I/O error has occurred

isPreventClose

public boolean isPreventClose()
Returns:
Returns the preventClose.

setPreventClose

public void setPreventClose(boolean preventClose)
Determine whether a call of the close method will be performed or not. This is a hack for FilterOutputStreams like the CBZip2OutputStream of apache which calls close of the slave via the final method which will be called from the garbage collector.

Parameters:
preventClose - The preventClose to set.

close

public void close()
           throws java.io.IOException
Closes this output stream and releases any system resources associated with the stream if isPreventClose is not true. Else nothing will be done. This is a hack for FilterOutputStreams like the CBZip2OutputStream which calls the close method of the slave at finalizing the class may be triggert by the GC.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class org.apache.tools.zip.ZipOutputStream
Throws:
java.io.IOException - if an I/O error occurs.

closeAlways

public void closeAlways()
                 throws java.io.IOException
Closes this output stream and releases any system resources associated with the stream also isPreventClose is true. This is a hack for FilterOutputStreams like the CBZip2OutputStream which calls the close method of the slave at finalizing the class may be triggert by the GC.

Throws:
java.io.IOException - if an I/O error occurs.

hasMagic

private static boolean hasMagic(byte[] edata)

get16

private static int get16(byte[] b,
                         int off)

set16

private static void set16(byte[] b,
                          int off,
                          int value)