gov.nih.nci.caarray.services.util.fileuploadapplet
Class Zipper

java.lang.Object
  extended by gov.nih.nci.caarray.services.util.fileuploadapplet.Zipper

public class Zipper
extends java.lang.Object

This object creates a zip file conaining the set of files within a SelectedFiles object. One can then get an InputStream for the zip file to use for transfering via FTP. This object also contains an unzip method to extract the files from the zip file. There is also support for determining how much of the zipping has been done (ie number of bytes read from the source file) Typical use would be: Zipper myZipper = new Zipper(); myZipper.setFiles(mySelectedFiles); //this method blocks until the zip file is created sendToServer(myZipper.getInputStream()); on server: Zipper.unZip(unpackDirectory, fullyQualifiedZipFileName)

Author:
L. Schuler 5/5/2004 for NIEHS

Constructor Summary
Zipper()
          no-arg constructor
 
Method Summary
 void bytesTransferred(long total, int lastchunk)
          callback method for copy util.
 long getBytesCompressed()
          return the number of bytes of source dtata files that have been sent to the zip compression function.
 java.lang.String getExpId()
           
 java.io.InputStream getInputStream()
          This method gets an InputStream for reading the zip file.
 java.lang.String getName()
          Method to get the name of the zip file.
 long getZipFileSize()
          Get the size of the zip file created by this class
 boolean isCompressing()
          Is this object currently compressing data files ?
static void main(java.lang.String[] args)
          I should use this to test this.
 void setFiles(SelectedFiles files)
          This method establishes the set of files to be put into the zip file, and then actually places them in there.
static boolean unZip(java.lang.String rootDir, java.lang.String zipFile)
          unzip ze file relative to the specified directory
static boolean unZip(java.lang.String rootDir, java.lang.String zipFile, UploadFile[] uploadFiles)
          unzip ze file relative to the specified directory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Zipper

public Zipper()
no-arg constructor

Method Detail

getName

public java.lang.String getName()
Method to get the name of the zip file. Since it is a java temp file, the exact name is not known unless this is called. It shouldn't really be needed, but just in case...

Returns:
The name of the zip file

setFiles

public void setFiles(SelectedFiles files)
              throws java.lang.Exception
This method establishes the set of files to be put into the zip file, and then actually places them in there. Be warned, this method will block until the temporary zip file has been filled with the files-which could take a while if there are large data files to zip.

Parameters:
files - the files to place into the zip file
sessIdent - the session Identifier. used to construct the path in the zip file.
Throws:
java.lang.Exception - if an error occurs during zip building

getExpId

public java.lang.String getExpId()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.lang.Exception
This method gets an InputStream for reading the zip file.

Returns:
an InputStream to read the zip file
Throws:
java.lang.Exception - if no files are defined, or zip is not built yet

getZipFileSize

public long getZipFileSize()
Get the size of the zip file created by this class

Returns:
the size of the temp zip file, 0 if not created yet

bytesTransferred

public void bytesTransferred(long total,
                             int lastchunk)
callback method for copy util. called when a new chunk of data has been moved

Parameters:
total - the total number of bytes transfered in this copy call
lastchunk - the number of bytes transferred since the last callback

getBytesCompressed

public long getBytesCompressed()
return the number of bytes of source dtata files that have been sent to the zip compression function.

Returns:
number of bytes from the source files that have been compressed

isCompressing

public boolean isCompressing()
Is this object currently compressing data files ?

Returns:
T/F if compression is currently in preogress.

unZip

public static boolean unZip(java.lang.String rootDir,
                            java.lang.String zipFile)
unzip ze file relative to the specified directory

Parameters:
rootDir - the directory to unzip the files into
zipFile - the zip file to unzip
Returns:
T/F if successfull.

unZip

public static boolean unZip(java.lang.String rootDir,
                            java.lang.String zipFile,
                            UploadFile[] uploadFiles)
unzip ze file relative to the specified directory

Parameters:
rootDir - the directory to unzip the files into
zipFile - the zip file to unzip
Returns:
T/F if successfull.

main

public static void main(java.lang.String[] args)
I should use this to test this.

Parameters:
args -