Java Tool Kit

ITT.WAFr.Utilities
Class ZipFile

java.lang.Object
  extended byITT.WAFr.Utilities.ZipFile

public final class ZipFile
extends Object

The ZipFile class provides convenient methods to generate streaming files in ZIP file format.

A ZipFile object can contain multiple sub-file entries in any of the following formats:

Any number of files can be added to the ZipFile object via the numerous Add methods. When all files have been added, the Create method will generate the ZIP file and stream the resulting data to the specified OutputStream.

NOTE: Because the ZipFile class is streaming, none of the methods will throw exceptions. Any exception thrown would end the output stream and result in a partial or corrupted ZIP file. To combat this, the ZipFile class will exclude any failed sub-file entries.

It is not necessary to close the output stream or any added input streams, as the Create method will do so upon completion.

Upon completion of the Create method, various methods are available to retrieve resulting errors and statistics regarding the zipping process.


Field Summary
static int BestCompression
           
static int BestSpeed
           
static int NoCompression
           
 
Constructor Summary
ZipFile()
          Constructs a new ZipFile object with a default compression level of zero (0), or NoCompression.
ZipFile(int iCompression)
          Constructs a new ZipFile object with a compression level of the specified integer from 0 - 9.
 
Method Summary
 void Add(byte[] iFileContent, String sFileName)
          Adds the file represented by the specified byte array to the resulting ZIP file utilizing the specified file name.
 void Add(byte[] iFileContent, String sFileName, String sZipPath)
          Adds the file represented by the specified byte array to the resulting ZIP file utilizing the specified file name.
 void Add(File oFile)
          Adds the file represented by the specified File object to the resulting ZIP file.
 void Add(File oFile, String sZipPath)
          Adds the file represented by the specified File object to the resulting ZIP file.
 void Add(InputStream oFileInput, String sFileName)
          Adds the file represented by the specified InputStream to the resulting ZIP file utilizing the specified file name.
 void Add(InputStream oFileInput, String sFileName, String sZipPath)
          Adds the file represented by the specified InputStream to the resulting ZIP file utilizing the specified file name.
 void Add(String sSourcePath)
          Adds the file at the specified source path to the resulting ZIP file.
 void Add(String sSourcePath, String sZipPath)
          Adds the file at the specified source path to the resulting ZIP file.
 void Add(Upload.PostedFile oPostedFile)
          Adds the file represented by the specified Upload.PostedFile object to the resulting ZIP file.
 void Add(Upload.PostedFile oPostedFile, String sZipPath)
          Adds the file represented by the specified Upload.PostedFile object to the resulting ZIP file.
 void Compression(int iCompression)
          Set the compression level of the ZIP file with the specified integer parameter.
 void Create(OutputStream oOutput)
          Creates a ZIP file with the added sub-file entries and streams the data to the specified output stream.
 int ErrorCount()
          Retrieves the total number of errors that occurred during the zipping process.
 String[] ErrorLog()
          Retrieves an array of error descriptions for each error that occurred during the zipping process.
 int FailedFileCount()
          Retrieves the number of sub-file entries that failed to be added to the resulting ZIP file stream.
 double InputRate()
          Retrieves the number of processed input data in Kilobytes per second, to the nearest tenth KB/s.
 double InputSize()
          Retrieves the number of Kilobytes inputted and processed during the zipping process.
 double OutputRate()
          Retrieves the number of processed output data in Kilobytes per second, to the nearest tenth KB/s.
 double OutputSize()
          Retrieves the size of the ZIP file output stream in Kilobytes.
 double ProcessTime()
          Retrieves the number of seconds, accurate to the millisecond, required to process the resulting ZIP stream.
 String Statistics()
          Retrieves a formatted report of all errors and statistics that occurred during the zipping process.
 int ZippedFileCount()
          Retrieves the number of sub-file entries successfully added and zipped to the resulting ZIP file stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BestCompression

public static final int BestCompression
See Also:
Constant Field Values

BestSpeed

public static final int BestSpeed
See Also:
Constant Field Values

NoCompression

public static final int NoCompression
See Also:
Constant Field Values
Constructor Detail

ZipFile

public ZipFile()
Constructs a new ZipFile object with a default compression level of zero (0), or NoCompression.

See Also:
ZipFile(int)

ZipFile

public ZipFile(int iCompression)
Constructs a new ZipFile object with a compression level of the specified integer from 0 - 9.

A compression level less than 1 will result in the default compression level of NoCompression. Compression levels greater than 8 will result the in the maximum level of BestCompression.

Parameters:
iCompression - an integer from 0 - 9 representing the compression level of the ZIP file.
See Also:
ZipFile(), Compression(int)
Method Detail

Add

public void Add(byte[] iFileContent,
                String sFileName)
Adds the file represented by the specified byte array to the resulting ZIP file utilizing the specified file name.

The sub-file entry will have no path and reside at the top level of the resulting ZIP file.

Parameters:
iFileContent - a byte array representing the content of the sub-file entry to be added to the ZIP file.
sFileName - a String containing the name to use for the sub-file entry within the ZIP file.
See Also:
Add(byte[],String,String)

Add

public void Add(byte[] iFileContent,
                String sFileName,
                String sZipPath)
Adds the file represented by the specified byte array to the resulting ZIP file utilizing the specified file name.

The sub-file entry will reside within the specified relative path within the resulting ZIP file.

Parameters:
iFileContent - a byte array representing the content of the sub-file entry to be added to the ZIP file.
sFileName - a String containing the name to use for the sub-file entry within the ZIP file.
sZipPath - a String containing the relative path for the sub-file entry within the ZIP file.
See Also:
Add(byte[],String)

Add

public void Add(File oFile)
Adds the file represented by the specified File object to the resulting ZIP file.

The sub-file entry will have no path and reside at the top level of the resulting ZIP file.

Parameters:
oFile - a File object representing the sub-file entry to be added to the ZIP file.
See Also:
Add(File,String)

Add

public void Add(File oFile,
                String sZipPath)
Adds the file represented by the specified File object to the resulting ZIP file.

The sub-file entry will reside within the specified relative path within the resulting ZIP file.

Parameters:
oFile - a File object representing the sub-file entry to be added to the ZIP file.
sZipPath - a String containing the relative path for the sub-file entry within the ZIP file.
See Also:
Add(File)

Add

public void Add(InputStream oFileInput,
                String sFileName)
Adds the file represented by the specified InputStream to the resulting ZIP file utilizing the specified file name.

The sub-file entry will have no path and reside at the top level of the resulting ZIP file.

Parameters:
oFileInput - an InputStream containing the content of the sub-file entry to be added to the ZIP file.
sFileName - a String containing the name to use for the sub-file entry within the ZIP file.
See Also:
Add(InputStream,String,String)

Add

public void Add(InputStream oFileInput,
                String sFileName,
                String sZipPath)
Adds the file represented by the specified InputStream to the resulting ZIP file utilizing the specified file name.

The sub-file entry will reside within the specified relative path within the resulting ZIP file.

Parameters:
oFileInput - an InputStream containing the content of the sub-file entry to be added to the ZIP file.
sFileName - a String containing the name to use for the sub-file entry within the ZIP file.
sZipPath - a String containing the relative path for the sub-file entry within the ZIP file.
See Also:
Add(InputStream,String)

Add

public void Add(String sSourcePath)
Adds the file at the specified source path to the resulting ZIP file.

The sub-file entry will have no path and reside at the top level of the resulting ZIP file.

Parameters:
sSourcePath - a String specifying the path to the source file to be added to the ZIP file.
See Also:
Add(String,String)

Add

public void Add(String sSourcePath,
                String sZipPath)
Adds the file at the specified source path to the resulting ZIP file.

The sub-file entry will reside within the specified relative path within the resulting ZIP file.

Parameters:
sSourcePath - a String specifying the path to the source file to be added to the ZIP file.
sZipPath - a String containing the relative path for the sub-file entry within the ZIP file.
See Also:
Add(String)

Add

public void Add(Upload.PostedFile oPostedFile)
Adds the file represented by the specified Upload.PostedFile object to the resulting ZIP file.

The sub-file entry will have no path and reside at the top level of the resulting ZIP file.

Parameters:
oPostedFile - an Upload.PostedFile object representing the sub-file entry to be added to the ZIP file.
See Also:
Add(Upload.PostedFile,String)

Add

public void Add(Upload.PostedFile oPostedFile,
                String sZipPath)
Adds the file represented by the specified Upload.PostedFile object to the resulting ZIP file.

The sub-file entry will reside within the specified relative path within the resulting ZIP file.

Parameters:
oPostedFile - an Upload.PostedFile object representing the sub-file entry to be added to the ZIP file.
sZipPath - a String containing the relative path for the sub-file entry within the ZIP file.
See Also:
Add(Upload.PostedFile)

Compression

public void Compression(int iCompression)
Set the compression level of the ZIP file with the specified integer parameter.

A compression level less than 1 will result in the default compression level of NoCompression.

Compression levels greater than 8 will result the in the maximum level of BestCompression.

Parameters:
iCompression - an integer from 0 - 9 representing the compression level of the ZIP file.

Create

public void Create(OutputStream oOutput)
Creates a ZIP file with the added sub-file entries and streams the data to the specified output stream.

This method closes the specified output stream any input streams passed with the Add method.

Parameters:
oOutput - an OutputStream in which the method will write the processed data.

ErrorCount

public int ErrorCount()
Retrieves the total number of errors that occurred during the zipping process.

Returns:
an integer containing the total number of errors that occurred.
See Also:
ZippedFileCount(), FailedFileCount()

ErrorLog

public String[] ErrorLog()
Retrieves an array of error descriptions for each error that occurred during the zipping process.

Returns:
a String array containing an error description for each error that occurred.
See Also:
ErrorCount()

FailedFileCount

public int FailedFileCount()
Retrieves the number of sub-file entries that failed to be added to the resulting ZIP file stream.

Returns:
an integer containing the number of sub-file entries that failed to be added.
See Also:
ZippedFileCount(), ErrorCount()

InputRate

public double InputRate()
Retrieves the number of processed input data in Kilobytes per second, to the nearest tenth KB/s.

Returns:
a double containing the data process rate during the ZIP process.
See Also:
OutputRate()

InputSize

public double InputSize()
Retrieves the number of Kilobytes inputted and processed during the zipping process.

Returns:
a double containing the number of Kilobytes inputted and processed.
See Also:
OutputSize()

OutputRate

public double OutputRate()
Retrieves the number of processed output data in Kilobytes per second, to the nearest tenth KB/s.

Returns:
a double containing the output rate of the ZIP process.
See Also:
InputRate()

OutputSize

public double OutputSize()
Retrieves the size of the ZIP file output stream in Kilobytes.

Returns:
a double containing the size of the output data stream.
See Also:
InputSize()

ProcessTime

public double ProcessTime()
Retrieves the number of seconds, accurate to the millisecond, required to process the resulting ZIP stream.

Returns:
a double containing the number of seconds required to execute.

Statistics

public String Statistics()
Retrieves a formatted report of all errors and statistics that occurred during the zipping process.

Returns:
a String containing an error description for each error that occurred.

ZippedFileCount

public int ZippedFileCount()
Retrieves the number of sub-file entries successfully added and zipped to the resulting ZIP file stream.

Returns:
an integer containing the number of sub-file entries that were added.
See Also:
FailedFileCount(), ErrorCount()

Java Tool Kit

Copyright ©2004, If•Then Technology