org.opengts.util
Class FileTools

java.lang.Object
  extended by org.opengts.util.FileTools

public class FileTools
extends java.lang.Object

File handling tools


Field Summary
static int DEFAULT_URL_COPYFILE_TIMEOUT_MS
           
 
Constructor Summary
FileTools()
           
 
Method Summary
static boolean canExecute(java.io.File f)
          Returns true if the file can be executed
static boolean canRead(java.io.File f)
          Returns true if the file can be read
static boolean canWrite(java.io.File f)
          Returns true if the file can be written
static void closeStream(java.io.InputStream in)
          Closes the specified InputStream.
static void closeStream(java.io.OutputStream out)
          Closes the specified OutputStream
static int copyFile(java.net.URL inpURL, java.io.File outFile)
          Copies an input URL to an output file
static int copyFile(java.net.URL inpURL, java.io.File outFile, boolean progress)
          Copies an input URL to an output file
static int copyFile(java.net.URL inpURL, java.io.File outFile, boolean progress, int timeoutMS)
          Copies an input URL to an output file
static int copyFile(java.net.URL inpURL, java.io.OutputStream out)
          Copies an input URL to an output file
static int copyFile(java.net.URL inpURL, java.io.OutputStream out, boolean progress)
          Copies an input URL to an output file
static int copyFile(java.net.URL inpURL, java.io.OutputStream out, boolean progress, int timeoutMS)
          Copies an input URL to an output file
static int copyStreams(java.io.InputStream input, java.io.OutputStream output)
          Copies bytes from one stream to another
static int copyStreams(java.io.InputStream input, java.io.OutputStream output, byte[] pattern, int maxLen)
          Copies bytes from one stream to another
static int copyStreams(java.io.InputStream input, java.io.OutputStream output, byte[] pattern, int maxLen, boolean progress)
          Copies bytes from one stream to another.
If 'maxLen' is >= '0', then at most 'maxLen' bytes will be written to the output stream.
static int copyStreams(java.io.InputStream input, java.io.OutputStream output, int maxLen)
          Copies bytes from one stream to another
static java.io.File findFile(java.io.File parentDir, java.lang.String[] fileNames)
          Returns the file path for the first file found in the specified list
static java.util.List<java.lang.String> findPatternInFile(java.io.File file, java.lang.String pattern, boolean ignoreCase)
          Search (grep) for the specified pattern in the specified file
static java.lang.Object getAttribute(java.io.File file, java.lang.String attr)
          Gets the specified attribute for this file.
static java.io.File getCygwinSymlinkFile(java.io.File link, boolean makeAbsolute)
          Gets the String path target of the Cygwin symbolic link
(EXPERIMENTAL: May not work with all Cygwin symbolic link files)
static java.io.File[] getDirectories(java.io.File dir)
          Returns an array of sub-directories within the specified parent directory.
static java.lang.String getExtension(java.io.File file)
          Gets the shortest possible extension characters from the specified file.
static java.lang.String getExtension(java.lang.String filePath)
          Gets the extension characters from the specified file name
static java.lang.Object getFilePath(java.io.File file)
          Returns a java.nio.file.Path instance for this file
static java.io.File[] getFiles(java.io.File dir)
          Returns an array of files within the specified parent directory.
static java.io.File[] getFiles(java.io.File dir, java.util.regex.Pattern regex, boolean recursiveDecent)
          Returns an array of files within the specified parent directory.
static java.io.File[] getFiles(java.io.File dir, java.util.Set<java.lang.String> extnSet, boolean recursiveDecent)
          Returns an array of files within the specified parent directory which match the specified extensions.
static java.io.File[] getFiles(java.io.File dir, java.lang.String[] extnList, boolean recursiveDecent)
          Returns an array of files within the specified parent directory which match the specified extensions.
static java.io.File[] getFiles(java.io.File dir, java.lang.String fileGlob, boolean recursiveDecent)
          Returns an array of files within the specified parent directory.
static java.io.File[] getFilesystemRoots()
          Return an array of all filesystem 'root' directories
static java.lang.String getGroupOwner(java.io.File file)
          Gets the group owner of this file
static java.lang.String getHash_MD5(byte[] data)
          Returns the MD5 hash for the specified bytes
static java.lang.String getHash_MD5(java.io.File file)
          Returns the MD5 hash for the specified file
static java.lang.String getHash_SHA1(byte[] data)
          Returns the SHA-1 hash for the specified bytes
static java.lang.String getHash_SHA1(java.io.File file)
          Returns the SHA-1 hash for the specified bytes
static java.lang.String getHash_SHA256(byte[] data)
          Returns the SHA-256 hash for the specified bytes
static java.lang.String getHash_SHA256(java.io.File file)
          Returns the SHA-256 hash for the specified bytes
static java.io.File getRealFile(java.io.File file)
          Gets the real (canonical) file for the specified file/path
static java.io.File getRealFile(java.io.File dir, java.lang.String file)
          Gets the real (canonical) file for the specified file/path
static java.lang.String getUserOwner(java.io.File file)
          Gets the user owner of this file
static java.io.File getWindowsShortcutFile(java.io.File link, boolean makeAbsolute)
          Gets the String path target of the Windows shortcut.
(EXPERIMENTAL: May not work with all Windows shortcut files)
static boolean hasExtension(java.io.File file, java.lang.String[] extn)
          Returns true if the specified file has an extension which matches one of the extensions listed in the specified String array
static boolean hasExtension(java.lang.String filePath, java.lang.String[] extn)
          Returns true if the specified file path has an extension which matches one of the extensions listed in the specified String array
static boolean hasFileSeparator(java.lang.String fn)
          Returns true if the specified String contains a file separator
static boolean isAbsolute(java.io.File f)
          Returns true if the specified path reference is absolute
static boolean isCygwinSymlink(java.io.File link)
          Returns true if the specified file is a Cygwin symbolic link
(EXPERIMENTAL: May not work with all Cygwin symbolic link files)
static boolean isDirectory(java.io.File d)
          Returns true if the specified item is a directory
static boolean isDirectory(java.lang.String d)
          Returns true if the specified item is a directory
static boolean isFile(java.io.File f)
          Returns true if the specified item is a file
static boolean isFile(java.io.File f, java.lang.String ext)
          Returns true if the specified item is a file with the specified extension
static boolean isFile(java.lang.String f)
          Returns true if the specified item is a file
static boolean isFileSeparatorChar(char ch)
          Returns true if the specified character is a file separator
static boolean isSymbolicLink(java.io.File file)
          Returns true if this file is a symbolic link
static boolean isWindowsShortcut(java.io.File link)
          Returns true if the specified file is a Windows shortcut file
(EXPERIMENTAL: May not work with all Windows shortcut files)
static void main(java.lang.String[] argv)
          Debug/Testing entry point
static java.io.InputStream openInputFile(java.io.File file)
          Opens the specified file for reading
static java.io.InputStream openInputFile(java.lang.String file)
          Opens the specified file for reading
static boolean readBoolean_stdin(java.lang.String msg, boolean dft)
          Prints a message, and reads a boolean value from stdin
static double readDouble_stdin(java.lang.String msg, double dft)
          Prints a message, and reads a double value from stdin
static byte[] readFile(java.io.File file)
          Returns an array of bytes read from the specified file
static byte[] readFile(java.io.File file, int maxLen)
          Returns an array of bytes read from the specified file
static byte[] readFile(java.lang.String file)
          Returns an array of bytes read from the specified file
static java.lang.String readLine_stdin()
          Reads a single line of characters from stdin, terminated by either a newline (\n) or carriage-return (\r)
static java.lang.String readLine(java.io.InputStream input)
          Reads a single line of characters from the specified InputStream, terminated by either a newline (\n) or carriage-return (\r)
static java.lang.String readLine(java.io.InputStream input, char eol)
          Reads a single line of characters from the specified InputStream, terminated by either a newline (\n) or carriage-return (\r)
static java.lang.String readLineNL(java.io.InputStream input)
          Reads a single line of characters from the specified InputStream, terminated by a newline only (\n).
static long readLong_stdin(java.lang.String msg, long dft)
          Prints a message, and reads a long value from stdin
static byte[] readStream(java.io.InputStream input)
          Returns an array of bytes read from the specified InputStream
static byte[] readStream(java.io.InputStream input, int maxLen)
          Returns an array of bytes read from the specified InputStream
static java.lang.String readString_stdin(java.lang.String msg, java.lang.String dft)
          Prints a message, and reads a line of text from stdin
static java.lang.String removeExtension(java.io.File file)
          Removes the extension from the specified file
static java.lang.String removeExtension(java.lang.String filePath)
          Removes the extension from the specified file path
static java.io.File resolveCommand(java.lang.String cmd)
          Resolves specified command relative to the environment "PATH" variable
static boolean supportsFilesGetAttribute()
          Returns true if "Files.getAttribute(...)" is supported.
static java.io.File toFile(java.io.File base, java.lang.String[] path)
          Convert a URL specification to a File
static java.io.File toFile(java.lang.String[] path)
          Convert a URL specification to a File
static java.io.File toFile(java.net.URL url)
          Convert a URL specification to a File
static java.net.URL toURL(java.io.File file)
          Convert a File specification to a URL
static boolean traverseAllFiles(java.io.File dir, java.io.FileFilter filter)
          Executed the filter "accept" callback on all files within the specified directory
static boolean writeEscapedUnicode(java.lang.String dataStr, java.io.File file)
          Writes a String to the specified file in "ISO-8859-1" character encoding.
Unicode characters are escaped using the '' format.
static boolean writeFile(byte[] data, java.io.File file)
          Writes a byte array to the specified file
static boolean writeFile(byte[] data, java.io.File file, boolean append)
          Writes a byte array to the specified file
static void writeStream(java.io.OutputStream output, java.lang.String dataStr)
          Writes a String to the specified OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_URL_COPYFILE_TIMEOUT_MS

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

FileTools

public FileTools()
Method Detail

toURL

public static java.net.URL toURL(java.io.File file)
                          throws java.net.MalformedURLException
Convert a File specification to a URL

Parameters:
file - The file specification
Returns:
A URL representing the specified file
Throws:
java.net.MalformedURLException - If a protocol handler for the URL could not be found, or if some other error occurred while constructing the URL

toFile

public static java.io.File toFile(java.net.URL url)
                           throws java.net.URISyntaxException
Convert a URL specification to a File

Parameters:
url - The URL specification
Returns:
A file representing the specified URL
Throws:
URIsyntaxException - if the protocol was not 'file' or URL could otherwise not be converted to a file
java.net.URISyntaxException

toFile

public static java.io.File toFile(java.io.File base,
                                  java.lang.String[] path)
Convert a URL specification to a File

Parameters:
base - The base file specification
path - The file path directories (last element may be a file name)
Returns:
A file representing the specified path

toFile

public static java.io.File toFile(java.lang.String[] path)
Convert a URL specification to a File

Parameters:
path - The file path directories (last element may be a file name)
Returns:
A file representing the specified path

getRealFile

public static java.io.File getRealFile(java.io.File file)
Gets the real (canonical) file for the specified file/path

Parameters:
file - The file for which the real file will be returned
Returns:
The real (canonical) file, or null if the file does not exist, or if an error occurs

getRealFile

public static java.io.File getRealFile(java.io.File dir,
                                       java.lang.String file)
Gets the real (canonical) file for the specified file/path

Parameters:
dir - The directory containing the specified file name
file - The file for which the real file will be returned
Returns:
The real (canonical) file, or null if the file does not exist, or if an error occurs

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.File outFile)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
outFile - The File to whish data will be written
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.File outFile,
                           boolean progress)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
outFile - The File to whish data will be written
progress - Show progress
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.File outFile,
                           boolean progress,
                           int timeoutMS)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
outFile - The File to whish data will be written
progress - Show progress
timeoutMS - The timeout in milliseconds (0 for infinite timeout)
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.OutputStream out)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
out - The OutputStream to whish data will be written
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.OutputStream out,
                           boolean progress)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
out - The OutputStream to whish data will be written
progress - Show progress
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyFile

public static int copyFile(java.net.URL inpURL,
                           java.io.OutputStream out,
                           boolean progress,
                           int timeoutMS)
                    throws java.io.IOException
Copies an input URL to an output file

Parameters:
inpURL - The URL from which data will be read
out - The OutputStream to whish data will be written
progress - Show progress
timeoutMS - The timeout in milliseconds (0 for infinite timeout)
Returns:
The number of bytes copied
Throws:
java.io.IOException

copyStreams

public static int copyStreams(java.io.InputStream input,
                              java.io.OutputStream output)
                       throws java.io.IOException
Copies bytes from one stream to another

Parameters:
input - The InputStream
output - The OutputStream
Returns:
The number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs

copyStreams

public static int copyStreams(java.io.InputStream input,
                              java.io.OutputStream output,
                              int maxLen)
                       throws java.io.IOException
Copies bytes from one stream to another

Parameters:
input - The InputStream
output - The OutputStream
maxLen - The maximum number of bytes to copy
Returns:
The number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs

copyStreams

public static int copyStreams(java.io.InputStream input,
                              java.io.OutputStream output,
                              byte[] pattern,
                              int maxLen)
                       throws java.io.IOException
Copies bytes from one stream to another

Parameters:
input - The InputStream
output - The OutputStream
pattern - The pattern to match, to terminate the copy
maxLen - The maximum number of bytes to copy
Returns:
The number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs

copyStreams

public static int copyStreams(java.io.InputStream input,
                              java.io.OutputStream output,
                              byte[] pattern,
                              int maxLen,
                              boolean progress)
                       throws java.io.EOFException,
                              java.io.IOException
Copies bytes from one stream to another.
If 'maxLen' is >= '0', then at most 'maxLen' bytes will be written to the output stream. If 'pattern' is specified, the stream will be scanned for the first occurance of the matching pattern, however, only 'maxLen' bytes will be written. to the output stream.

Parameters:
input - The InputStream
output - The OutputStream
pattern - The pattern to match, to terminate the copy
maxLen - The maximum number of bytes to copy
progress - Show progress (to stdout)
Returns:
The number of bytes copied
Throws:
java.io.EOFException - if the end of stream is reached before the pattern is found
java.io.IOException - if an I/O error occurs (on either input or output)

openInputFile

public static java.io.InputStream openInputFile(java.lang.String file)
Opens the specified file for reading

Parameters:
file - The path of the file to open
Returns:
The opened InputStream

openInputFile

public static java.io.InputStream openInputFile(java.io.File file)
Opens the specified file for reading

Parameters:
file - The file to open
Returns:
The opened InputStream

closeStream

public static void closeStream(java.io.InputStream in)
Closes the specified InputStream.

Parameters:
in - The InputStream to close

closeStream

public static void closeStream(java.io.OutputStream out)
Closes the specified OutputStream

Parameters:
out - The OutputStream to close

readStream

public static byte[] readStream(java.io.InputStream input)
                         throws java.io.IOException
Returns an array of bytes read from the specified InputStream

Parameters:
input - The InputStream
Returns:
The array of bytes read from the InputStream
Throws:
java.io.IOException - if an I/O error occurs

readStream

public static byte[] readStream(java.io.InputStream input,
                                int maxLen)
                         throws java.io.IOException
Returns an array of bytes read from the specified InputStream

Parameters:
input - The InputStream
maxLen - The maximum number of bytes to read from the stream
Returns:
The array of bytes read from the InputStream
Throws:
java.io.IOException - if an I/O error occurs

writeStream

public static void writeStream(java.io.OutputStream output,
                               java.lang.String dataStr)
                        throws java.io.IOException
Writes a String to the specified OutputStream

Parameters:
output - The OutputStream
dataStr - The String to write to the OutputStream
Throws:
java.io.IOException - if an I/O error occurs

readFile

public static byte[] readFile(java.lang.String file)
Returns an array of bytes read from the specified file

Parameters:
file - The file path from which the byte array is read
Returns:
The byte array read from the specified file

readFile

public static byte[] readFile(java.io.File file)
Returns an array of bytes read from the specified file

Parameters:
file - The file from which the byte array is read
Returns:
The byte array read from the specified file

readFile

public static byte[] readFile(java.io.File file,
                              int maxLen)
Returns an array of bytes read from the specified file

Parameters:
file - The file from which the byte array is read
maxLen - The maximum number of bytes to read from the file
Returns:
The byte array read from the specified file

readLine

public static java.lang.String readLine(java.io.InputStream input,
                                        char eol)
                                 throws java.io.IOException
Reads a single line of characters from the specified InputStream, terminated by either a newline (\n) or carriage-return (\r)

Parameters:
input - The InputStream
eol - The specific end-of-line character to search for
Returns:
The line read from the InputStream
Throws:
java.io.EOFException - if the end of the input stream is encountered
java.io.IOException - if an I/O error occurs

readLine

public static java.lang.String readLine(java.io.InputStream input)
                                 throws java.io.IOException
Reads a single line of characters from the specified InputStream, terminated by either a newline (\n) or carriage-return (\r)

Parameters:
input - The InputStream
Returns:
The line read from the InputStream
Throws:
java.io.EOFException - if the end of the input stream is encountered
java.io.IOException - if an I/O error occurs

readLineNL

public static java.lang.String readLineNL(java.io.InputStream input)
                                   throws java.io.IOException
Reads a single line of characters from the specified InputStream, terminated by a newline only (\n). Carriage-returns (\r) are ignored.

Parameters:
input - The InputStream
Returns:
The line read from the InputStream
Throws:
java.io.EOFException - if the end of the input stream is encountered
java.io.IOException - if an I/O error occurs

readLine_stdin

public static java.lang.String readLine_stdin()
                                       throws java.io.IOException
Reads a single line of characters from stdin, terminated by either a newline (\n) or carriage-return (\r)

Returns:
The line read from stdin
Throws:
java.io.IOException - if an I/O error occurs

readString_stdin

public static java.lang.String readString_stdin(java.lang.String msg,
                                                java.lang.String dft)
                                         throws java.io.IOException
Prints a message, and reads a line of text from stdin

Parameters:
msg - The message to print
dft - The default String returned, if no text was entered
Returns:
The line of text read from stdin
Throws:
java.io.IOException - if an I/O error occurs

readBoolean_stdin

public static boolean readBoolean_stdin(java.lang.String msg,
                                        boolean dft)
                                 throws java.io.IOException
Prints a message, and reads a boolean value from stdin

Parameters:
msg - The message to print
dft - The default boolean value returned, if no value was entered
Returns:
The boolean value read from stdin
Throws:
java.io.IOException - if an I/O error occurs

readLong_stdin

public static long readLong_stdin(java.lang.String msg,
                                  long dft)
                           throws java.io.IOException
Prints a message, and reads a long value from stdin

Parameters:
msg - The message to print
dft - The default long value returned, if no value was entered
Returns:
The long value read from stdin
Throws:
java.io.IOException - if an I/O error occurs

readDouble_stdin

public static double readDouble_stdin(java.lang.String msg,
                                      double dft)
                               throws java.io.IOException
Prints a message, and reads a double value from stdin

Parameters:
msg - The message to print
dft - The default double value returned, if no value was entered
Returns:
The double value read from stdin
Throws:
java.io.IOException - if an I/O error occurs

writeFile

public static boolean writeFile(byte[] data,
                                java.io.File file)
                         throws java.io.IOException
Writes a byte array to the specified file

Parameters:
data - The byte array to write to the file
file - The file to which the byte array is written
Returns:
True if the bytes were successfully written to the file
Throws:
java.io.IOException - if an I/O error occurs

writeFile

public static boolean writeFile(byte[] data,
                                java.io.File file,
                                boolean append)
                         throws java.io.IOException
Writes a byte array to the specified file

Parameters:
data - The byte array to write to the file
file - The file to which the byte array is written
append - True to append the bytes to the file, false to overwrite.
Returns:
True if the bytes were successfully written to the file
Throws:
java.io.IOException - if an error occurred.

writeEscapedUnicode

public static boolean writeEscapedUnicode(java.lang.String dataStr,
                                          java.io.File file)
                                   throws java.io.IOException
Writes a String to the specified file in "ISO-8859-1" character encoding.
Unicode characters are escaped using the '' format.

Parameters:
dataStr - The String to write to the file
file - The file to which the byte array is written
Returns:
True if the String was successfully written to the file
Throws:
java.io.IOException - if an error occurred.

findPatternInFile

public static java.util.List<java.lang.String> findPatternInFile(java.io.File file,
                                                                 java.lang.String pattern,
                                                                 boolean ignoreCase)
Search (grep) for the specified pattern in the specified file

Parameters:
file - The target file
pattern - The pattern String
ignoreCase - True to ignore case
Returns:
A list of matches, or null if no match was found

getExtension

public static java.lang.String getExtension(java.lang.String filePath)
Gets the extension characters from the specified file name

Parameters:
filePath - The file name
Returns:
The extension characters

getExtension

public static java.lang.String getExtension(java.io.File file)
Gets the shortest possible extension characters from the specified file. IE. "file.aa.bb.cc" would return extension "cc".

Parameters:
file - The file
Returns:
The extension characters

hasExtension

public static boolean hasExtension(java.lang.String filePath,
                                   java.lang.String[] extn)
Returns true if the specified file path has an extension which matches one of the extensions listed in the specified String array

Parameters:
filePath - The file path/name
extn - An array of file extensions
Returns:
True if the specified file path has a matching exention

hasExtension

public static boolean hasExtension(java.io.File file,
                                   java.lang.String[] extn)
Returns true if the specified file has an extension which matches one of the extensions listed in the specified String array

Parameters:
file - The file
extn - An array of file extensions
Returns:
True if the specified file has a matching exention

removeExtension

public static java.lang.String removeExtension(java.lang.String filePath)
Removes the extension from the specified file path

Parameters:
filePath - The file path from which the extension will be removed
Returns:
The file path with the extension removed

removeExtension

public static java.lang.String removeExtension(java.io.File file)
Removes the extension from the specified file

Parameters:
file - The file from which the extension will be removed
Returns:
The file path with the extension removed

isFileSeparatorChar

public static boolean isFileSeparatorChar(char ch)
Returns true if the specified character is a file separator

Parameters:
ch - The character to test
Returns:
True if the specified character is a file separator

hasFileSeparator

public static boolean hasFileSeparator(java.lang.String fn)
Returns true if the specified String contains a file separator

Parameters:
fn - The String file path
Returns:
True if the file String contains a file separator

resolveCommand

public static java.io.File resolveCommand(java.lang.String cmd)
Resolves specified command relative to the environment "PATH" variable

Parameters:
cmd - The command name. If the specified command is an absolute path, then the specified command path will me returned as-is.
Returns:
The resolved command path

isAbsolute

public static boolean isAbsolute(java.io.File f)
Returns true if the specified path reference is absolute

Parameters:
f - The file to test for absolute
Returns:
True if the specified file is absolute

isFile

public static boolean isFile(java.lang.String f)
Returns true if the specified item is a file

Parameters:
f - The item to check
Returns:
True if the specified item is a file

isFile

public static boolean isFile(java.io.File f)
Returns true if the specified item is a file

Parameters:
f - The item to check
Returns:
True if the specified item is a file

isFile

public static boolean isFile(java.io.File f,
                             java.lang.String ext)
Returns true if the specified item is a file with the specified extension

Parameters:
f - The item to check
ext - The required file extension
Returns:
True if the specified item is a file with the specified extension

isDirectory

public static boolean isDirectory(java.lang.String d)
Returns true if the specified item is a directory

Parameters:
d - The item to check
Returns:
True if the specified item is a directory

isDirectory

public static boolean isDirectory(java.io.File d)
Returns true if the specified item is a directory

Parameters:
d - The item to check
Returns:
True if the specified item is a directory

isWindowsShortcut

public static boolean isWindowsShortcut(java.io.File link)
Returns true if the specified file is a Windows shortcut file
(EXPERIMENTAL: May not work with all Windows shortcut files)

Parameters:
link - A file possibly representing a Windows shortcut file
Returns:
True if the specified file is a Windows shortcut file

getWindowsShortcutFile

public static java.io.File getWindowsShortcutFile(java.io.File link,
                                                  boolean makeAbsolute)
Gets the String path target of the Windows shortcut.
(EXPERIMENTAL: May not work with all Windows shortcut files)

Parameters:
link - The Windows shortcut file.
makeAbsolute - If true and the shortcut is not absolute, the returned file will be made relative to the parent directory of the specified link. If false, the returned file will left as specified in the shortcut link.
Returns:
The shortcut target file/directory.

isCygwinSymlink

public static boolean isCygwinSymlink(java.io.File link)
Returns true if the specified file is a Cygwin symbolic link
(EXPERIMENTAL: May not work with all Cygwin symbolic link files)

Parameters:
link - A file possibly representing a Cygwin symbolic link
Returns:
True if the specified file is a Cygwin symbolic link

getCygwinSymlinkFile

public static java.io.File getCygwinSymlinkFile(java.io.File link,
                                                boolean makeAbsolute)
Gets the String path target of the Cygwin symbolic link
(EXPERIMENTAL: May not work with all Cygwin symbolic link files)

Parameters:
link - The Cygwin symbolic link file.
makeAbsolute - If true and the link is not absolute, the returned file will be made relative to the parent directory of the specified link. If false, the returned file will left as specified in the Cygwin symbolic link.
Returns:
The Cygwin symbolic link target file/directory.

canExecute

public static boolean canExecute(java.io.File f)
Returns true if the file can be executed

Parameters:
f - The file to test
Returns:
True if the file can be executed

canRead

public static boolean canRead(java.io.File f)
Returns true if the file can be read

Parameters:
f - The file to test
Returns:
True if the file can be read

canWrite

public static boolean canWrite(java.io.File f)
Returns true if the file can be written

Parameters:
f - The file to test
Returns:
True if the file can be written

findFile

public static java.io.File findFile(java.io.File parentDir,
                                    java.lang.String[] fileNames)
Returns the file path for the first file found in the specified list

Parameters:
parentDir - The parent directory
fileNames - The list of files to search for
Returns:
The path to the file, or null if not found

getFilesystemRoots

public static java.io.File[] getFilesystemRoots()
Return an array of all filesystem 'root' directories

Returns:
An array of all filesystem 'root' directories

getDirectories

public static java.io.File[] getDirectories(java.io.File dir)
Returns an array of sub-directories within the specified parent directory. Files are not included in the list.

Parameters:
dir - The parent directory
Returns:
An array of sub-directories within the specified parent directory, or null if the specified file is not a directory.

getFiles

public static java.io.File[] getFiles(java.io.File dir)
Returns an array of files within the specified parent directory. Directories are not included in the list. (non-recursive)

Parameters:
dir - The parent directory
Returns:
An array of files within the specified parent directory, or null if the specified directory is not a directory.

getFiles

public static java.io.File[] getFiles(java.io.File dir,
                                      java.util.Set<java.lang.String> extnSet,
                                      boolean recursiveDecent)
Returns an array of files within the specified parent directory which match the specified extensions. Directories are not included in the list.

Parameters:
dir - The parent directory
extnSet - The set of extensions to look for
recursiveDecent - True to descend all directories looking for matching files
Returns:
An array of files within the specified parent directory, or null if the specified file is not a directory.

getFiles

public static java.io.File[] getFiles(java.io.File dir,
                                      java.lang.String[] extnList,
                                      boolean recursiveDecent)
Returns an array of files within the specified parent directory which match the specified extensions. Directories are not included in the list.

Parameters:
dir - The parent directory
extnList - The list of extensions to look for
recursiveDecent - True to descend all directories looking for matching files
Returns:
An array of files within the specified parent directory, or null if the specified directory is not a directory.

getFiles

public static java.io.File[] getFiles(java.io.File dir,
                                      java.util.regex.Pattern regex,
                                      boolean recursiveDecent)
Returns an array of files within the specified parent directory. Directories are not included in the list.

Parameters:
dir - The parent directory
regex - A regular expression (Pattern) that the file names must match
recursiveDecent - True to descend all directories looking for matching files
Returns:
An array of files within the specified parent directory, or null if the specified directory is not a directory.

getFiles

public static java.io.File[] getFiles(java.io.File dir,
                                      java.lang.String fileGlob,
                                      boolean recursiveDecent)
Returns an array of files within the specified parent directory. Directories are not included in the list.

Parameters:
dir - The parent directory
fileGlob - A file glob expression that the file names must match
recursiveDecent - True to descend all directories looking for matching files
Returns:
An array of files within the specified parent directory, or null if the specified directory is not a directory.

traverseAllFiles

public static boolean traverseAllFiles(java.io.File dir,
                                       java.io.FileFilter filter)
Executed the filter "accept" callback on all files within the specified directory

Parameters:
dir - The parent directory
filter - The callback filter
Returns:
True if the specified file is a directory, false otherwise.

getHash_MD5

public static java.lang.String getHash_MD5(java.io.File file)
Returns the MD5 hash for the specified file

Parameters:
file - The file
Returns:
The MD5 hash

getHash_MD5

public static java.lang.String getHash_MD5(byte[] data)
Returns the MD5 hash for the specified bytes

Parameters:
data - The data bytes
Returns:
The MD5 hash

getHash_SHA1

public static java.lang.String getHash_SHA1(java.io.File file)
Returns the SHA-1 hash for the specified bytes

Parameters:
file - The file
Returns:
The SHA-1 hash

getHash_SHA1

public static java.lang.String getHash_SHA1(byte[] data)
Returns the SHA-1 hash for the specified bytes

Parameters:
data - The data bytes
Returns:
The SHA-1 hash

getHash_SHA256

public static java.lang.String getHash_SHA256(java.io.File file)
Returns the SHA-256 hash for the specified bytes

Parameters:
file - The file
Returns:
The SHA-256 hash

getHash_SHA256

public static java.lang.String getHash_SHA256(byte[] data)
Returns the SHA-256 hash for the specified bytes

Parameters:
data - The data bytes
Returns:
The SHA-256 hash

supportsFilesGetAttribute

public static boolean supportsFilesGetAttribute()
Returns true if "Files.getAttribute(...)" is supported.


getFilePath

public static java.lang.Object getFilePath(java.io.File file)
                                    throws java.lang.UnsupportedOperationException,
                                           java.lang.IllegalArgumentException
Returns a java.nio.file.Path instance for this file

Throws:
java.lang.UnsupportedOperationException
java.lang.IllegalArgumentException

getAttribute

public static java.lang.Object getAttribute(java.io.File file,
                                            java.lang.String attr)
                                     throws java.lang.UnsupportedOperationException,
                                            java.lang.IllegalArgumentException,
                                            java.io.IOException,
                                            java.lang.SecurityException
Gets the specified attribute for this file. Will compile on Java-6, however requires Java-7 for valid results. Will return null, when running on Java-6

Throws:
java.lang.UnsupportedOperationException
java.lang.IllegalArgumentException
java.io.IOException
java.lang.SecurityException

isSymbolicLink

public static boolean isSymbolicLink(java.io.File file)
                              throws java.lang.UnsupportedOperationException
Returns true if this file is a symbolic link

Throws:
java.lang.UnsupportedOperationException

getUserOwner

public static java.lang.String getUserOwner(java.io.File file)
Gets the user owner of this file


getGroupOwner

public static java.lang.String getGroupOwner(java.io.File file)
Gets the group owner of this file


main

public static void main(java.lang.String[] argv)
Debug/Testing entry point

Parameters:
argv - The Command-line args