org.aeonscope.io
Class FileKit

java.lang.Object
  extended by org.aeonscope.io.FileKit

public class FileKit
extends Object

General utilities for file manipulation.

Author:
Brooke Kuhlmann

Constructor Summary
FileKit()
           
 
Method Summary
static boolean doesExist(File file)
          Determines if a given file exists on a file system.
static boolean doesExist(String path)
          Determines if a given file path exists on a file system.
static String getMD5Sum(File file)
          Answers the MD5, 32-character hex checksum based on a file.
static String getMD5Sum(String path)
          Answers the MD5, 32-character hex checksum based on a file path.
static Collection listDirectories(File file)
          Answers a list of directories for the given file.
static Collection listDirectories(String path)
          Answers a list of directories for the given path.
static Collection<?> listFilesWithIOFileFilter(String path, org.apache.commons.io.filefilter.IOFileFilter filter, boolean isRecursive)
          Obtains a list of files that match a given suffix with the option to recurse a directory structure.
static Collection<?> listFilesWithPrefix(String path, String prefix, boolean isRecursive)
          List files that match a given prefix with the option for directory recursion.
static Collection<?> listFilesWithPrefixes(String path, String[] prefixes, boolean isRecursive)
          List files that match an array of prefixes with the option for directory recursion.
static Collection<?> listFilesWithSuffix(String path, String suffix, boolean isRecursive)
          List files that match a given suffix with the option for directory recursion.
static Collection<?> listFilesWithSuffixes(String path, String[] suffixes, boolean isRecursive)
          List files that match a suffix array with the option for directory recursion.
static String reparent(String sourcePath, String sourceRootPath, String targetRootPath)
          Re-parents a path (case sensitive) by switching the source root path with the target root path.
static String separatorsToSystemWithNoEndSeparator(String path)
          Convert all separators to system separators and removes the trailing separator (if found).
static String separatorsToSystemWithNoOuterSeparators(String path)
          Convert all separators to system separators and removes separators found before and after the path (if any).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileKit

public FileKit()
Method Detail

doesExist

public static boolean doesExist(String path)
Determines if a given file path exists on a file system.

Parameters:
path - The file path to validate.
Returns:
true = file path exists, false = file path is null, empty, or does not exist.

doesExist

public static boolean doesExist(File file)
Determines if a given file exists on a file system.

Parameters:
file - The file to validate.
Returns:
true = file exists, false = file is null or does not exist.

listDirectories

public static Collection listDirectories(String path)
Answers a list of directories for the given path.

Parameters:
path - The path to search.
Returns:
The directory list, otherwise an empty list.

listDirectories

public static Collection listDirectories(File file)
Answers a list of directories for the given file.

Parameters:
file - The file to search.
Returns:
The directory list, otherwise an empty list.

listFilesWithPrefix

public static Collection<?> listFilesWithPrefix(String path,
                                                String prefix,
                                                boolean isRecursive)
List files that match a given prefix with the option for directory recursion.

Parameters:
path - The root path to search.
prefix - The prefix used to determine a file match.
isRecursive - true = traverse the root path and all sub-directories, false = traverse the root path only.
Returns:
The collection of matching files (java.io.File), otherwise an empty collection.

listFilesWithPrefixes

public static Collection<?> listFilesWithPrefixes(String path,
                                                  String[] prefixes,
                                                  boolean isRecursive)
List files that match an array of prefixes with the option for directory recursion.

Parameters:
path - The root path to search.
prefixes - The prefix array used to determine a file match.
isRecursive - true = traverse the root path and all sub-directories, false = traverse the root path only.
Returns:
The collection of matching files (java.io.File), otherwise an empty collection.

listFilesWithSuffix

public static Collection<?> listFilesWithSuffix(String path,
                                                String suffix,
                                                boolean isRecursive)
List files that match a given suffix with the option for directory recursion.

Parameters:
path - The root path to search.
suffix - The suffix used to determine a file match.
isRecursive - true = traverse the root path and all sub-directories, false = traverse the root path only.
Returns:
The collection of matching files (java.io.File), otherwise an empty collection.

listFilesWithSuffixes

public static Collection<?> listFilesWithSuffixes(String path,
                                                  String[] suffixes,
                                                  boolean isRecursive)
List files that match a suffix array with the option for directory recursion.

Parameters:
path - The root path to search.
suffixes - The suffix array used to determine a file match.
isRecursive - true = traverse the root path and all sub-directories, false = traverse the root path only.
Returns:
The collection of matching files (java.io.File), otherwise an empty collection.

listFilesWithIOFileFilter

public static Collection<?> listFilesWithIOFileFilter(String path,
                                                      org.apache.commons.io.filefilter.IOFileFilter filter,
                                                      boolean isRecursive)
Obtains a list of files that match a given suffix with the option to recurse a directory structure.

Parameters:
path - The root path to search.
filter - The file filter used to determine a file match.
isRecursive - true = traverse the root path and all sub-directories, false = traverse the root path only.
Returns:
The collection of matching files (java.io.File), otherwise an empty collection.

reparent

public static String reparent(String sourcePath,
                              String sourceRootPath,
                              String targetRootPath)
Re-parents a path (case sensitive) by switching the source root path with the target root path. All paths are standardized to use the current system path separators. Extraneous path separators are ignored.

NOTE: Only the first occurrence of a path is replaced should there be more than one occurrence in the source path.

Examples

Parameters:
sourcePath - The path to re-parent.
sourceRootPath - The root path of the source path.
targetRootPath - The root path of the target path.
Returns:
The re-parented path, otherwise null if null input.

separatorsToSystemWithNoOuterSeparators

public static String separatorsToSystemWithNoOuterSeparators(String path)
Convert all separators to system separators and removes separators found before and after the path (if any). This method is basically a combination of the FilenameUtils.separatorsToSystem(String) and StringUtils.strip(String, String) methods.

Windows Examples

Unix Examples

Parameters:
path - The path to format.
Returns:
The new path, otherwise null if null input.
See Also:
FilenameUtils.separatorsToSystem(String), StringUtils.strip(String, String)

separatorsToSystemWithNoEndSeparator

public static String separatorsToSystemWithNoEndSeparator(String path)
Convert all separators to system separators and removes the trailing separator (if found). This method is basically a combination of the FilenameUtils.separatorsToSystem(String) and StringUtils.removeEnd(String, String) methods.

Windows Examples

Unix Examples

Parameters:
path - The path to format.
Returns:
The new path, otherwise null if null input.
See Also:
FilenameUtils.separatorsToSystem(String), StringUtils.removeEnd(String, String)

getMD5Sum

public static String getMD5Sum(String path)
Answers the MD5, 32-character hex checksum based on a file path.

Parameters:
path - The path to the file for which to calculate checksum for.
Returns:
The file checksum, otherwise null.

getMD5Sum

public static String getMD5Sum(File file)
Answers the MD5, 32-character hex checksum based on a file.

Parameters:
file - The file to calculate the checksum for.
Returns:
The file checksum, otherwise null.