|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bristle.javalib.io.FileUtil
public class FileUtil
This class contains utility routines for manipulating files.
Usage:
- The typical scenario for using this class is:
String s = FileUtil.getTextFileContents("/dir/filename.txt");
- See the source code of the inner Tester class for more examples.
Assumptions:
Effects:
- None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
$Log$
| Nested Class Summary | |
|---|---|
static class |
FileUtil.ExtensionFilenameFilter
This class implements FilenameFilter, filtering based on one or more filename extensions. |
static class |
FileUtil.FileDeleteException
Thrown when an attempt to delete a file fails. |
static class |
FileUtil.FileRenameException
Thrown when an attempt to rename a file fails. |
static class |
FileUtil.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
static class |
FileUtil.TooManyBytesException
Thrown when an attempt is made to operate on too many bytes of data. |
| Field Summary | |
|---|---|
static long |
lngNO_MAX_BYTES
|
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static void |
appendToFile(String strFilename,
String strString)
Append the specified string to the specified file, opening and closing the file to do so. |
static long |
copyBinaryFileToStream(String strFilenameIn,
OutputStream streamOut,
long lngMaxBytes)
Copy the binary contents of the file with the specified name to the specified OutputStream, up to the specified number of bytes, returning the count of bytes written. |
static void |
copyBinaryFileToWriter(String strFilename,
Writer writer)
Copy the contents of the specified binary file to the specified Writer. |
static long |
copyBinaryFileToWriter(String strFilenameIn,
Writer writerOut,
long lngMaxBytes)
Copy the binary contents of the file with the specified name to the specified Writer, up to the specified number of bytes, returning the count of bytes written. |
static long |
copyBinaryStreamToFile(InputStream streamIn,
String strFilenameOut,
long lngMaxBytes)
Copy the binary contents of the specified InputStream to the file with the specified name, up to the specified number of bytes, returning the count of bytes written. |
static long |
copyBinaryStreamToStream(InputStream streamIn,
OutputStream streamOut,
long lngMaxBytes)
Copy the binary contents of the specified InputStream to the specified OutputStream, up to the specified number of bytes, returning the count of bytes written. |
static long |
copyBinaryStreamToWriter(InputStream streamIn,
Writer writerOut,
long lngMaxBytes)
Copy the binary contents of the specified InputStream to the specified Writer, up to the specified number of bytes, returning the count of bytes written. |
static void |
delete(String strFileName)
Delete the file with the specified name. |
static boolean |
deleteDirectoryTree(String strDirectoryName)
Delete the directory tree with the specified name. |
static boolean |
deleteIfExists(String strFileName)
Delete the file with the specified name, if it exists, returning true if it existed and was successfully deleted. |
static String |
getFileNameWithoutPath(String strFileName)
Return the simple name, including extension, but not path, of the specified filename. |
static String[] |
getSortedNames(File directory)
Returns a sorted array of Strings naming the files and directories in the specified directory. |
static String |
getTextFileContents(InputStream istream)
Returns the contents of the requested text file as a string. |
static String |
getTextFileContents(Reader reader)
Returns the contents of the requested text file as a string. |
static String |
getTextFileContents(String strFilename)
Returns the contents of the requested text file as a string. |
static String |
getTextFileContentsOrEmpty(InputStream istream)
Returns the contents of the requested text file as a string, or the empty String ("") if no such file exists or any other error occurs. |
static String |
getTextFileContentsOrEmpty(Reader reader)
Returns the contents of the requested text file as a string, or the empty String ("") if no such file exists or any other error occurs. |
static String |
getTextFileContentsOrEmpty(String strFilename)
Returns the contents of the requested text file as a string, or the empty String ("") if no such file exists or any other error occurs. |
static String |
getTextFileContentsOrNull(InputStream istream)
Returns the contents of the requested text file as a string, or null if no such file exists or any other error occurs. |
static String |
getTextFileContentsOrNull(Reader reader)
Returns the contents of the requested text file as a string, or null if no such file exists or any other error occurs. |
static String |
getTextFileContentsOrNull(String strFilename)
Returns the contents of the requested text file as a string, or null if no such file exists or any other error occurs. |
static void |
rename(String strOldFileName,
String strNewFileName)
Rename the file with the specified old name to the specified new name. |
static long |
skipEntireStreamReturningCount(InputStream streamIn)
Skip past all bytes in the specified InputStream, returning the count of bytes found. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long lngNO_MAX_BYTES
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static String getTextFileContents(Reader reader)
throws IOException
reader - Reader of the file to get.
IOException - When an error occurs reading the file.public static String getTextFileContentsOrNull(Reader reader)
reader - Reader of the file to get.
public static String getTextFileContentsOrEmpty(Reader reader)
reader - Reader of the file to get.
public static String getTextFileContents(InputStream istream)
throws IOException
istream - InputStream of the file to get.
IOException - When an error occurs reading the file.public static String getTextFileContentsOrNull(InputStream istream)
istream - InputStream of the file to get.
public static String getTextFileContentsOrEmpty(InputStream istream)
istream - InputStream of the file to get.
public static String getTextFileContents(String strFilename)
throws FileNotFoundException,
IOException
strFilename - String name of the file to get.
FileNotFoundException - When the specified file is not found.
IOException - When an error occurs reading the file.public static String getTextFileContentsOrNull(String strFilename)
strFilename - String name of the file to get.
public static String getTextFileContentsOrEmpty(String strFilename)
strFilename - String name of the file to get.
public static void copyBinaryFileToWriter(String strFilename,
Writer writer)
throws FileNotFoundException,
IOException
strFilename - Name of the file to copy.writer - Writer to write to.
FileNotFoundException - When binary file not found.
IOException - When an I/O error occurs reading the file or
writing it to the Writer.
public static long copyBinaryStreamToStream(InputStream streamIn,
OutputStream streamOut,
long lngMaxBytes)
throws FileUtil.TooManyBytesException,
IOException
streamIn - InputStream to read fromstreamOut - OutputStream to write tolngMaxBytes - Max number of bytes to copy, or lngNO_MAX_BYTES
for unlimited
FileUtil.TooManyBytesException - When streamIn contains more than intMaxBytes,
resulting in a partially copied binary stream.
IOException - When an I/O error occurs reading or writing a
stream.
public static long copyBinaryStreamToWriter(InputStream streamIn,
Writer writerOut,
long lngMaxBytes)
throws FileUtil.TooManyBytesException,
IOException
streamIn - InputStream to read fromwriterOut - Writer to write tolngMaxBytes - Max number of bytes to copy, or lngNO_MAX_BYTES
for unlimited
FileUtil.TooManyBytesException - When streamIn contains more than intMaxBytes,
resulting in a partially copied binary stream.
IOException - When an I/O error occurs reading or writing a
stream or Writer.
public static long copyBinaryStreamToFile(InputStream streamIn,
String strFilenameOut,
long lngMaxBytes)
throws FileUtil.TooManyBytesException,
FileNotFoundException,
IOException
streamIn - InputStream to read fromstrFilenameOut - String name of the file to write tolngMaxBytes - Max number of bytes to copy, or lngNO_MAX_BYTES
for unlimited
FileUtil.TooManyBytesException - When streamIn contains more than intMaxBytes,
resulting in a partially copied binary stream.
The file is still closed properly.
FileNotFoundException - When the output file cannot be created or written.
IOException - When an I/O error occurs reading or writing a
stream or file.
public static long copyBinaryFileToStream(String strFilenameIn,
OutputStream streamOut,
long lngMaxBytes)
throws FileUtil.TooManyBytesException,
FileNotFoundException,
IOException
strFilenameIn - String name of the file to read fromstreamOut - OutputStream to write tolngMaxBytes - Max number of bytes to copy, or lngNO_MAX_BYTES
for unlimited
FileUtil.TooManyBytesException - When the input file contains more than intMaxBytes,
resulting in a partially copied binary stream.
The input file is still closed properly, and the
output stream is flushed.
FileNotFoundException - When the input file cannot be found or read.
IOException - When an I/O error occurs reading or writing a
stream or file.
public static long copyBinaryFileToWriter(String strFilenameIn,
Writer writerOut,
long lngMaxBytes)
throws FileUtil.TooManyBytesException,
FileNotFoundException,
IOException
strFilenameIn - String name of the file to read fromwriterOut - Writer to write tolngMaxBytes - Max number of bytes to copy, or lngNO_MAX_BYTES
for unlimited
FileUtil.TooManyBytesException - When the input file contains more than intMaxBytes,
resulting in a partially copied binary stream.
The input file is still closed properly, and the
Writer is flushed.
FileNotFoundException - When the input file cannot be found or read.
IOException - When an I/O error occurs reading or writing a
Writer or file.
public static long skipEntireStreamReturningCount(InputStream streamIn)
throws IOException
streamIn - InputStream to read from
IOException - When an I/O error occurs reading or writing a
stream.
public static void appendToFile(String strFilename,
String strString)
throws IOException
strFilename - String name of the file to get.strString - String to append to the file.
IOException - When an error occurs writing the file.public static String[] getSortedNames(File directory)
directory - The directory to search
public static void rename(String strOldFileName,
String strNewFileName)
throws FileUtil.FileRenameException
strOldFileName - Old name of the file.strNewFileName - New name of the file.
FileUtil.FileRenameException - When unable to rename the file.public static boolean deleteIfExists(String strFileName)
strFileName - Name of the file to delete.
public static void delete(String strFileName)
throws FileUtil.FileDeleteException
strFileName - Name of the file to delete.
FileUtil.FileDeleteException - When unable to delete the file.public static boolean deleteDirectoryTree(String strDirectoryName)
strDirectoryName - String name of the directory tree to delete.
public static String getFileNameWithoutPath(String strFileName)
strFileName - File name
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||