|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jppf.utils.FileUtils
public final class FileUtils
This class provides a set of utility methods for reading, writing and manipulating files.
| Method Summary | |
|---|---|
static void |
closeInputStream(InputStream is,
org.slf4j.Logger log)
Attempt to close the specified input stream and log any eventual error. |
static void |
copyStream(InputStream is,
OutputStream os)
Copy the data read from the specified input stream to the specified output stream. |
static boolean |
deletePath(File path)
Delete the specified path, recursively if this is a directory. |
static byte[] |
getFileAsByte(File file)
Get the content of a file as an array of bytes. |
static byte[] |
getFileAsByte(String path)
Get the content of a file as an array of bytes. |
static String |
getFileExtension(File file)
Get the extension of a file. |
static String |
getFileExtension(String filePath)
Get the extension of a file. |
static InputStream |
getFileInputStream(String path)
Get an input stream given a file path. |
static String |
getFileName(String filePath)
Get the name of a file from its full path. |
static List<String> |
getFilePathList(String fileListPath)
Get a list of files whose paths are found in a text file. |
static Reader |
getFileReader(String path)
Load a file from the specified path. |
static byte[] |
getInputStreamAsByte(InputStream is)
Get the content of an input stream as an array of bytes. |
static String |
getParentFolder(String filePath)
Get the parent folder of a file or directory from its full path. |
static void |
main(String... args)
Entry point for the splitTextFile() method. |
static String |
readTextFile(File file)
Read the content of a specified file into a string. |
static String |
readTextFile(Reader aReader)
Read the content of a specified reader into a string. |
static String |
readTextFile(String filename)
Read the content of a specified file into a string. |
static void |
splitTextFile(String file,
int splitSize)
Split a file into multiple files whose size is as close as possible to the specified split size. |
static List<String> |
textFileAsLines(Reader aReader)
Read the content of a specified reader into a string. |
static File[] |
toFiles(File dir,
String... names)
Convert a set of file names into a set of File objects. |
static URL[] |
toURLs(File... files)
Convert a set of file paths into a set of URLs. |
static void |
writeBytesToFile(byte[] data,
File path)
Write a byte array into an file. |
static void |
writeBytesToFile(byte[] data,
String path)
Write a byte array into an file. |
static void |
writeBytesToStream(byte[] data,
OutputStream os)
Write a byte array into an output stream. |
static void |
writeTextFile(File file,
String content)
Write the content of a string into a specified file. |
static void |
writeTextFile(String filename,
String content)
Write the content of a string into a specified file. |
static void |
writeTextFile(Writer dest,
String content)
Write the content of a string into a specified file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String readTextFile(Reader aReader)
throws IOException
aReader - the reader to read the vcontent from.
IOException - if the file can't be found or read.
public static List<String> textFileAsLines(Reader aReader)
throws IOException
aReader - the reader to read the vcontent from.
IOException - if the file can't be found or read.
public static String readTextFile(File file)
throws IOException
file - the file to read.
IOException - if the file can't be found or read.
public static String readTextFile(String filename)
throws IOException
filename - the location of the file to read.
IOException - if the file can't be found or read.
public static void writeTextFile(String filename,
String content)
throws IOException
filename - the location of the file to write to.content - the content to wwrite into the file.
IOException - if the file can't be found or read.
public static void writeTextFile(File file,
String content)
throws IOException
file - the location of the file to write to.content - the content to wwrite into the file.
IOException - if the file can't be found or read.
public static void writeTextFile(Writer dest,
String content)
throws IOException
dest - the file to write to.content - the content to wwrite into the file.
IOException - if the file can't be found or read.
public static InputStream getFileInputStream(String path)
throws IOException
path - the path to the file to lookup.
InputStream instance, or null if the file could not be found.
IOException - if an IO error occurs while looking up the file.
public static Reader getFileReader(String path)
throws IOException
path - the path to the file to load.
Reader instance, or null if the schema file could not be found.
IOException - if an IO error occurs while looking up the file.
public static List<String> getFilePathList(String fileListPath)
throws IOException
fileListPath - the path to the file that holds the list of documents to validate.
IOException - if an error occurs while looking up or reading the file.public static String getFileExtension(String filePath)
filePath - the file from which to get the extension.
public static String getFileExtension(File file)
file - the file from which to get the extension.
public static String getFileName(String filePath)
filePath - the file from which to get the file name.
public static String getParentFolder(String filePath)
filePath - the path from which to get the parent path.
public static void splitTextFile(String file,
int splitSize)
throws IOException
file - the etxt file to split.splitSize - the maximum number of lines of each resulting file.
IOException - if an IO error occurs.public static void main(String... args)
args - contains the arguments for the splitTextFile() method.
public static byte[] getFileAsByte(String path)
throws IOException
path - the path of the file to read from as a string.
IOException - if an IO error occurs.
public static byte[] getFileAsByte(File file)
throws IOException
file - the abstract path of the file to read from.
IOException - if an IO error occurs.
public static byte[] getInputStreamAsByte(InputStream is)
throws IOException
is - the input stream to read from.
IOException - if an IO error occurs.
public static void copyStream(InputStream is,
OutputStream os)
throws IOException
is - the input stream to read from.os - the output stream to write to.
IOException - if an I/O error occurs.
public static File[] toFiles(File dir,
String... names)
File objects.
dir - the directory in which the files are locatednames - the name part of each file (not the full path)
File objects.public static URL[] toURLs(File... files)
files - the files whose path is to be converted to a URL.
URL objects.
public static void writeBytesToStream(byte[] data,
OutputStream os)
throws IOException
data - the byte array to write.os - the output stream to write to.
IOException - if an I/O error occurs.
public static void writeBytesToFile(byte[] data,
String path)
throws IOException
data - the byte array to write.path - the path to the file to write to.
IOException - if an I/O error occurs.
public static void writeBytesToFile(byte[] data,
File path)
throws IOException
data - the byte array to write.path - the path to the file to write to.
IOException - if an I/O error occurs.
public static void closeInputStream(InputStream is,
org.slf4j.Logger log)
is - the input stream to close.log - the logger to use; if null no logging occurs.public static boolean deletePath(File path)
path - the path to delete.
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||