Project Wonder 5.0.0.8795

er.extensions.foundation
Class ERXFileUtilities

java.lang.Object
  extended by er.extensions.foundation.ERXFileUtilities

public class ERXFileUtilities
extends Object

Collection of handy {java.io.File} utilities.


Field Summary
static Logger log
          logging support
 
Constructor Summary
ERXFileUtilities()
           
 
Method Summary
static NSArray<File> arrayByAddingFilesInDirectory(File directory, boolean recursive)
          Creates a new NSArray which contains all files in the specified directory.
static byte[] bytesFromFile(File f)
          Returns the byte array for a given file.
static byte[] bytesFromFile(File f, int n)
          Returns an array of the first n bytes for a given file.
static byte[] bytesFromGZippedFile(File f)
          Returns the byte array for a given gzipped file.
static byte[] bytesFromInputStream(InputStream in)
          Returns the byte array for a given stream.
static byte[] bytesFromInputStream(InputStream fis, int n)
          Returns an array of the first n bytes for a given input stream
static void chmod(File file, String mode)
          Java wrapper for call out to chmod.
static void chmodRecusively(File dir, String mode)
          Java wrapper for call out to chmod with -R parameter for recursive processing.
static void copyFilesFromDirectory(File srcDirectory, File dstDirectory, boolean deleteOriginals, boolean replaceExistingFiles, boolean recursiveCopy, FileFilter filter)
          Copies all of the files in a given directory to another directory.
static void copyFilesFromDirectory(File srcDirectory, File dstDirectory, boolean deleteOriginals, boolean recursiveCopy, FileFilter filter)
          Copies all of the files in a given directory to another directory.
static void copyFileToFile(File srcFile, File dstFile, boolean deleteOriginals, boolean forceDelete)
          Copys the source file to the destination
static File createTempDir()
          Creates a temporary directory.
static File createTempDir(String prefix, String suffix)
          Creates a temporary directory.
static String datePathWithRoot(String rootPath)
          Returns a path containing an optional root with a directory hierarchy based on the current time
static boolean deleteDirectory(File directory)
          Deletes a given directory in a recursive fashion.
static boolean deleteFile(File fileToDelete)
           
static boolean deleteFiles(NSMutableArray filesToDelete)
          Deletes all files in filesToDelete uses the methdo deleteDirectory
static void deleteFilesInDirectory(File directory, boolean recurseIntoDirectories)
          Deletes all of the files in a given directory with the option to recursively delete all of the directories in the given directory.
static void deleteFilesInDirectory(File directory, FileFilter filter, boolean recurseIntoDirectories, boolean removeDirectories)
          Deletes all of the files in a given directory with the option to recursively delete all of the files in the given directory.
static String fileExtension(String name)
          returns the fileExtension from the specified filename
static String fileNameFromBrowserSubmittedPath(String path)
          Returns the file name portion of a browser submitted path.
static InputStream inputStreamForResourceNamed(String fileName, String frameworkName, NSArray languages)
          Get the input stream from the specified Resource.
static long lastModifiedDateForFileInFramework(String fileName, String frameworkName)
          Determines the last modification date for a given file in a framework.
static long length(File f)
           
static void linkFiles(File source, File destination, boolean symbolic, boolean allowUnlink, boolean followSymbolicLinks)
          Creates a symlink for a given file.
static File[] listDirectories(File baseDir, boolean recursive)
          Lists all directories in the specified directory, is desired recursive.
static File[] listFiles(File baseDir, boolean recursive, FileFilter filter)
          Lists all directories in the specified directory, is desired recursive.
static byte[] md5(File file)
          Generate an MD5 hash from a file.
static byte[] md5(InputStream in)
          Generate an MD5 hash from an input stream.
static String md5Hex(File file)
          Generate an MD5 hash from a file.
static String md5Hex(InputStream in)
          Generate an MD5 hash from an input stream.
static String pathForResourceNamed(String fileName, String frameworkName, NSArray languages)
          Determines the path of the specified Resource.
static URL pathURLForResourceNamed(String fileName, String frameworkName, NSArray languages)
          Determines the path URL of the specified Resource.
static Object readPropertyListFromFileInFramework(String fileName, String aFrameWorkName)
          Reads a file in from the file system and then parses it as if it were a property list, using the platform's default encoding.
static Object readPropertyListFromFileInFramework(String fileName, String aFrameWorkName, NSArray languageList)
          Reads a file in from the file system for the given set of languages and then parses the file as if it were a property list, using the platform's default encoding.
static Object readPropertyListFromFileInFramework(String fileName, String aFrameWorkName, NSArray languageList, String encoding)
          Reads a file in from the file system for the given set of languages and then parses the file as if it were a property list, using the specified encoding.
static Object readPropertyListFromFileInFramework(String fileName, String aFrameWorkName, String encoding)
          Reads a file in from the file system and then parses it as if it were a property list, using the specified encoding.
static void remoteCopyFile(File srcFile, String dstHost, String dstPath)
          Copy a file across hosts using scp.
static void remoteCopyFile(String srcHost, String srcPath, File dstFile)
          Copy a file across hosts using scp.
static void remoteCopyFile(String srcHost, String srcPath, String dstHost, String dstPath)
          Copy a file across hosts using scp.
static String removeFileExtension(String name)
          returns the filename without its fileExtension
static void renameTo(File source, File destination)
          moves a file from one location to another one.
static String replaceFileExtension(String path, String newExtension)
          Replaces the extension of the given file with the new extension.
static File reserveUniqueFile(File desiredFile, boolean overwrite)
          Reserves a unique file on the filesystem based on the given file name.
static boolean resourceExists(String fileName, String frameworkName, NSArray languages)
          Determines if a given resource exists.
static String shortenFilename(String name, int maxLength)
          shortens a filename, for example aVeryLongFileName.java -> aVer...Name.java
static String stringFromFile(File f)
          Returns a string from the file using the default encoding.
static String stringFromFile(File f, String encoding)
          Returns a string from the file using the specified encoding.
static String stringFromGZippedFile(File f)
          Returns a string from the gzipped file using the default encoding.
static String stringFromInputStream(InputStream in)
          Returns a string from the input stream using the default encoding.
static String stringFromInputStream(InputStream in, String encoding)
          Returns a string from the input stream using the specified encoding.
static String stringFromURL(URL url)
          Returns the String from the contents of the given URL.
static void stringToFile(String s, File f)
          Writes the contents of s to f using the platform's default encoding.
static void stringToFile(String s, File f, String encoding)
          Writes the contents of s to f using specified encoding.
static void stringToGZippedFile(String s, File f)
           
static File unzipFile(File f, File destination)
          Decompresses the specified zipfile.
static URL URLFromFile(File file)
          Create an URL for a given file.
static URL URLFromPath(String fileName)
          Create an URL for a given path.
static void writeInputStreamToFile(File f, InputStream is)
          Deprecated. use writeInputStreamToFile(InputStream is, File f) instead
static void writeInputStreamToFile(InputStream stream, File file)
          Writes the contents of an InputStream to a specified file.
static void writeInputStreamToGZippedFile(InputStream stream, File file)
           
static void writeInputStreamToOutputStream(InputStream in, boolean closeInputStream, OutputStream out, boolean closeOutputStream)
          Copies the contents of the input stream to the given output stream.
static void writeInputStreamToOutputStream(InputStream in, OutputStream out)
          Copies the contents of the input stream to the given output stream.
static File writeInputStreamToTempFile(InputStream stream)
          Writes the contents of an InputStream to a temporary file.
static File writeInputStreamToTempFile(InputStream stream, String prefix, String suffix)
          Writes the contents of an InputStream to a temporary file.
static void writeUrlToTempFile(String url, File file)
          Copies the contents of the given URL to a file.
static File writeUrlToTempFile(String url, String prefix, String suffix)
          Copies the contents of the given URL to a temporary file.
static void writeUrlToTempFile(URL url, File file)
          Copies the contents of the given URL to a file.
static File writeUrlToTempFile(URL url, String prefix, String suffix)
          Copies the contents of the given URL to a temporary file.
static File zipFile(File f, boolean absolutePaths, boolean deleteOriginal, boolean forceDelete)
          zips a given File.
static File zipFile(File f, boolean absolutePaths, boolean deleteOriginal, boolean forceDelete, int level)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final Logger log
logging support

Constructor Detail

ERXFileUtilities

public ERXFileUtilities()
Method Detail

writeUrlToTempFile

public static File writeUrlToTempFile(String url,
                                      String prefix,
                                      String suffix)
                               throws IOException
Copies the contents of the given URL to a temporary file.

Parameters:
url - the URL to copy from
prefix - the temporary file prefix
suffix - the temporary file suffix (if null, the extension from the URL is used)
Returns:
the temporary file
Throws:
IOException - if the copy fails

writeUrlToTempFile

public static File writeUrlToTempFile(URL url,
                                      String prefix,
                                      String suffix)
                               throws IOException
Copies the contents of the given URL to a temporary file.

Parameters:
url - the URL to copy from
prefix - the temporary file prefix
suffix - the temporary file suffix (if null, the extension from the URL is used)
Returns:
the temporary file
Throws:
IOException - if the copy fails

writeUrlToTempFile

public static void writeUrlToTempFile(String url,
                                      File file)
                               throws IOException
Copies the contents of the given URL to a file.

Parameters:
url - the URL to copy from
file - the File to write to
Throws:
IOException - if the copy fails

writeUrlToTempFile

public static void writeUrlToTempFile(URL url,
                                      File file)
                               throws IOException
Copies the contents of the given URL to a file.

Parameters:
url - the URL to copy from
file - the File to write to
Throws:
IOException - if the copy fails

bytesFromInputStream

public static byte[] bytesFromInputStream(InputStream in)
                                   throws IOException
Returns the byte array for a given stream.

Parameters:
in - stream to get the bytes from
Returns:
byte array of the stream.
Throws:
IOException - if things go wrong

stringFromInputStream

public static String stringFromInputStream(InputStream in,
                                           String encoding)
                                    throws IOException
Returns a string from the input stream using the specified encoding.

Parameters:
in - stream to read
encoding - to be used, null will use the default
Returns:
string representation of the stream.
Throws:
IOException

stringFromInputStream

public static String stringFromInputStream(InputStream in)
                                    throws IOException
Returns a string from the input stream using the default encoding.

Parameters:
in - stream to read
Returns:
string representation of the stream.
Throws:
IOException

stringFromURL

public static String stringFromURL(URL url)
                            throws IOException
Returns the String from the contents of the given URL.

Parameters:
url - the URL to read from
Returns:
the String contents of the URL
Throws:
IOException - if an error occurs

bytesFromGZippedFile

public static byte[] bytesFromGZippedFile(File f)
                                   throws IOException
Returns the byte array for a given gzipped file.

Parameters:
f - file to get the bytes from
Returns:
byte array of the file.
Throws:
IOException - if things go wrong

bytesFromFile

public static byte[] bytesFromFile(File f)
                            throws IOException
Returns the byte array for a given file.

Parameters:
f - file to get the bytes from
Returns:
byte array of the file.
Throws:
IOException - if things go wrong

bytesFromFile

public static byte[] bytesFromFile(File f,
                                   int n)
                            throws IOException
Returns an array of the first n bytes for a given file.

Parameters:
f - file to get the bytes from
n - number of bytes to read from input file
Returns:
byte array of the first n bytes from the file.
Throws:
IOException - if things go wrong

bytesFromInputStream

public static byte[] bytesFromInputStream(InputStream fis,
                                          int n)
                                   throws IOException
Returns an array of the first n bytes for a given input stream

Parameters:
fis - inputstream to get the bytes from
n - number of bytes to read from input stream
Returns:
byte array of the first n bytes from the file.
Throws:
IOException - if things go wrong

writeInputStreamToFile

public static void writeInputStreamToFile(File f,
                                          InputStream is)
                                   throws IOException
Deprecated. use writeInputStreamToFile(InputStream is, File f) instead

Throws:
IOException

writeInputStreamToTempFile

public static File writeInputStreamToTempFile(InputStream stream)
                                       throws IOException
Writes the contents of an InputStream to a temporary file.

Parameters:
stream - to pull data from
Returns:
the temp file that was created
Throws:
IOException

writeInputStreamToTempFile

public static File writeInputStreamToTempFile(InputStream stream,
                                              String prefix,
                                              String suffix)
                                       throws IOException
Writes the contents of an InputStream to a temporary file.

Parameters:
stream - to pull data from
prefix - the filename prefix of the temp file
suffix - the filename suffix of the temp file
Returns:
the temp file that was created
Throws:
IOException

writeInputStreamToFile

public static void writeInputStreamToFile(InputStream stream,
                                          File file)
                                   throws IOException
Writes the contents of an InputStream to a specified file.

Parameters:
file - to write to
stream - to pull data from
Throws:
IOException

writeInputStreamToGZippedFile

public static void writeInputStreamToGZippedFile(InputStream stream,
                                                 File file)
                                          throws IOException
Throws:
IOException

writeInputStreamToOutputStream

public static void writeInputStreamToOutputStream(InputStream in,
                                                  OutputStream out)
                                           throws IOException
Copies the contents of the input stream to the given output stream. Both streams are guaranteed to be closed by the end of this method.

Parameters:
in - the input stream to copy from
out - the output stream to copy to
Throws:
IOException - if there is any failure

writeInputStreamToOutputStream

public static void writeInputStreamToOutputStream(InputStream in,
                                                  boolean closeInputStream,
                                                  OutputStream out,
                                                  boolean closeOutputStream)
                                           throws IOException
Copies the contents of the input stream to the given output stream.

Parameters:
in - the input stream to copy from
closeInputStream - if true, the input stream will be closed
out - the output stream to copy to
closeOutputStream - if true, the output stream will be closed
Throws:
IOException - if there is any failure

stringToGZippedFile

public static void stringToGZippedFile(String s,
                                       File f)
                                throws IOException
Throws:
IOException

stringToFile

public static void stringToFile(String s,
                                File f)
                         throws IOException
Writes the contents of s to f using the platform's default encoding.

Parameters:
s - the string to be written to file
f - the destination file
Throws:
IOException

stringToFile

public static void stringToFile(String s,
                                File f,
                                String encoding)
                         throws IOException
Writes the contents of s to f using specified encoding.

Parameters:
s - the string to be written to file
f - the destination file
encoding - the desired encoding
Throws:
IOException

remoteCopyFile

public static void remoteCopyFile(String srcHost,
                                  String srcPath,
                                  String dstHost,
                                  String dstPath)
                           throws IOException
Copy a file across hosts using scp.

Parameters:
srcHost - host to send from (null if file is local)
srcPath - path on srcHost to read from
dstHost - host to send to (null if file is local)
dstPath - path on srcHost to write to
Throws:
IOException

remoteCopyFile

public static void remoteCopyFile(File srcFile,
                                  String dstHost,
                                  String dstPath)
                           throws IOException
Copy a file across hosts using scp.

Parameters:
srcFile - local file to send
dstHost - host to send to (null if file is local)
dstPath - path on srcHost to write to
Throws:
IOException

remoteCopyFile

public static void remoteCopyFile(String srcHost,
                                  String srcPath,
                                  File dstFile)
                           throws IOException
Copy a file across hosts using scp.

Parameters:
srcHost - host to send from (null if file is local)
srcPath - path on srcHost to read from
dstFile - local file to write to
Throws:
IOException

stringFromGZippedFile

public static String stringFromGZippedFile(File f)
                                    throws IOException
Returns a string from the gzipped file using the default encoding.

Parameters:
f - file to read
Returns:
string representation of that file.
Throws:
IOException

stringFromFile

public static String stringFromFile(File f)
                             throws IOException
Returns a string from the file using the default encoding.

Parameters:
f - file to read
Returns:
string representation of that file.
Throws:
IOException

stringFromFile

public static String stringFromFile(File f,
                                    String encoding)
                             throws IOException
Returns a string from the file using the specified encoding.

Parameters:
f - file to read
encoding - to be used, null will use the default
Returns:
string representation of the file.
Throws:
IOException

pathForResourceNamed

public static String pathForResourceNamed(String fileName,
                                          String frameworkName,
                                          NSArray languages)
Determines the path of the specified Resource. This is done to get a single entry point due to the deprecation of pathForResourceNamed

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the absolutePath method off of the file object

resourceExists

public static boolean resourceExists(String fileName,
                                     String frameworkName,
                                     NSArray languages)
Determines if a given resource exists. This is done to get a single entry point due to the deprecation of pathForResourceNamed

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the absolutePath method off of the file object

inputStreamForResourceNamed

public static InputStream inputStreamForResourceNamed(String fileName,
                                                      String frameworkName,
                                                      NSArray languages)
Get the input stream from the specified Resource.

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the absolutePath method off of the file object

datePathWithRoot

public static String datePathWithRoot(String rootPath)
Returns a path containing an optional root with a directory hierarchy based on the current time

Parameters:
rootPath - Root of the path before the above the date directories
Returns:
the path based on time.

pathURLForResourceNamed

public static URL pathURLForResourceNamed(String fileName,
                                          String frameworkName,
                                          NSArray languages)
Determines the path URL of the specified Resource. This is done to get a single entry point due to the deprecation of pathForResourceNamed. In a later version this will call out to the resource managers new methods directly.

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the absolutePath method off of the file object

URLFromFile

public static URL URLFromFile(File file)
Create an URL for a given file.

Parameters:
file - name of the file
Returns:
file:// URL for the given path

URLFromPath

public static URL URLFromPath(String fileName)
Create an URL for a given path.

Parameters:
fileName - path of the file
Returns:
file:// URL for the given path

lastModifiedDateForFileInFramework

public static long lastModifiedDateForFileInFramework(String fileName,
                                                      String frameworkName)
Determines the last modification date for a given file in a framework. Note that this method will only test for the global resource not the localized resources.

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the lastModified method off of the file object

readPropertyListFromFileInFramework

public static Object readPropertyListFromFileInFramework(String fileName,
                                                         String aFrameWorkName)
Reads a file in from the file system and then parses it as if it were a property list, using the platform's default encoding.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
Returns:
de-serialized object from the plist formatted file specified.

readPropertyListFromFileInFramework

public static Object readPropertyListFromFileInFramework(String fileName,
                                                         String aFrameWorkName,
                                                         String encoding)
Reads a file in from the file system and then parses it as if it were a property list, using the specified encoding.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
encoding - the encoding used with fileName
Returns:
de-serialized object from the plist formatted file specified.

readPropertyListFromFileInFramework

public static Object readPropertyListFromFileInFramework(String fileName,
                                                         String aFrameWorkName,
                                                         NSArray languageList)
Reads a file in from the file system for the given set of languages and then parses the file as if it were a property list, using the platform's default encoding.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
languageList - language list search order
Returns:
de-serialized object from the plist formatted file specified.

readPropertyListFromFileInFramework

public static Object readPropertyListFromFileInFramework(String fileName,
                                                         String aFrameWorkName,
                                                         NSArray languageList,
                                                         String encoding)
Reads a file in from the file system for the given set of languages and then parses the file as if it were a property list, using the specified encoding.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
languageList - language list search order
encoding - the encoding used with fileName
Returns:
de-serialized object from the plist formatted file specified.

deleteFilesInDirectory

public static void deleteFilesInDirectory(File directory,
                                          boolean recurseIntoDirectories)
Deletes all of the files in a given directory with the option to recursively delete all of the directories in the given directory.

Parameters:
directory - to delete all of the files from
recurseIntoDirectories - determines if the delete is recursive

deleteFilesInDirectory

public static void deleteFilesInDirectory(File directory,
                                          FileFilter filter,
                                          boolean recurseIntoDirectories,
                                          boolean removeDirectories)
Deletes all of the files in a given directory with the option to recursively delete all of the files in the given directory.

Parameters:
directory - to delete all of the files from
filter - optional FileFilter to restrict what gets deleted, null to delete everything
recurseIntoDirectories - determines if the delete is recursive
removeDirectories - true if directories should be removed as well as files, false to only remove files

deleteDirectory

public static boolean deleteDirectory(File directory)
Deletes a given directory in a recursive fashion.

Parameters:
directory - to be deleted
Returns:
if the directory deleted successfully

chmod

public static void chmod(File file,
                         String mode)
                  throws IOException
Java wrapper for call out to chmod. Only works if your OS supports the chmod command.

Parameters:
file - the File to run chmod on
mode - see the chmod man page
Throws:
IOException - if things go wrong

chmodRecusively

public static void chmodRecusively(File dir,
                                   String mode)
                            throws IOException
Java wrapper for call out to chmod with -R parameter for recursive processing. Only works if your OS supports the chmod command.

Parameters:
dir - the File to run chmod on
mode - see the chmod man page
Throws:
IOException - if things go wrong

linkFiles

public static void linkFiles(File source,
                             File destination,
                             boolean symbolic,
                             boolean allowUnlink,
                             boolean followSymbolicLinks)
                      throws IOException
Creates a symlink for a given file. Note this only works on civilized OSs which support symbolic linking.

Parameters:
source - to create the link to
destination - file to create the link to
symbolic - determines if a symlink should be created
allowUnlink - determines if the symlink is a hardlink which allows unlinking
Throws:
IOException

copyFilesFromDirectory

public static void copyFilesFromDirectory(File srcDirectory,
                                          File dstDirectory,
                                          boolean deleteOriginals,
                                          boolean recursiveCopy,
                                          FileFilter filter)
                                   throws FileNotFoundException,
                                          IOException
Copies all of the files in a given directory to another directory. Existing files are replaced.

Parameters:
srcDirectory - source directory
dstDirectory - destination directory
deleteOriginals - tells if the original files, the file is deleted even if appuser has no write rights. This is compareable to a rm -f filename instead of rm filename
recursiveCopy - specifies if directories should be recursively copied
filter - which restricts the files to be copied
Throws:
FileNotFoundException
IOException

copyFilesFromDirectory

public static void copyFilesFromDirectory(File srcDirectory,
                                          File dstDirectory,
                                          boolean deleteOriginals,
                                          boolean replaceExistingFiles,
                                          boolean recursiveCopy,
                                          FileFilter filter)
                                   throws FileNotFoundException,
                                          IOException
Copies all of the files in a given directory to another directory.

Parameters:
srcDirectory - source directory
dstDirectory - destination directory
deleteOriginals - tells if the original files, the file is deleted even if appuser has no write rights. This is compareable to a rm -f filename instead of rm filename
replaceExistingFiles - true if the destination should be overwritten if it already exists
recursiveCopy - specifies if directories should be recursively copied
filter - which restricts the files to be copied
Throws:
FileNotFoundException
IOException

copyFileToFile

public static void copyFileToFile(File srcFile,
                                  File dstFile,
                                  boolean deleteOriginals,
                                  boolean forceDelete)
                           throws FileNotFoundException,
                                  IOException
Copys the source file to the destination

Parameters:
srcFile - source file
dstFile - destination file
deleteOriginals - tells if original file will be deleted. Note that if the appuser has no write rights on the file it is NOT deleted unless force delete is true
forceDelete - if true then missing write rights are ignored and the file is deleted.
Throws:
FileNotFoundException
IOException

createTempDir

public static final File createTempDir()
                                throws IOException
Creates a temporary directory.

Returns:
a temporary directory
Throws:
IOException - if something goes wrong

createTempDir

public static final File createTempDir(String prefix,
                                       String suffix)
                                throws IOException
Creates a temporary directory.

Returns:
a temporary directory
Throws:
IOException - if something goes wrong

arrayByAddingFilesInDirectory

public static NSArray<File> arrayByAddingFilesInDirectory(File directory,
                                                          boolean recursive)
Creates a new NSArray which contains all files in the specified directory.

Parameters:
directory - the directory from which to add the files
recursive - if true then files are added recursively meaning subdirectories are scanned, too.
Returns:
a NSArray containing the files in the directory. If the specified directory does not exist then the array is empty.

replaceFileExtension

public static String replaceFileExtension(String path,
                                          String newExtension)
Replaces the extension of the given file with the new extension.

Parameters:
path - the path of the file.
newExtension - the new extension.
Returns:
the new path.

unzipFile

public static File unzipFile(File f,
                             File destination)
                      throws IOException
Decompresses the specified zipfile. If the file is a compressed directory, the whole subdirectory structure is created as a subdirectory with the name if the zip file minus the .zip extension from destination. All intermittent directories are also created. If destination is null then the System Property "java.io.tmpdir" is used as destination for the uncompressed file(s).

Parameters:
f - The file to unzip
destination - the destination directory. If directory is null then the file will be unzipped in java.io.tmpdir, if it does not exist, then a directory is created and if it exists but is a file then the destination is set to the directory in which the file is located.
Returns:
the file or directory in which the zipfile was unzipped
Throws:
IOException

zipFile

public static File zipFile(File f,
                           boolean absolutePaths,
                           boolean deleteOriginal,
                           boolean forceDelete)
                    throws IOException
zips a given File.

Parameters:
f - the file to zip, either a file or a directory
absolutePaths - if true then the files are added with absolute paths
deleteOriginal - if true then the original file is deleted
forceDelete - if true then the original is deleted even if the file is read only
Throws:
IOException

zipFile

public static File zipFile(File f,
                           boolean absolutePaths,
                           boolean deleteOriginal,
                           boolean forceDelete,
                           int level)
                    throws IOException
Throws:
IOException

md5

public static byte[] md5(File file)
                  throws IOException
Generate an MD5 hash from a file.

Parameters:
file - the file to sum
Returns:
the MD5 sum of the bytes in file
Throws:
IOException

md5

public static byte[] md5(InputStream in)
                  throws IOException
Generate an MD5 hash from an input stream.

Parameters:
in - the input stream to sum
Returns:
the MD5 sum of the bytes in file
Throws: