com.dynalivery.saffron.client
Class FileUtilities

java.lang.Object
  extended bycom.dynalivery.saffron.client.FileUtilities

public class FileUtilities
extends java.lang.Object

This class defines some useful methods for manipulating files and filenames.


Field Summary
static int BUFFER_SIZE_IN_BYTES
           
 
Constructor Summary
FileUtilities()
           
 
Method Summary
static void copyFile(java.io.File sourceFile, java.io.File destFile)
          Copy a file
static byte[] createByteArrayFromFile(java.io.File file)
          Returns a byte array with the entire contents of the specified file
static byte[] createByteArrayFromStream(java.io.InputStream inputStream)
          Returns a byte array with the entire contents of the specified file
static void extractZipFile(java.lang.String dirPathname, java.lang.String zipFilename)
           
static java.io.File findFile(java.lang.String filename)
          Find a file.
static java.lang.String getLastPathnameElement(java.lang.String pathname)
          Get last element of pathname
static java.util.ArrayList getNestedFiles(java.lang.String directory, java.lang.String filename)
           
static java.lang.String getParentPathname(java.lang.String pathname)
          Get parent's pathname
static java.lang.String setLastPathnameElement(java.lang.String pathname, java.lang.String newLastElement)
          Set the last element of a pathname
static void writeByteArrayToFile(java.io.File file, byte[] byteArray)
          Writes a byte array to the specified file
static void zipDirectory(java.lang.String dirPathname, java.lang.String zipFilename, boolean deleteFiles)
          Zip the files in specified directory
static void zipFiles(java.lang.String[] pathnames, java.lang.String zipFilename, boolean deleteFiles)
          Zip the specified files
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE_IN_BYTES

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

FileUtilities

public FileUtilities()
Method Detail

createByteArrayFromFile

public static byte[] createByteArrayFromFile(java.io.File file)
                                      throws java.io.FileNotFoundException,
                                             java.io.IOException
Returns a byte array with the entire contents of the specified file

Parameters:
file - the File to be read
Returns:
byte array of the file contents
Throws:
java.io.FileNotFoundException
java.io.IOException

createByteArrayFromStream

public static byte[] createByteArrayFromStream(java.io.InputStream inputStream)
                                        throws java.io.IOException
Returns a byte array with the entire contents of the specified file

Parameters:
inputStream - the InputStream to be read
Returns:
byte array of the file contents
Throws:
java.io.IOException

writeByteArrayToFile

public static void writeByteArrayToFile(java.io.File file,
                                        byte[] byteArray)
                                 throws java.io.FileNotFoundException,
                                        java.io.IOException
Writes a byte array to the specified file

Parameters:
file - the File to be written
byteArray - of the file contents
Throws:
java.io.FileNotFoundException
java.io.IOException

getParentPathname

public static java.lang.String getParentPathname(java.lang.String pathname)
Get parent's pathname

Parameters:
pathname - full pathname to be parsed
Returns:
original pathname except last element

getLastPathnameElement

public static java.lang.String getLastPathnameElement(java.lang.String pathname)
Get last element of pathname

Parameters:
pathname - full pathname to be parsed
Returns:
last element of pathname

setLastPathnameElement

public static java.lang.String setLastPathnameElement(java.lang.String pathname,
                                                      java.lang.String newLastElement)
Set the last element of a pathname

Parameters:
pathname - full pathname to be parsed
newLastElement - the String to replace the last pathname element
Returns:
modified pathname

copyFile

public static void copyFile(java.io.File sourceFile,
                            java.io.File destFile)
                     throws java.io.IOException
Copy a file

Parameters:
sourceFile - the source File
destFile - the destination File
Throws:
java.io.IOException

findFile

public static java.io.File findFile(java.lang.String filename)
Find a file. This method searches the current directory first and then the classpath.

Parameters:
filename - the filename we are looking for
Returns:
the desired File object or null if file is not found

getNestedFiles

public static java.util.ArrayList getNestedFiles(java.lang.String directory,
                                                 java.lang.String filename)

zipDirectory

public static void zipDirectory(java.lang.String dirPathname,
                                java.lang.String zipFilename,
                                boolean deleteFiles)
                         throws java.io.IOException
Zip the files in specified directory

Parameters:
dirPathname - the pathname String for the source directory
zipFilename - the filename String for the destination zip file
deleteFiles - true if files should be deleted after zip file is built
Throws:
java.io.IOException

zipFiles

public static void zipFiles(java.lang.String[] pathnames,
                            java.lang.String zipFilename,
                            boolean deleteFiles)
                     throws java.io.IOException
Zip the specified files

Parameters:
pathnames - String array of pathname to be deleted
zipFilename - the filename String for the destination zip file
deleteFiles - true if files should be deleted after zip file is built
Throws:
java.io.IOException

extractZipFile

public static void extractZipFile(java.lang.String dirPathname,
                                  java.lang.String zipFilename)
                           throws java.io.IOException
Throws:
java.io.IOException