TrueZIP 6.8.3

de.schlichtherle.io.archive.zip
Class ZipOutputArchive

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by de.schlichtherle.util.zip.BasicZipOutputStream
              extended by de.schlichtherle.io.archive.zip.ZipOutputArchive
All Implemented Interfaces:
OutputArchive, Closeable, Flushable
Direct Known Subclasses:
CheckedZip32OutputArchive, Zip32OutputArchive

public class ZipOutputArchive
extends BasicZipOutputStream
implements OutputArchive

An implementation of OutputArchive to write ZIP archives.

This output archive can only write one entry at a time. Archive drivers may wrap this class in a MultiplexedOutputArchive to overcome this limitation.

Since:
TrueZIP 6.7
Author:
Christian Schlichtherle
See Also:
ZipDriver

Nested Class Summary
private static class ZipOutputArchive.Crc32OutputStream
           
private  class ZipOutputArchive.EntryOutputStream
          This entry output stream writes directly to our subclass.
private  class ZipOutputArchive.TempEntryOutputStream
          This entry output stream writes the entry to a temporary file.
 
Field Summary
private  OutputArchiveMetaData metaData
           
private  ZipInputArchive source
           
private static String TEMP_FILE_PREFIX
          Prefix for temporary files created by the multiplexer.
private  ZipEntry tempEntry
           
 
Fields inherited from class de.schlichtherle.util.zip.BasicZipOutputStream
DEFAULT_CHARSET
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ZipOutputArchive(OutputStream out, String charset, int level, ZipInputArchive source)
          Creates a new instance which uses the output stream, character set and compression level.
ZipOutputArchive(OutputStream out, String charset, ZipInputArchive source)
          Deprecated.  
 
Method Summary
 void finish()
          Retain the postamble of the source ZIP archive, if any.
 Enumeration getArchiveEntries()
          Returns an enumeration of the ArchiveEntry instances in this archive (i.e. written so far).
 ArchiveEntry getArchiveEntry(String entryName)
          Returns the ArchiveEntry for the given entry name or null if no entry with this name has been written or started to be written.
 OutputArchiveMetaData getMetaData()
          Returns the meta data for this input archive.
 int getNumArchiveEntries()
          Returns the number of ArchiveEntry instances in this archive.
 OutputStream getOutputStream(ArchiveEntry dstEntry, ArchiveEntry srcEntry)
          Returns a new OutputStream for writing the contents of the given archive entry.
 boolean isBusy()
          Returns whether this output archive is busy writing an archive entry or not.
 void setMetaData(OutputArchiveMetaData metaData)
          Sets the meta data for this input archive.
 void storeDirectory(ArchiveEntry entry)
          Deprecated. This method will be removed in the next major version number release and should be implemented as getOutputStream(entry, null).close().
private  void storeTempEntry(ZipEntry entry, File temp)
           
 
Methods inherited from class de.schlichtherle.util.zip.BasicZipOutputStream
close, closeEntry, entries, getComment, getEncoding, getEntry, getLevel, getMethod, length, putNextEntry, putNextEntry, setComment, setLevel, setMethod, size, write, write
 
Methods inherited from class java.io.FilterOutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.schlichtherle.io.archive.spi.OutputArchive
close
 

Field Detail

TEMP_FILE_PREFIX

private static final String TEMP_FILE_PREFIX
Prefix for temporary files created by the multiplexer.

See Also:
Constant Field Values

source

private final ZipInputArchive source

metaData

private OutputArchiveMetaData metaData

tempEntry

private ZipEntry tempEntry
Constructor Detail

ZipOutputArchive

public ZipOutputArchive(OutputStream out,
                        String charset,
                        ZipInputArchive source)
                 throws NullPointerException,
                        UnsupportedEncodingException,
                        IOException
Deprecated. 

Throws:
NullPointerException
UnsupportedEncodingException
IOException

ZipOutputArchive

public ZipOutputArchive(OutputStream out,
                        String charset,
                        int level,
                        ZipInputArchive source)
                 throws NullPointerException,
                        UnsupportedEncodingException,
                        IOException
Creates a new instance which uses the output stream, character set and compression level.

Parameters:
level - The compression level to use.
Throws:
IllegalArgumentException - If level is not in the range [1..9] and is not -1.
NullPointerException
UnsupportedEncodingException
IOException
Method Detail

getNumArchiveEntries

public int getNumArchiveEntries()
Description copied from interface: OutputArchive
Returns the number of ArchiveEntry instances in this archive.

This method may be called before the archive is closed and must also reflect entries which have not yet been closed.

Specified by:
getNumArchiveEntries in interface OutputArchive

getArchiveEntries

public Enumeration getArchiveEntries()
Description copied from interface: OutputArchive
Returns an enumeration of the ArchiveEntry instances in this archive (i.e. written so far).

This method may be called before the archive is closed and must also reflect entries which have not yet been closed.

Specified by:
getArchiveEntries in interface OutputArchive

getArchiveEntry

public ArchiveEntry getArchiveEntry(String entryName)
Description copied from interface: OutputArchive
Returns the ArchiveEntry for the given entry name or null if no entry with this name has been written or started to be written.

This method may be called before the archive is closed and must also reflect entries which have not yet been closed.

Specified by:
getArchiveEntry in interface OutputArchive
Parameters:
entryName - A valid archive entry name - never null.
See Also:
Requirements for Archive Entry Names

getOutputStream

public OutputStream getOutputStream(ArchiveEntry dstEntry,
                                    ArchiveEntry srcEntry)
                             throws IOException
Description copied from interface: OutputArchive
Returns a new OutputStream for writing the contents of the given archive entry.

The returned stream should preferrably be unbuffered, as buffering is usually done in higher layers (all copy routines in TrueZIP do this and most client applications do it, too). Buffering twice does not increase, but decrease performance.

Note that the stream is guaranteed to be closed before the OutputArchive.close() method of this archive is called!

Specified by:
getOutputStream in interface OutputArchive
Parameters:
dstEntry - A valid reference to an archive entry. The runtime class of this entry is the same as the runtime class of the entries returned by ArchiveDriver.createArchiveEntry(de.schlichtherle.io.archive.Archive, java.lang.String, de.schlichtherle.io.archive.spi.ArchiveEntry).
srcEntry - If not null, this identifies the entry from which TrueZIP is actually copying data from and should be used to implement the Direct Data Copying (DDC) feature. Note that there is no guarantee on the runtime type of this object; it may have been created by other drivers. Furthermore, this not exclusively used for archive copies, so you should not simply copy all properties of the source entry to the entry (see ArchiveDriver.createArchiveEntry(Archive, String, ArchiveEntry) for comparison).

For example, the ZIP driver family uses this to copy the already deflated data if the source entry is another ZIP file entry. As another example, the TarDriver uses this to determine the size of the input file, thereby removing the need to create (yet another) temporary file.

Returns:
A (preferrably unbuffered) OutputStream to write the archive entry data to. null is not allowed!
Throws:
OutputArchiveBusyException - If the archive is currently busy on output for another entry. This exception is guaranteed to be recoverable, meaning it should be possible to write the same entry again as soon as the archive is not busy on output anymore.
FileNotFoundException - If the archive entry is not accessible for some reason.
IOException - On any other exceptional condition.

isBusy

public final boolean isBusy()
Returns whether this output archive is busy writing an archive entry or not.

Overrides:
isBusy in class BasicZipOutputStream

storeTempEntry

private void storeTempEntry(ZipEntry entry,
                            File temp)
                     throws IOException
Throws:
IOException

storeDirectory

public final void storeDirectory(ArchiveEntry entry)
                          throws IOException
Deprecated. This method will be removed in the next major version number release and should be implemented as getOutputStream(entry, null).close().

Description copied from interface: OutputArchive
Writes the given entry as a directory enry.

Specified by:
storeDirectory in interface OutputArchive
Parameters:
entry - The archive entry to write. This is never null and safe to be casted to the archive entry type actually created by the ArchiveDriver.createArchiveEntry(de.schlichtherle.io.archive.Archive, java.lang.String, de.schlichtherle.io.archive.spi.ArchiveEntry) method.
Throws:
IOException - On any exceptional condition.

finish

public void finish()
            throws IOException
Retain the postamble of the source ZIP archive, if any.

Overrides:
finish in class BasicZipOutputStream
Throws:
ZipException - If and only if writing the entry is impossible because the resulting file would not comply to the ZIP file format specification.
IOException - On any I/O related issue.

getMetaData

public OutputArchiveMetaData getMetaData()
Description copied from interface: OutputArchive
Returns the meta data for this input archive. The default value is null.

Specified by:
getMetaData in interface OutputArchive

setMetaData

public void setMetaData(OutputArchiveMetaData metaData)
Description copied from interface: OutputArchive
Sets the meta data for this input archive.

Specified by:
setMetaData in interface OutputArchive
Parameters:
metaData - The meta data - may not be null.

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.