|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opengts.util.FileTools
public class FileTools
File handling tools
| 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.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 |
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.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.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.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 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 |
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 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.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 |
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 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 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 |
| Constructor Detail |
|---|
public FileTools()
| Method Detail |
|---|
public static java.net.URL toURL(java.io.File file)
throws java.net.MalformedURLException
file - The file specification
java.net.MalformedURLException - If a protocol handler for the URL could not be found,
or if some other error occurred while constructing the URL
public static java.io.File toFile(java.net.URL url)
throws java.net.URISyntaxException
url - The URL specification
URIsyntaxException - if the protocol was not 'file' or URL could
otherwise not be converted to a file
java.net.URISyntaxException
public static java.io.File toFile(java.io.File base,
java.lang.String[] path)
base - The base file specificationpath - The file path directories (last element may be a file name)
public static java.io.File toFile(java.lang.String[] path)
path - The file path directories (last element may be a file name)
public static java.io.File getRealFile(java.io.File file)
file - The file for which the real file will be returned
public static java.io.File getRealFile(java.io.File dir,
java.lang.String file)
file - The file for which the real file will be returned
public static int copyFile(java.net.URL inpURL,
java.io.File outFile)
throws java.io.IOException
inpURL - The URL from which data will be readoutFile - The File to whish data will be written
java.io.IOException
public static int copyFile(java.net.URL inpURL,
java.io.File outFile,
boolean progress)
throws java.io.IOException
inpURL - The URL from which data will be readoutFile - The File to whish data will be writtenprogress - Show progress
java.io.IOException
public static int copyFile(java.net.URL inpURL,
java.io.OutputStream out)
throws java.io.IOException
inpURL - The URL from which data will be readout - The OutputStream to whish data will be written
java.io.IOException
public static int copyFile(java.net.URL inpURL,
java.io.OutputStream out,
boolean progress)
throws java.io.IOException
inpURL - The URL from which data will be readout - The OutputStream to whish data will be writtenprogress - Show progress
java.io.IOException
public static int copyStreams(java.io.InputStream input,
java.io.OutputStream output)
throws java.io.IOException
input - The InputStreamoutput - The OutputStream
java.io.IOException - if an I/O error occurs
public static int copyStreams(java.io.InputStream input,
java.io.OutputStream output,
int maxLen)
throws java.io.IOException
input - The InputStreamoutput - The OutputStreammaxLen - The maximum number of bytes to copy
java.io.IOException - if an I/O error occurs
public static int copyStreams(java.io.InputStream input,
java.io.OutputStream output,
byte[] pattern,
int maxLen)
throws java.io.IOException
input - The InputStreamoutput - The OutputStreampattern - The pattern to match, to terminate the copymaxLen - The maximum number of bytes to copy
java.io.IOException - if an I/O error occurs
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
input - The InputStreamoutput - The OutputStreampattern - The pattern to match, to terminate the copymaxLen - The maximum number of bytes to copyprogress - Show progress (to stdout)
java.io.EOFException - if the end of stream is reached before the pattern is found
java.io.IOException - if an I/O error occurspublic static java.io.InputStream openInputFile(java.lang.String file)
file - The path of the file to open
public static java.io.InputStream openInputFile(java.io.File file)
file - The file to open
public static void closeStream(java.io.InputStream in)
in - The InputStream to closepublic static void closeStream(java.io.OutputStream out)
out - The OutputStream to close
public static byte[] readStream(java.io.InputStream input)
throws java.io.IOException
input - The InputStream
java.io.IOException - if an I/O error occurs
public static void writeStream(java.io.OutputStream output,
java.lang.String dataStr)
throws java.io.IOException
output - The OutputStreamdataStr - The String to write to the OutputStream
java.io.IOException - if an I/O error occurspublic static byte[] readFile(java.lang.String file)
file - The file path from which the byte array is read
public static byte[] readFile(java.io.File file)
file - The file from which the byte array is read
public static java.lang.String readLine(java.io.InputStream input)
throws java.io.IOException
input - The InputStream
java.io.EOFException - if the end of the input stream is encountered
java.io.IOException - if an I/O error occurs
public static java.lang.String readLineNL(java.io.InputStream input)
throws java.io.IOException
input - The InputStream
java.io.EOFException - if the end of the input stream is encountered
java.io.IOException - if an I/O error occurs
public static java.lang.String readLine_stdin()
throws java.io.IOException
java.io.IOException - if an I/O error occurs
public static java.lang.String readString_stdin(java.lang.String msg,
java.lang.String dft)
throws java.io.IOException
msg - The message to printdft - The default String returned, if no text was entered
java.io.IOException - if an I/O error occurs
public static boolean readBoolean_stdin(java.lang.String msg,
boolean dft)
throws java.io.IOException
msg - The message to printdft - The default boolean value returned, if no value was entered
java.io.IOException - if an I/O error occurs
public static long readLong_stdin(java.lang.String msg,
long dft)
throws java.io.IOException
msg - The message to printdft - The default long value returned, if no value was entered
java.io.IOException - if an I/O error occurs
public static double readDouble_stdin(java.lang.String msg,
double dft)
throws java.io.IOException
msg - The message to printdft - The default double value returned, if no value was entered
java.io.IOException - if an I/O error occurs
public static boolean writeFile(byte[] data,
java.io.File file)
throws java.io.IOException
data - The byte array to write to the filefile - The file to which the byte array is written
java.io.IOException - if an I/O error occurs
public static boolean writeFile(byte[] data,
java.io.File file,
boolean append)
throws java.io.IOException
data - The byte array to write to the filefile - The file to which the byte array is writtenappend - True to append the bytes to the file, false to overwrite.
java.io.IOException - if an error occurred.
public static boolean writeEscapedUnicode(java.lang.String dataStr,
java.io.File file)
throws java.io.IOException
dataStr - The String to write to the filefile - The file to which the byte array is written
java.io.IOException - if an error occurred.
public static java.util.List<java.lang.String> findPatternInFile(java.io.File file,
java.lang.String pattern,
boolean ignoreCase)
file - The target filepattern - The pattern StringignoreCase - True to ignore case
public static java.lang.String getExtension(java.lang.String filePath)
filePath - The file name
public static java.lang.String getExtension(java.io.File file)
file - The file
public static boolean hasExtension(java.lang.String filePath,
java.lang.String[] extn)
filePath - The file path/nameextn - An array of file extensions
public static boolean hasExtension(java.io.File file,
java.lang.String[] extn)
file - The fileextn - An array of file extensions
public static java.lang.String removeExtension(java.lang.String filePath)
filePath - The file path from which the extension will be removed
public static java.lang.String removeExtension(java.io.File file)
file - The file from which the extension will be removed
public static boolean isFileSeparatorChar(char ch)
ch - The character to test
public static boolean hasFileSeparator(java.lang.String fn)
fn - The String file path
public static java.io.File resolveCommand(java.lang.String cmd)
cmd - The command name. If the specified command is an absolute path,
then the specified command path will me returned as-is.
public static boolean isFile(java.lang.String f)
f - The item to check
public static boolean isFile(java.io.File f)
f - The item to check
public static boolean isFile(java.io.File f,
java.lang.String ext)
f - The item to checkext - The required file extension
public static boolean isDirectory(java.lang.String d)
d - The item to check
public static boolean isDirectory(java.io.File d)
d - The item to check
public static boolean canExecute(java.io.File f)
throws java.lang.UnsupportedOperationException
f - The file to test
java.lang.UnsupportedOperationException - if the JRE does not support the "canExecute" method.
public static boolean canRead(java.io.File f)
throws java.lang.UnsupportedOperationException
f - The file to test
java.lang.UnsupportedOperationException - if the JRE does not support the "canRead" method.
public static boolean canWrite(java.io.File f)
throws java.lang.UnsupportedOperationException
f - The file to test
java.lang.UnsupportedOperationException - if the JRE does not support the "canWrite" method.
public static java.io.File findFile(java.io.File parentDir,
java.lang.String[] fileNames)
parentDir - The parent directoryfileNames - The list of files to search for
public static java.io.File[] getFilesystemRoots()
public static java.io.File[] getDirectories(java.io.File dir)
dir - The parent directory
public static java.io.File[] getFiles(java.io.File dir)
dir - The parent directory
public static java.io.File[] getFiles(java.io.File dir,
java.util.Set<java.lang.String> extnSet,
boolean recursiveDecent)
dir - The parent directoryextnSet - The set of extensions to look forrecursiveDecent - True to descend all directories looking for matching files
public static java.io.File[] getFiles(java.io.File dir,
java.lang.String[] extnList,
boolean recursiveDecent)
dir - The parent directoryextnList - The list of extensions to look forrecursiveDecent - True to descend all directories looking for matching files
public static java.io.File[] getFiles(java.io.File dir,
java.util.regex.Pattern regex,
boolean recursiveDecent)
dir - The parent directoryregex - A regular expression (Pattern) that the file names must matchrecursiveDecent - True to descend all directories looking for matching files
public static java.io.File[] getFiles(java.io.File dir,
java.lang.String fileGlob,
boolean recursiveDecent)
dir - The parent directoryfileGlob - A file glob expression that the file names must matchrecursiveDecent - True to descend all directories looking for matching files
public static boolean traverseAllFiles(java.io.File dir,
java.io.FileFilter filter)
dir - The parent directoryfilter - The callback filter
public static void main(java.lang.String[] argv)
argv - The Command-line args
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||