gov.nih.nci.caarray.services.util.file
Class FileZipper

java.lang.Object
  extended by gov.nih.nci.caarray.services.util.file.FileZipper

public class FileZipper
extends java.lang.Object

This object creates a zip file containing 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: FileZipper myZipper = new FileZipper(); 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, TranP

Constructor Summary
FileZipper()
           
 
Method Summary
static void createZip(java.lang.String zipFilePathName, java.lang.String[] filePathNames, boolean noPath)
          Creates a zip file and adds the specified fileNames to it.
 long getBytesCompressed()
          return the number of bytes of source dtata files that have been sent to the zip compression function.
 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 boolean isZipFile(java.lang.String pathName)
          Checks if the specified file is a compressed zip file.
static void main(java.lang.String[] args)
          Use this for testing.
 void setFiles(java.lang.String sessIdent, java.io.File[] files)
          This method establishes the set of files to be put into the zip file, and then actually places them in there.
static java.lang.String[] unZip(java.lang.String targetDirectory, java.lang.String zipFilePath)
          unzip a 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

FileZipper

public FileZipper()
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(java.lang.String sessIdent,
                     java.io.File[] 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

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

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 final java.lang.String[] unZip(java.lang.String targetDirectory,
                                             java.lang.String zipFilePath)
                                      throws java.io.IOException
unzip a file relative to the specified directory

Parameters:
targetDirectory - the directory to unzip the files into
zipFilePath - the zip file to unzip
Returns:
An array of file names, without parent path, contained in the zip file.
Throws:
java.io.IOException

createZip

public static void createZip(java.lang.String zipFilePathName,
                             java.lang.String[] filePathNames,
                             boolean noPath)
                      throws java.io.IOException
Creates a zip file and adds the specified fileNames to it. tranp

Parameters:
zipFileName -
fileNames -
noPath - - True to indicate all files are put at the root of the zip files.
Throws:
java.io.IOException

isZipFile

public static final boolean isZipFile(java.lang.String pathName)
Checks if the specified file is a compressed zip file. The file name must end with case-insensitive .zip or .jar.

Parameters:
pathName -
Returns:

main

public static void main(java.lang.String[] args)
Use this for testing.

Parameters:
args -