com.isti.util
Class FileUtils

java.lang.Object
  extended by com.isti.util.FileUtils

public class FileUtils
extends java.lang.Object

Class FileUtils contains various static utility methods for handling files.


Field Summary
protected static java.applet.Applet appletObj
           
protected static boolean DEBUG_FLAG
           
protected static FileUtils fileUtilsObj
           
protected static java.lang.String lastCreateUnusedFileNameStr
           
protected static java.lang.Object lastCreateUnusedFNSyncObj
           
static long MS_PER_DAY
          Number of milliseconds in a day.
static long MS_PER_HOUR
          Number of milliseconds in an hour.
protected static int STREAM_TRANSFER_BUFFER_SIZE
           
 
Method Summary
static java.lang.String addStrToFileName(java.lang.String fileNameStr, java.lang.String s)
          Add a string to the end of a file name (before the extension if present.)
static java.io.BufferedReader appletResourceOpen(java.applet.Applet appletObj, java.lang.String nameStr)
          Attempts to open the given name as a file in the codebase of the given applet.
static java.io.InputStream appletResourceOpenInputStream(java.applet.Applet appletObj, java.lang.String nameStr)
          Attempts to open the given name as a file in the codebase of the given applet.
static java.io.BufferedInputStream appletResourceOpenStream(java.applet.Applet appletObj, java.lang.String nameStr)
          Attempts to open the given name as a file in the codebase of the given applet.
static java.io.BufferedReader appResourceOpen(java.lang.String nameStr)
          Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.
static java.io.InputStream appResourceOpenInputStream(java.lang.String nameStr)
          Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.
static java.io.BufferedInputStream appResourceOpenStream(java.lang.String nameStr)
          Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.
static java.lang.String buildPathName(java.lang.String dirStr, java.lang.String fileStr)
          Combines the given directory and file names.
static java.lang.String buildPathName(java.lang.String dirStr, java.lang.String fileStr, boolean forwardSlashFlag)
          Combines the given directory and file names.
static boolean closeStream(java.io.InputStream inputStreamObj)
          Closes the given input stream.
static boolean closeStream(java.io.OutputStream outputStreamObj)
          Closes the given output stream.
static void copyFile(java.io.File sourceFileObj, java.io.File destFileObj)
          Copies one file to another.
static void copyFile(java.io.File sourceFileObj, java.io.File destFileObj, boolean copyLastModFlag)
          Copies one file to another.
static void copyFile(java.lang.String sourceFileNameStr, java.lang.String destFileNameStr)
          Copies one file to another.
static void copyFile(java.lang.String sourceFileNameStr, java.lang.String destFileNameStr, boolean copyLastModFlag)
          Copies one file to another.
static void copyLastModifiedTime(java.io.File sourceFileObj, java.io.File destFileObj)
          Copies the last-modified-time value from one file to another.
static java.lang.String createBackupFileName(java.lang.String fileNameStr)
          Creates a backup file name for the specified file name.
static java.lang.String createBackupFileName(java.lang.String fileNameStr, java.lang.String backupStr)
          Creates a backup file name for the specified file name.
static boolean createParentDirs(java.io.File fileObj)
          Creates any needed parent directories needed for the given file object.
static boolean createParentDirs(java.lang.String nameStr)
          Creates any needed parent directories needed for the given file/path name.
static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.io.File parentDirFileObj, boolean useTimeFlag)
          Creates a new 'File' object that references an unused file name.
static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.io.File parentDirFileObj, boolean useTimeFlag, boolean fileExtFlag)
          Creates a new 'File' object that references an unused file name.
static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.lang.String parentDirStr, boolean useTimeFlag)
          Creates a new 'File' object that references an unused file name.
static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.lang.String parentDirStr, boolean useTimeFlag, boolean fileExtFlag)
          Creates a new 'File' object that references an unused file name.
static void deleteFiles(java.io.File file)
          Deletes the specified file or if a directory is specified deletes the directory and any subdirectories.
static void deleteFiles(java.io.File[] fileList, int maxAgeDays)
          Deletes files in the specified list that are older than the given age.
static void deleteFiles(java.io.File[] fileList, long maxAgeMs)
          Deletes files in the specified list that are older than the given age.
static void deleteOldFiles(java.io.File directoryObj, int maxAgeDays)
          Deletes files older than the given age from the specified directory.
static void deleteOldFiles(java.io.File directoryObj, int maxAgeDays, java.lang.String filterStr)
          Deletes files older than the given age from the specified directory.
static void deleteOldFiles(java.io.File directoryObj, long maxAgeMs)
          Deletes files older than the given age from the specified directory.
static void deleteOldFiles(java.io.File directoryObj, long maxAgeMs, java.lang.String filterStr)
          Deletes files older than the given age from the specified directory.
protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr, java.util.Properties urlRequestProps)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
protected static java.net.URL doFileMultiOpenInputURL(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
protected static java.net.URL doGetURL(java.lang.String nameStr)
          Attempts to get a URL from the given name as a URL, as a local file, and as a system resource (whichever works first).
static boolean endsWithDirSepChar(java.lang.String str)
          Returns an indicator of whether or not the given string ends with a directory separator character.
static boolean existsMultiOpen(java.lang.String nameStr)
          Determines if the given name denotes an existing local file or a URL or 'jar'-file resource that may be accessed.
static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr, java.util.Properties urlRequestProps)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr, java.util.Properties urlRequestProps)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.net.URL fileMultiOpenInputURL(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.io.BufferedInputStream fileMultiOpenStream(java.lang.String nameStr)
          Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).
static java.io.BufferedReader getBufferedReader(java.io.InputStream stmObj)
          Gets a buffered reader for the specified input stream.
static long getFileAge(java.io.File f, long currentTime)
           
static java.lang.String getFileExtension(java.lang.String fileNameStr)
          Returns the extension portion of the file name string or null if none (does not include the ".".)
static int getFileExtensionIndex(java.lang.String fileNameStr)
          Returns the index of the extension portion of the file name string.
static long getFileLength(java.lang.String nameStr)
          Returns the file-length value for the file denoted by the given name.
static java.lang.String getFileNameWithoutExtension(java.lang.String fileNameStr)
          Returns the file name string without the extension portion.
static long getLastModifiedTime(java.lang.String nameStr)
          Returns the last-modified time value for the file denoted by the given name.
static java.net.URL getURL(java.lang.String nameStr)
          Attempts to get a URL from the given name as a URL, as a local file, and as a system resource (whichever works first).
static boolean isDirSepChar(char ch)
          Returns an indicator of whether or not the given character is a directory separator character.
static java.io.File[] listAllFiles(java.io.File dirFileObj, java.io.FileFilter filterObj)
          Returns an array of abstract pathnames denoting the requested files in the specified directory and all subdirectories.
static java.io.File[] listFiles(java.io.File directoryObj)
          Returns an array of abstract pathnames denoting the files in the specified directory.
static java.io.File[] listFiles(java.io.File directoryObj, java.io.FileFilter filter)
          Returns an array of abstract pathnames denoting the files in the specified directory.
static void moveFile(java.io.File sourceFileObj, java.io.File destDirFileObj)
          Moves the specified file to a new location (even if the new location is on a different filesystem).
static void moveFile(java.lang.String sourceFileNameStr, java.lang.String destDirNameStr)
          Moves the specified file to a new location (even if the new location is on a different filesystem).
static void readFileTail(java.lang.String sourceFileNameStr, long numberOfLines, java.io.OutputStream outputStreamObj)
          Reads given number of lines from tail end of given file.
static byte[] readFileToBuffer(java.io.File fileObj)
          Reads data from a file into a buffer.
static byte[] readFileToBuffer(java.lang.String fileNameStr)
          Reads data from a file into a buffer.
static java.lang.String readFileToString(java.io.File fileObj)
          Reads data from a file into a string.
static java.lang.String readFileToString(java.io.File fileObj, java.lang.String charsetNameStr)
          Reads data from a file into a string.
static java.lang.String readFileToString(java.lang.String fileNameStr)
          Reads data from a file into a string.
static java.lang.String readFileToString(java.lang.String fileNameStr, java.lang.String charsetNameStr)
          Reads data from a file into a string.
static byte[] readMultiOpenFileToBuffer(java.lang.String fileNameStr)
          Reads data from a file into a byte array, where the given name may specify a local file, a URL, a resource or an entry in a 'jar' file (whichever works first).
static java.lang.String readMultiOpenFileToString(java.lang.String fileNameStr)
          Reads data from a file into a string, where the given name may specify a local file, a URL, a resource or an entry in a 'jar' file (whichever works first).
static byte[] readStreamToBuffer(java.io.InputStream stmObj)
          Reads data from an input stream into a byte array.
static java.lang.String readStreamToString(java.io.BufferedReader rdrObj)
          Reads data from an input stream into a string.
static java.lang.String readStreamToString(java.io.InputStream stmObj)
          Reads data from an input stream into a string.
static java.lang.String readStreamToString(java.io.InputStream inStmObj, java.lang.String charsetNameStr)
          Reads data from an input stream into a string.
static java.lang.String removeLeadingDotDir(java.lang.String fileNameStr)
          Removes leading "dot" directory from given filename.
static void setAppletObj(java.applet.Applet appletObj)
          Used to set Applet object to be used by the "appResourceOpen" methods.
static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj)
          Transfers data from the input stream to the output stream.
static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj, CallBackCompletion callBack)
          Transfers data from the input stream to the output stream.
static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj, long maxBytesLimit)
          Transfers data from the input stream to the output stream.
static boolean urlExists(java.net.URL urlObj)
          Tests whether the specified URL exists.
static void writeBufferToFile(java.lang.String fileNameStr, byte[] btArr)
          Writes a data buffer to a file.
static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr)
          Writes a data string to a file.
static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, boolean appendFlag)
          Writes a data string to a file.
static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, boolean appendFlag, java.lang.String charsetNameStr)
          Writes a data string to a file.
static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, java.lang.String charsetNameStr)
          Writes a data string to a file.
static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr)
          Writes a data string to a file.
static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, boolean appendFlag)
          Writes a data string to a file.
static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, boolean appendFlag, java.lang.String charsetNameStr)
          Writes a data string to a file.
static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, java.lang.String charsetNameStr)
          Writes a data string to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_FLAG

protected static final boolean DEBUG_FLAG
See Also:
Constant Field Values

appletObj

protected static java.applet.Applet appletObj

fileUtilsObj

protected static FileUtils fileUtilsObj

STREAM_TRANSFER_BUFFER_SIZE

protected static int STREAM_TRANSFER_BUFFER_SIZE

MS_PER_HOUR

public static final long MS_PER_HOUR
Number of milliseconds in an hour.

See Also:
Constant Field Values

MS_PER_DAY

public static final long MS_PER_DAY
Number of milliseconds in a day.

See Also:
Constant Field Values

lastCreateUnusedFileNameStr

protected static java.lang.String lastCreateUnusedFileNameStr

lastCreateUnusedFNSyncObj

protected static final java.lang.Object lastCreateUnusedFNSyncObj
Method Detail

fileMultiOpenInputStream

public static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

fileMultiOpenInputStream

public static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr,
                                                           java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
urlRequestProps - the request properties to use for URL connections or null if none.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

doFileMultiOpenInputStream

protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

doFileMultiOpenInputStream

protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr,
                                                                java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
urlRequestProps - the request properties to use for URL connections or null if none.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

fileMultiOpenStream

public static java.io.BufferedInputStream fileMultiOpenStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The buffered InputStream object opened for the name, or null if the name could not be opened.

fileMultiOpen

public static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The BufferedReader object opened for the name, or null if the name could not be opened.

fileMultiOpen

public static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr,
                                                   java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
urlRequestProps - the request properties to use for URL connections or null if none.
Returns:
The BufferedReader object opened for the name, or null if the name could not be opened.

appletResourceOpenInputStream

public static java.io.InputStream appletResourceOpenInputStream(java.applet.Applet appletObj,
                                                                java.lang.String nameStr)
Attempts to open the given name as a file in the codebase of the given applet.

Parameters:
appletObj - Applet object.
nameStr - file name string.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

appletResourceOpenStream

public static java.io.BufferedInputStream appletResourceOpenStream(java.applet.Applet appletObj,
                                                                   java.lang.String nameStr)
Attempts to open the given name as a file in the codebase of the given applet.

Parameters:
appletObj - Applet object.
nameStr - file name string.
Returns:
The buffered InputStream object opened for the name, or null if the name could not be opened.

appletResourceOpen

public static java.io.BufferedReader appletResourceOpen(java.applet.Applet appletObj,
                                                        java.lang.String nameStr)
Attempts to open the given name as a file in the codebase of the given applet.

Parameters:
appletObj - Applet object.
nameStr - file name string.
Returns:
The BufferedReader object opened for the name, or null if the name could not be opened.

setAppletObj

public static void setAppletObj(java.applet.Applet appletObj)
Used to set Applet object to be used by the "appResourceOpen" methods. If this is not setup then the methods will attempt to open the input names as files.

Parameters:
appletObj - Applet object.

appResourceOpenInputStream

public static java.io.InputStream appResourceOpenInputStream(java.lang.String nameStr)
Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.

Parameters:
nameStr - file name string.
Returns:
The (unbuffered) InputStream object opened for the name, or null if the name could not be opened.

appResourceOpenStream

public static java.io.BufferedInputStream appResourceOpenStream(java.lang.String nameStr)
Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.

Parameters:
nameStr - file name string.
Returns:
The buffered InputStream object opened for the name, or null if the name could not be opened.

appResourceOpen

public static java.io.BufferedReader appResourceOpen(java.lang.String nameStr)
Attempts to open the given name via either the applet or application method, depending on if an Applet object has been setup via 'setAppletObj()'.

Parameters:
nameStr - file name string.
Returns:
The BufferedReader object opened for the name, or null if the name could not be opened.

fileMultiOpenInputURL

public static java.net.URL fileMultiOpenInputURL(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The URL object opened for the name, or null if the name could not be opened.

doFileMultiOpenInputURL

protected static java.net.URL doFileMultiOpenInputURL(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The URL object opened for the name, or null if the name could not be opened.

writeStringToFile

public static void writeStringToFile(java.lang.String fileNameStr,
                                     java.lang.String dataStr,
                                     boolean appendFlag)
                              throws java.io.IOException
Writes a data string to a file.

Parameters:
fileNameStr - the name of the output file.
dataStr - the data to be written.
appendFlag - true to append to current contents of file, false to overwrite.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.lang.String fileNameStr,
                                     java.lang.String dataStr)
                              throws java.io.IOException
Writes a data string to a file. Any previous contents in the file are overritten.

Parameters:
fileNameStr - the name of the output file.
dataStr - the data to be written.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.io.File fileObj,
                                     java.lang.String dataStr,
                                     boolean appendFlag)
                              throws java.io.IOException
Writes a data string to a file.

Parameters:
fileObj - the output file object to use.
dataStr - the data to be written.
appendFlag - true to append to current contents of file, false to overwrite.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.io.File fileObj,
                                     java.lang.String dataStr)
                              throws java.io.IOException
Writes a data string to a file. Any previous contents in the file are overritten.

Parameters:
fileObj - the output file object to use.
dataStr - the data to be written.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.lang.String fileNameStr,
                                     java.lang.String dataStr,
                                     boolean appendFlag,
                                     java.lang.String charsetNameStr)
                              throws java.io.IOException
Writes a data string to a file.

Parameters:
fileNameStr - the name of the output file.
dataStr - the data to be written.
appendFlag - true to append to current contents of file, false to overwrite.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.lang.String fileNameStr,
                                     java.lang.String dataStr,
                                     java.lang.String charsetNameStr)
                              throws java.io.IOException
Writes a data string to a file. Any previous contents in the file are overritten.

Parameters:
fileNameStr - the name of the output file.
dataStr - the data to be written.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.io.File fileObj,
                                     java.lang.String dataStr,
                                     boolean appendFlag,
                                     java.lang.String charsetNameStr)
                              throws java.io.IOException
Writes a data string to a file.

Parameters:
fileObj - the output file object to use.
dataStr - the data to be written.
appendFlag - true to append to current contents of file, false to overwrite.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeStringToFile

public static void writeStringToFile(java.io.File fileObj,
                                     java.lang.String dataStr,
                                     java.lang.String charsetNameStr)
                              throws java.io.IOException
Writes a data string to a file. Any previous contents in the file are overritten.

Parameters:
fileObj - the output file object to use.
dataStr - the data to be written.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

writeBufferToFile

public static void writeBufferToFile(java.lang.String fileNameStr,
                                     byte[] btArr)
                              throws java.io.IOException
Writes a data buffer to a file. Any previous contents in the file are overritten.

Parameters:
fileNameStr - the name of the output file.
btArr - the data to be written.
Throws:
java.io.IOException - if an error occurred while opening or writing to the output file.

readStreamToString

public static java.lang.String readStreamToString(java.io.BufferedReader rdrObj)
                                           throws java.io.IOException
Reads data from an input stream into a string. The stream is expected to provide characters organized into one or more lines.

Parameters:
rdrObj - the input stream to use.
Returns:
A String containing the contents of the file.
Throws:
java.io.IOException - if an error occurred while reading from the input stream.

readStreamToString

public static java.lang.String readStreamToString(java.io.InputStream stmObj)
                                           throws java.io.IOException
Reads data from an input stream into a string. The stream is expected to provide characters organized into one or more lines.

Parameters:
stmObj - the input stream to use.
Returns:
A String containing the contents of the file.
Throws:
java.io.IOException - if an error occurred while reading from the input stream.

readStreamToString

public static java.lang.String readStreamToString(java.io.InputStream inStmObj,
                                                  java.lang.String charsetNameStr)
                                           throws java.io.IOException
Reads data from an input stream into a string.

Parameters:
inStmObj - input stream to use.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Returns:
A String containing the contents of the file.
Throws:
java.io.IOException - if an error occurred while reading from the input stream.

readFileToString

public static java.lang.String readFileToString(java.lang.String fileNameStr)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
Reads data from a file into a string. The file is expected to contain characters organized into one or more lines.

Parameters:
fileNameStr - the name of the input file.
Returns:
A String containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readFileToString

public static java.lang.String readFileToString(java.io.File fileObj)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
Reads data from a file into a string. The file is expected to contain characters organized into one or more lines.

Parameters:
fileObj - the input file object.
Returns:
A String containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readFileToString

public static java.lang.String readFileToString(java.lang.String fileNameStr,
                                                java.lang.String charsetNameStr)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
Reads data from a file into a string.

Parameters:
fileNameStr - the name of the input file.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Returns:
A String containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readFileToString

public static java.lang.String readFileToString(java.io.File fileObj,
                                                java.lang.String charsetNameStr)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
Reads data from a file into a string.

Parameters:
fileObj - the input file object.
charsetNameStr - name of charset to use for conversion from data bytes to characters, or null for default charset.
Returns:
A String containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readMultiOpenFileToString

public static java.lang.String readMultiOpenFileToString(java.lang.String fileNameStr)
                                                  throws java.io.FileNotFoundException,
                                                         java.io.IOException
Reads data from a file into a string, where the given name may specify a local file, a URL, a resource or an entry in a 'jar' file (whichever works first). The file is expected to contain characters organized into one or more lines.

Parameters:
fileNameStr - the name of the input file.
Returns:
A String containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readStreamToBuffer

public static byte[] readStreamToBuffer(java.io.InputStream stmObj)
                                 throws java.io.IOException
Reads data from an input stream into a byte array. The stream is expected to provide characters organized into one or more lines.

Parameters:
stmObj - the input stream to use.
Returns:
A byte array containing the contents of the file.
Throws:
java.io.IOException - if an error occurred while reading from the input stream.

readFileToBuffer

public static byte[] readFileToBuffer(java.lang.String fileNameStr)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
Reads data from a file into a buffer.

Parameters:
fileNameStr - the name of the input file.
Returns:
A byte array containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readFileToBuffer

public static byte[] readFileToBuffer(java.io.File fileObj)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
Reads data from a file into a buffer.

Parameters:
fileObj - the 'File' object for the input file.
Returns:
A byte array containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

readMultiOpenFileToBuffer

public static byte[] readMultiOpenFileToBuffer(java.lang.String fileNameStr)
                                        throws java.io.FileNotFoundException,
                                               java.io.IOException
Reads data from a file into a byte array, where the given name may specify a local file, a URL, a resource or an entry in a 'jar' file (whichever works first).

Parameters:
fileNameStr - the name of the input file.
Returns:
A byte array containing the contents of the file.
Throws:
java.io.FileNotFoundException - if the specified file is not found.
java.io.IOException - if an error occurred while opening or reading from the input file.

createParentDirs

public static boolean createParentDirs(java.io.File fileObj)
Creates any needed parent directories needed for the given file object. The given object should denote a file, not a directory.

Parameters:
fileObj - the file object to use.
Returns:
true if successful or if the needed parent directories already existed, false if error.

createParentDirs

public static boolean createParentDirs(java.lang.String nameStr)
Creates any needed parent directories needed for the given file/path name. The given name should denote a file, not a directory.

Parameters:
nameStr - file name string.
Returns:
true if successful or if the needed parent directories already existed, false if error.

listFiles

public static java.io.File[] listFiles(java.io.File directoryObj)
Returns an array of abstract pathnames denoting the files in the specified directory.

Parameters:
directoryObj - directory object.

If the file does is not a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

listFiles

public static java.io.File[] listFiles(java.io.File directoryObj,
                                       java.io.FileFilter filter)
Returns an array of abstract pathnames denoting the files in the specified directory.

Parameters:
directoryObj - directory object
filter - The filename filter to use, or null for none.
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
See Also:

If the file does is not a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the {@link #File(java.io.File, java.lang.String) File(File, String)} constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.


listAllFiles

public static java.io.File[] listAllFiles(java.io.File dirFileObj,
                                          java.io.FileFilter filterObj)
Returns an array of abstract pathnames denoting the requested files in the specified directory and all subdirectories. Entries for the directories themselves are not included in the result. Each resulting abstract pathname is constructed from the given abstract pathname using the 'File' constructor. Therefore if the given pathname is absolute then each resulting pathname is absolute; if the given pathname is relative then each resulting pathname will be relative to the same directory. There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order. Note that the given filename filter must accept all directory entries (i.e., an 'IstiFileFilter' with 'setAcceptDirectories(true)').

Parameters:
dirFileObj - directory object to use.
filterObj - filename filter to use, or null for none.
Returns:
A new array of 'File' objects denoting the requested files in the specified directory and all subdirectories, or null if the given 'File' object does not denote a directory.

getBufferedReader

public static java.io.BufferedReader getBufferedReader(java.io.InputStream stmObj)
Gets a buffered reader for the specified input stream.

Parameters:
stmObj - the input stream.
Returns:
the buffered reader.

getFileAge

public static long getFileAge(java.io.File f,
                              long currentTime)
Parameters:
f - file
currentTime - current time
Returns:
the age of the file in milliseconds.

deleteFiles

public static void deleteFiles(java.io.File file)
Deletes the specified file or if a directory is specified deletes the directory and any subdirectories.

Parameters:
file - the 'File' object to delete.

deleteFiles

public static void deleteFiles(java.io.File[] fileList,
                               long maxAgeMs)
Deletes files in the specified list that are older than the given age.

Parameters:
fileList - the array of 'File' objects to delete.
maxAgeMs - the maximum number of milliseconds to keep files.
See Also:
listFiles

deleteFiles

public static void deleteFiles(java.io.File[] fileList,
                               int maxAgeDays)
Deletes files in the specified list that are older than the given age.

Parameters:
fileList - the array of 'File' objects to delete.
maxAgeDays - the maximum number of days to keep files.
See Also:
listFiles

deleteOldFiles

public static void deleteOldFiles(java.io.File directoryObj,
                                  long maxAgeMs,
                                  java.lang.String filterStr)
Deletes files older than the given age from the specified directory.

Parameters:
directoryObj - the directory to use.
maxAgeMs - the maximum number of milliseconds to keep files, or 0 to delete no files.
filterStr - the file filter string to use (i.e.: "*.txt", "temp.*", "temp.txt", "*bak*"), or null for none.
See Also:
IstiFileFilter.createFileFilter(java.lang.String)

deleteOldFiles

public static void deleteOldFiles(java.io.File directoryObj,
                                  long maxAgeMs)
Deletes files older than the given age from the specified directory.

Parameters:
directoryObj - the directory to use.
maxAgeMs - the maximum number of milliseconds to keep files, or 0 to delete no files.

deleteOldFiles

public static void deleteOldFiles(java.io.File directoryObj,
                                  int maxAgeDays,
                                  java.lang.String filterStr)
Deletes files older than the given age from the specified directory.

Parameters:
directoryObj - the directory to use.
maxAgeDays - the maximum number of days to keep files, or 0 to delete no files.
filterStr - the file filter string to use (i.e.: "*.txt", "temp.*", "temp.txt", "*bak*"), or null for none.
See Also:
IstiFileFilter.createFileFilter(java.lang.String)

deleteOldFiles

public static void deleteOldFiles(java.io.File directoryObj,
                                  int maxAgeDays)
Deletes files older than the given age from the specified directory.

Parameters:
directoryObj - the directory to use.
maxAgeDays - the maximum number of days to keep files, or 0 to delete no files.

getFileExtensionIndex

public static int getFileExtensionIndex(java.lang.String fileNameStr)
Returns the index of the extension portion of the file name string.

Parameters:
fileNameStr - the name of the file.
Returns:
the index of the extension portion of the file name string or -1 if none (includes the ".".)
See Also:
FileFilter.accept(java.io.File)

getFileExtension

public static java.lang.String getFileExtension(java.lang.String fileNameStr)
Returns the extension portion of the file name string or null if none (does not include the ".".)

Parameters:
fileNameStr - the name of the file.
Returns:
The extension portion of the file name string or null if none (does not include the ".".)

getFileNameWithoutExtension

public static java.lang.String getFileNameWithoutExtension(java.lang.String fileNameStr)
Returns the file name string without the extension portion.

Parameters:
fileNameStr - the name of the file.
Returns:
The file name string without the extension portion.

removeLeadingDotDir

public static java.lang.String removeLeadingDotDir(java.lang.String fileNameStr)
Removes leading "dot" directory from given filename. If the given filename starts with "./" or ".\" then the first two characters are removed.

Parameters:
fileNameStr - filename to process.
Returns:
The filename string with the leading "dot" directory removed, or the given string if the leading "dot" directory was not found.

getLastModifiedTime

public static long getLastModifiedTime(java.lang.String nameStr)
Returns the last-modified time value for the file denoted by the given name. The file may be a local file, a URL, a resource or an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The last-modified time value for the file denoted by the given name, or -1 if the time value could not be determined.

getFileLength

public static long getFileLength(java.lang.String nameStr)
Returns the file-length value for the file denoted by the given name. The file may be a local file, a URL, a resource or an entry in a 'jar' file (whichever works first).

Parameters:
nameStr - file name string.
Returns:
The file-length value for the file denoted by the given name, or -1 if the length could not be determined.

urlExists

public static boolean urlExists(java.net.URL urlObj)
                         throws java.io.IOException
Tests whether the specified URL exists.

Parameters:
urlObj - the URL.
Returns:
true if the URL exists, false otherwise.
Throws:
java.io.IOException - if an I/O exception occurs.

getURL

public static java.net.URL getURL(java.lang.String nameStr)
Attempts to get a URL from the given name as a URL, as a local file, and as a system resource (whichever works first).

Parameters:
nameStr - file name string.
Returns:
the URL or null if a URL could not be determined.

doGetURL

protected static java.net.URL doGetURL(java.lang.String nameStr)
Attempts to get a URL from the given name as a URL, as a local file, and as a system resource (whichever works first).

Parameters:
nameStr - file name string.
Returns:
the URL or null if a URL could not be determined.

existsMultiOpen

public static boolean existsMultiOpen(java.lang.String nameStr)
Determines if the given name denotes an existing local file or a URL or 'jar'-file resource that may be accessed.

Parameters:
nameStr - file name string.
Returns:
true if the given name denotes an existing file; false if not.

isDirSepChar

public static boolean isDirSepChar(char ch)
Returns an indicator of whether or not the given character is a directory separator character.

Parameters:
ch - the character to test.
Returns:
true if the given character is one of the following: '/', '\', ':'.

endsWithDirSepChar

public static boolean endsWithDirSepChar(java.lang.String str)
Returns an indicator of whether or not the given string ends with a directory separator character.

Parameters:
str - the string to test.
Returns:
true if the given string ends with one of the following: '/', '\', ':'.

buildPathName

public static java.lang.String buildPathName(java.lang.String dirStr,
                                             java.lang.String fileStr,
                                             boolean forwardSlashFlag)
Combines the given directory and file names. If the directory name does not end with a directory-separator character ('/', '\' or ':') then a forward-slash ('/') separator character is used.

Parameters:
dirStr - the directory name to use.
fileStr - the file name to use.
forwardSlashFlag - true to replace all backslash characters ('\') in the path with forward-slash characters ('/').
Returns:
The combined path name.

buildPathName

public static java.lang.String buildPathName(java.lang.String dirStr,
                                             java.lang.String fileStr)
Combines the given directory and file names. If the directory name does not end with a directory-separator character ('/', '\' or ':') then a forward-slash ('/') separator character is used. All backslash characters ('\') in the path are replaced with forward-slash characters ('/').

Parameters:
dirStr - the directory name to use.
fileStr - the file name to use.
Returns:
The combined path name.

addStrToFileName

public static java.lang.String addStrToFileName(java.lang.String fileNameStr,
                                                java.lang.String s)
Add a string to the end of a file name (before the extension if present.)

Parameters:
fileNameStr - the name of the file.
s - string to add.
Returns:
the new file name string.

createBackupFileName

public static java.lang.String createBackupFileName(java.lang.String fileNameStr)
Creates a backup file name for the specified file name.

Parameters:
fileNameStr - the name of the file.
Returns:
new file name string

createBackupFileName

public static java.lang.String createBackupFileName(java.lang.String fileNameStr,
                                                    java.lang.String backupStr)
Creates a backup file name for the specified file name.

Parameters:
fileNameStr - the name of the file.
backupStr - backup string to be added (bak) or null for none.
Returns:
new file name string

createUnusedFileNameObj

public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr,
                                                   java.lang.String parentDirStr,
                                                   boolean useTimeFlag,
                                                   boolean fileExtFlag)
Creates a new 'File' object that references an unused file name. The given template string is used to generate the file name, with a numeric value added to make it unique (if necessary).

Parameters:
tmplStr - the template to use when generating the file name, or null for none.
parentDirStr - the name of the parent directory to use, or null to use the current user directory.
useTimeFlag - if true then the current time value (in ms since 1/1/1970) is used in the file name, if false then an incrementing value is used, starting at 1 (if the template string name itself is already in use).
fileExtFlag - true to insert numeric value before the filename extension (if present); false to always append numeric value to end.
Returns:
A new 'File' object, or null if an unused file name object could not be created.

createUnusedFileNameObj

public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr,
                                                   java.lang.String parentDirStr,
                                                   boolean useTimeFlag)
Creates a new 'File' object that references an unused file name. The given template string is used to generate the file name, with a numeric value inserted before the extension (if present) to make it unique (if necessary).

Parameters:
tmplStr - the template to use when generating the file name, or null for none.
parentDirStr - the name of the parent directory to use, or null to use the current user directory.
useTimeFlag - if true then the current time value (in ms since 1/1/1970) is used in the file name, if false then an incrementing value is used, starting at 1 (if the template string name itself is already in use).
Returns:
A new 'File' object, or null if an unused file name object could not be created.

createUnusedFileNameObj

public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr,
                                                   java.io.File parentDirFileObj,
                                                   boolean useTimeFlag,
                                                   boolean fileExtFlag)
Creates a new 'File' object that references an unused file name. The given template string is used to generate the file name, with a numeric value added to make it unique (if necessary).

Parameters:
tmplStr - the template to use when generating the file name, or null for none.
parentDirFileObj - the File object for the parent directory to use, or null to use the current user directory.
useTimeFlag - if true then the current time value (in ms since 1/1/1970) is used in the file name, if false then an incrementing value is used, starting at 1 (if the template string name itself is already in use).
fileExtFlag - true to insert numeric value before the filename extension (if present); false to always append numeric value to end.
Returns:
A new 'File' object, or null if an unused file name object could not be created.

createUnusedFileNameObj

public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr,
                                                   java.io.File parentDirFileObj,
                                                   boolean useTimeFlag)
Creates a new 'File' object that references an unused file name. The given template string is used to generate the file name, with a numeric value inserted before the extension (if present) to make it unique (if necessary).

Parameters:
tmplStr - the template to use when generating the file name, or null for none.
parentDirFileObj - the File object for the parent directory to use, or null to use the current user directory.
useTimeFlag - if true then the current time value (in ms since 1/1/1970) is used in the file name, if false then an incrementing value is used, starting at 1 (if the template string name itself is already in use).
Returns:
A new 'File' object, or null if an unused file name object could not be created.

transferStream

public static void transferStream(java.io.InputStream inputStreamObj,
                                  java.io.OutputStream outputStreamObj)
                           throws java.io.IOException
Transfers data from the input stream to the output stream.

Parameters:
inputStreamObj - the input stream.
outputStreamObj - the output stream.
Throws:
java.io.IOException - if an I/O error occurs.

transferStream

public static void transferStream(java.io.InputStream inputStreamObj,
                                  java.io.OutputStream outputStreamObj,
                                  long maxBytesLimit)
                           throws java.io.IOException
Transfers data from the input stream to the output stream.

Parameters:
inputStreamObj - the input stream.
outputStreamObj - the output stream.
maxBytesLimit - the maximum number of bytes to be transferred, or 0 for no limit.
Throws:
java.io.IOException - if an I/O error occurs.

transferStream

public static void transferStream(java.io.InputStream inputStreamObj,
                                  java.io.OutputStream outputStreamObj,
                                  CallBackCompletion callBack)
                           throws java.io.IOException
Transfers data from the input stream to the output stream.

Parameters:
inputStreamObj - the input stream.
outputStreamObj - the output stream.
callBack - callBack method or null to execute on the current thread.
Throws:
java.io.IOException - if an I/O error occurs.

copyFile

public static void copyFile(java.lang.String sourceFileNameStr,
                            java.lang.String destFileNameStr)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copies one file to another. The last-modified-time value for the destination file is not set to that of the source file.

Parameters:
sourceFileNameStr - name of source file.
destFileNameStr - name of destination file.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

copyFile

public static void copyFile(java.io.File sourceFileObj,
                            java.io.File destFileObj)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copies one file to another. The last-modified-time value for the destination file is not set to that of the source file.

Parameters:
sourceFileObj - source file object.
destFileObj - destination file object.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

copyFile

public static void copyFile(java.lang.String sourceFileNameStr,
                            java.lang.String destFileNameStr,
                            boolean copyLastModFlag)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copies one file to another.

Parameters:
sourceFileNameStr - name of source file.
destFileNameStr - name of destination file.
copyLastModFlag - true to set the last-modified-time value for the destination file to that of the source file.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

copyFile

public static void copyFile(java.io.File sourceFileObj,
                            java.io.File destFileObj,
                            boolean copyLastModFlag)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copies one file to another.

Parameters:
sourceFileObj - source file object.
destFileObj - destination file object.
copyLastModFlag - true to set the last-modified-time value for the destination file to that of the source file.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

moveFile

public static void moveFile(java.io.File sourceFileObj,
                            java.io.File destDirFileObj)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Moves the specified file to a new location (even if the new location is on a different filesystem). If the file is moved to a different filesystem then the last-modified-time value is copied from the original file. The 'destDirFileObj' object may specify the destination directory or the destination path and filename. The destination directory must already exist.

Parameters:
sourceFileObj - source file object.
destDirFileObj - destination directory or file object.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

moveFile

public static void moveFile(java.lang.String sourceFileNameStr,
                            java.lang.String destDirNameStr)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Moves the specified file to a new location (even if the new location is on a different filesystem). If the file is moved to a different filesystem then the last-modified-time value is copied from the original file. The 'destDirFileObj' object may specify the destination directory or the destination path and filename. The destination directory must already exist.

Parameters:
sourceFileNameStr - name of source file.
destDirNameStr - name of destination directory or file.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

copyLastModifiedTime

public static void copyLastModifiedTime(java.io.File sourceFileObj,
                                        java.io.File destFileObj)
Copies the last-modified-time value from one file to another.

Parameters:
sourceFileObj - source file object.
destFileObj - destination file object.
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the named file.

readFileTail

public static void readFileTail(java.lang.String sourceFileNameStr,
                                long numberOfLines,
                                java.io.OutputStream outputStreamObj)
                         throws java.io.FileNotFoundException,
                                java.io.IOException
Reads given number of lines from tail end of given file.

Parameters:
sourceFileNameStr - name of source file.
numberOfLines - number of lines to read.
outputStreamObj - output stream to send read data into.
Throws:
java.io.FileNotFoundException - if the source file is not found.
java.io.IOException - if an I/O error occurs.

closeStream

public static boolean closeStream(java.io.InputStream inputStreamObj)
Closes the given input stream.

Parameters:
inputStreamObj - the input stream.
Returns:
true if the stream was closed successfully false otherwise.

closeStream

public static boolean closeStream(java.io.OutputStream outputStreamObj)
Closes the given output stream.

Parameters:
outputStreamObj - the output stream.
Returns:
true if the stream was closed successfully false otherwise.