com.jfw.file
Class UnzipFile

java.lang.Object
  extended by com.jfw.file.UnzipFile

public final class UnzipFile
extends java.lang.Object

Unzip a file.
If the zip file has been created using the encryption method offered in ZipFile then you can decrypt the zip file by setting the decryption key (method setKey4Decryption(java.lang.String)) before to use the extract(java.lang.String, boolean) method.


Constructor Summary
UnzipFile(java.lang.String name)
          Create an instance.
UnzipFile(java.lang.String path, java.lang.String name)
          Create an instance.
 
Method Summary
 void addFile(java.lang.String name)
          Add the name of a file to extract.
 void decrypt(java.lang.String file2Decrypt)
          Decrypt a zip.
 void extract(java.lang.String path)
          Extract all file form the zip file.
 void extractFiles(java.lang.String path)
          Extract the only files set in method addFile(java.lang.String).
 byte[] getFile(java.lang.String fileName)
          Get a file from the zip file.
 java.lang.String[] listFiles()
          Get the names of files in the zip file.
 void setKey4Decryption(java.lang.String key4Decryption)
          Set the decryption key of the zipped files.
 java.lang.String toString()
          Return log informations relative of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnzipFile

public UnzipFile(java.lang.String name)
Create an instance.

Parameters:
name - path and name, with extension, of zip file.

UnzipFile

public UnzipFile(java.lang.String path,
                 java.lang.String name)
Create an instance.

Parameters:
path - the path of the zip file.
name - name, with extension, of zip file.
Method Detail

setKey4Decryption

public void setKey4Decryption(java.lang.String key4Decryption)
Set the decryption key of the zipped files.

Parameters:
key4Decryption - the decryption key.

addFile

public void addFile(java.lang.String name)
Add the name of a file to extract.

Parameters:
name - the absolute path+name of the file to extract.

extract

public void extract(java.lang.String path)
             throws JFWGenericException
Extract all file form the zip file.
If the zip file is encrypted you don't have to decrypt it manually.

Parameters:
path - the path to unzip the file.
Throws:
JFWGenericException

extractFiles

public void extractFiles(java.lang.String path)
                  throws JFWGenericException
Extract the only files set in method addFile(java.lang.String).
If the zip file is encrypted you don't have to decrypt it manually.

Parameters:
path - the path to unzip the file.
Throws:
JFWGenericException

getFile

public byte[] getFile(java.lang.String fileName)
               throws JFWGenericException
Get a file from the zip file.
If the zip file is encrypted then you have to decrypt it manually using the decrypt(java.lang.String) method.

Parameters:
fileName - the name of the file to get.
Returns:
the content of the file.
Throws:
JFWGenericException

decrypt

public void decrypt(java.lang.String file2Decrypt)
             throws JFWGenericException
Decrypt a zip.
The name of the decrypted file will be the original name plus the extension TMP_EXT. For example, if the original name is "myfile.zip" the decrypted file name will be "myfile.zip.dec". Note that the original file is not deleted after decryption.

Parameters:
file2Decrypt - the absolute path and name of the file to decrypt.
Throws:
JFWGenericException

listFiles

public java.lang.String[] listFiles()
                             throws java.lang.Exception
Get the names of files in the zip file.

Returns:
the names of files in the zip file.
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Return log informations relative of the object.

Overrides:
toString in class java.lang.Object
Returns:
log informations relative of the object.