public class FileSystem
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String[] |
CHARS_INVALID
The configured set of the file system invalid characters per the
"FileSystem.Invalid.Characters" properties key.
|
static java.lang.String[] |
CHARS_REPLACE
The configured set of the file system replacement characters per the
"FileSystem.Replace.Characters" properties key.
|
static int |
FILE_BUFFER
The size of the buffer used during file reads and writes.
|
static java.lang.String |
FILE_ENCODING
The default file character encoding.
|
private static long |
serialVersionUID
The class' serialization version id.
|
| Constructor and Description |
|---|
FileSystem() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
copyFile(java.io.File srcfile,
java.io.File dstfile)
Copies the given source file to the given destination file.
|
static boolean |
deleteFile(java.io.File file)
Deletes the given file from the file system.
|
static boolean |
deleteFile(java.io.File file,
boolean recurse)
Deletes the given file object (may be a folder).
|
static boolean |
deleteFile(java.lang.String path)
Deletes the file represented by the given path from the file system.
|
static void |
dumpProperties(java.util.Properties props,
java.lang.String filename)
Dumps a sorted list of a property object's keys and values to a specified
file in the application's temp folder.
|
static java.lang.String |
fixFileSeparator(java.lang.String s)
Returns a string containing file separators that are valid for the local
file system.
|
static java.lang.String |
fixURLSeparator(java.lang.String s)
Returns a string containing path separators that are valid for a URL path.
|
static java.lang.StringBuilder |
getFileContent(java.io.File file)
Returns a file's content as a
StringBuilder. |
static java.lang.StringBuilder |
getFileContent(java.io.File file,
boolean bodyonly)
Returns a file's content as a
StringBuilder. |
static java.lang.StringBuilder |
getFileContent(java.io.File file,
boolean bodyonly,
boolean linebreaks)
Returns a file's content as a
StringBuilder. |
static java.lang.StringBuilder |
getFileContent(java.lang.String path)
Returns a file's content as a
StringBuilder. |
static java.lang.StringBuilder |
getFileContent(java.lang.String path,
boolean bodyonly)
Returns a file's content as a
StringBuilder. |
static java.lang.StringBuilder |
getFileContent(java.lang.String path,
boolean bodyonly,
boolean linebreaks)
Returns a file's content as a
StringBuilder. |
static java.lang.String |
getFileExtension(java.io.File file)
Returns a file's file extension.
|
static java.lang.String |
getFileExtension(java.lang.String file)
Returns a file's file extension.
|
static java.util.ArrayList<java.lang.String> |
getFolderFileNames(java.io.File folder)
Returns a sorted list of the file names in a folder.
|
static java.util.ArrayList<java.lang.String> |
getFolderFileNames(java.lang.String path)
Returns a sorted list of the file names in a folder.
|
static java.io.File |
getTempFile()
Returns a
File object for a randomly named file. |
static java.lang.String |
getValidFileName(java.lang.String name)
Returns a file name that is valid for the file system based on the invalid
and replacement characters defined in the properties.
|
static void |
save(java.io.PrintWriter prnt,
java.lang.String key,
java.lang.String val)
Stores this key, value pair to the specified output stream.
|
static boolean |
writeFileContent(java.io.File file,
java.lang.String content)
Writes a file's content to the file system.
|
static boolean |
writeFileContent(java.io.File file,
java.lang.String content,
boolean append)
Writes a file's content to the file system and optionally appends the
content to any existing content.
|
static boolean |
writeFileContent(java.lang.String path,
java.lang.String content)
Writes a file's content to the file system.
|
static boolean |
writeFileContent(java.lang.String path,
java.lang.String content,
boolean append)
Writes a file's content to the file system and optionally appends the
content to any existing content.
|
static boolean |
writeFileForURL(java.net.URL url,
java.io.File file,
boolean overwrite)
Invokes the given URL and writes the URL's response to the given file.
|
private static final long serialVersionUID
public static final java.lang.String FILE_ENCODING
public static final int FILE_BUFFER
public static final java.lang.String[] CHARS_INVALID
public static final java.lang.String[] CHARS_REPLACE
public static boolean copyFile(java.io.File srcfile,
java.io.File dstfile)
srcfile - (File) A File object that points to the
location of the file to be copied.dstfile - (File) A File object that points to the
location where the file is to be copied.true if the copy is successful;
otherwise false.public static boolean deleteFile(java.io.File file)
file - (File) The object for the file that is to be deleted.true if the file successfully deletes,
otherwise false.public static boolean deleteFile(java.io.File file,
boolean recurse)
file - (File) A File object for the file or folder
to be deleted.recurse - (boolean) true if subfolders are to be
recursed, otherwise false.true if the delete is successful;
otherwise false.public static boolean deleteFile(java.lang.String path)
path - (String) The full path to the file that is to be deleted.true if the file successfully deletes,
otherwise false.public static void dumpProperties(java.util.Properties props,
java.lang.String filename)
props - (Properties) The properties to dump.filename - (String) The name of the dump file.public static java.lang.String fixFileSeparator(java.lang.String s)
s - (String) A string containing a file path.public static java.lang.String fixURLSeparator(java.lang.String s)
s - (String) A string containing a URL path.public static java.lang.StringBuilder getFileContent(java.io.File file)
StringBuilder. Assumes the
entire file content is to be returned (no HTML body extraction) and with
line breaks.file - (File) The object for the file that is to be read.public static java.lang.StringBuilder getFileContent(java.io.File file,
boolean bodyonly)
StringBuilder. Assumes the
file content is to be returned with line breaks.file - (File) The object for the file that is to be read.bodyonly - (boolean) true if the source file is an
html file and only the body portion of the html file is to be
included in the results, otherwise false. This
parameter is ignored for all non-html file types.public static java.lang.StringBuilder getFileContent(java.io.File file,
boolean bodyonly,
boolean linebreaks)
StringBuilder.file - (File) The object for the file that is to be read.bodyonly - (boolean) true if the source file is an
html file and only the body portion of the html file is to be
included in the results, otherwise false. This
parameter is ignored for all non-html file types.linebreaks - (boolean) true if the resulting string
is to contain embedded carriage return / line feeds, otherwise
false.public static java.lang.StringBuilder getFileContent(java.lang.String path)
StringBuilder. Assumes the
entire file content is to be returned (no HTML body extraction) and with
line breaks.path - (String) The full path to the file that is to be read.public static java.lang.StringBuilder getFileContent(java.lang.String path,
boolean bodyonly)
StringBuilder. Assumes the
file content is to be returned with line breaks.path - (String) The full path to the file that is to be read.bodyonly - (boolean) true if the source file is an
html file and only the body portion of the html file is to be
included in the results, otherwise false. This
parameter is ignored for all non-html file types.public static java.lang.StringBuilder getFileContent(java.lang.String path,
boolean bodyonly,
boolean linebreaks)
StringBuilder.path - (String) The full path to the file that is to be read.bodyonly - (boolean) true if the source file is an
html file and only the body portion of the html file is to be
included in the results, otherwise false. This
parameter is ignored for all non-html file types.linebreaks - (boolean) true if the resulting string
is to contain embedded carriage return / line feeds, otherwise
false.public static java.lang.String getFileExtension(java.io.File file)
file - (File) A file object.public static java.lang.String getFileExtension(java.lang.String file)
file - (String) A file name.public static java.util.ArrayList<java.lang.String> getFolderFileNames(java.io.File folder)
folder - (File) The object for the desired folder.public static java.util.ArrayList<java.lang.String> getFolderFileNames(java.lang.String path)
path - (String) The full path to the desired folder.public static java.io.File getTempFile()
File object for a randomly named file. The path
of the file points to the configured temporary file folder.null
if a random name could not be generated.public static java.lang.String getValidFileName(java.lang.String name)
name - (String) A file name (not including file path) that is to
be analyzed and, if necessary, fixed so that it is a valid file
name for the file system.public static void save(java.io.PrintWriter prnt,
java.lang.String key,
java.lang.String val)
key - (String) The name of the data to be saved.val - (String) The value of the data to be saved.prnt - (PrintWriter) An output writer.public static boolean writeFileContent(java.io.File file,
java.lang.String content)
file - (File) The file where the content is to be written.content - (String) The content to write.true if the file writing is successful;
otherwise false.public static boolean writeFileContent(java.io.File file,
java.lang.String content,
boolean append)
file - (File) The file where the content is to be written.content - (String) The content to write.append - (boolean) true to append to the file's
existing content, otherwise false to overwrite
the file's existing content.true if the file writing is successful;
otherwise false.public static boolean writeFileContent(java.lang.String path,
java.lang.String content)
path - (String) The path to the file where the content is to be
written.content - (String) The content to write.true if the file writing is successful;
otherwise false.public static boolean writeFileContent(java.lang.String path,
java.lang.String content,
boolean append)
path - (String) The path to the file where the content is to be
written.content - (String) The content to write.append - (boolean) true to append to the file's
existing content, otherwise false to overwrite
the file's existing content.true if the file writing is successful;
otherwise false.public static boolean writeFileForURL(java.net.URL url,
java.io.File file,
boolean overwrite)
url - (URL) The URL to invoke.file - (File) The file where the invoked URL's response is to be
written.overwrite - (boolean) true if an existing file with
the same name should be overwritten; otherwise false.true if the file writing is successful;
otherwise false.