|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dbforms.util.external.FileUtil
public class FileUtil
DOCUMENT ME!
Field Summary | |
---|---|
static int |
ONE_GB
The number of bytes in a gigabyte. |
static int |
ONE_KB
The number of bytes in a kilobyte. |
static int |
ONE_MB
The number of bytes in a megabyte. |
Method Summary | |
---|---|
static String |
basename(String filename)
Returns the filename portion of a file specification string. |
static String |
basename(String filename,
String suffix)
Returns the filename portion of a file specification string. |
static String |
byteCountToDisplaySize(int size)
Returns a human-readable version of the file size (original is in bytes). |
static String |
catPath(String lookupPath,
String path)
Will concatenate 2 paths. |
static void |
cleanDirectory(File directory)
Clean a directory without deleting it. |
static void |
cleanDirectory(String directory)
Clean a directory without deleting it. |
static boolean |
contentEquals(File file1,
File file2)
Compare the contents of two files to determine if they are equal or not. |
static void |
copyFile(File source,
File destination)
Copy file from source to destination. |
static void |
copyFileToDirectory(File source,
File destinationDirectory)
Copy file from source to destination. |
static void |
copyFileToDirectory(String source,
String destinationDirectory)
Copy file from source to destination. |
static void |
copyURLToFile(URL source,
File destination)
Copies bytes from the URL source to a file
destination . |
static void |
deleteDirectory(File directory)
Recursively delete a directory. |
static void |
deleteDirectory(String directory)
Recursively delete a directory. |
static String |
dirname(String filename)
Returns the directory path portion of a file specification string. |
static String |
extension(String filename)
Returns the extension portion of a file specification string. |
static void |
fileCopy(String inFileName,
String outFileName)
Copy a file. |
static void |
fileDelete(String fileName)
Deletes a file. |
static boolean |
fileExists(String fileName)
Check if a file exits. |
static String |
filename(String filename)
Returns the filename portion of a file specification string. |
static String |
fileRead(String fileName)
Reads the contents of a file. |
static void |
fileWrite(String fileName,
String data)
Writes data to a file. |
static void |
forceDelete(File file)
Delete a file. |
static void |
forceDelete(String file)
Delete a file. |
static void |
forceDeleteOnExit(File file)
Schedule a file to be deleted when JVM exits. |
static void |
forceMkdir(File file)
Make a directory. |
static String |
getExtension(String filename)
Get extension from filename. ie foo.txt --> "txt" a\b\c.jpg --> "jpg" a\b\c --> "" |
static File |
getFile(String fileName)
Creates a file handle. |
static String[] |
getFilesFromExtension(String directory,
String[] extensions)
Given a directory and an array of extensions... return an array of compliant files. |
static String |
getPath(String filepath)
Get path from filename. |
static String |
getPath(String filepath,
char fileSeparatorChar)
Get path from filename. ie. |
static void |
mkdir(String dir)
Simple way to make a directory |
static String |
normalize(String path)
Normalize a path. |
static String |
removeExtension(String filename)
Remove extension from filename. ie foo.txt --> foo a\b\c.jpg --> a\b\c a\b\c --> a\b\c |
static String |
removePath(String filepath)
Remove path from filename. |
static String |
removePath(String filepath,
char fileSeparatorChar)
Remove path from filename. ie. |
static File |
resolveFile(File baseFile,
String filename)
Resolve a file filename to it's canonical form. |
static long |
sizeOfDirectory(File directory)
Recursively count size of a directory. |
static long |
sizeOfDirectory(String directory)
Recursively count size of a directory. |
static File |
toFile(URL url)
Convert from a URL to a File . |
static URL[] |
toURLs(File[] files)
Convert the array of Files into a list of URLs. |
static boolean |
waitFor(String fileName,
int seconds)
Waits for NFS to propagate a file creation, imposing a timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ONE_KB
public static final int ONE_MB
public static final int ONE_GB
Method Detail |
---|
public static String getExtension(String filename)
foo.txt --> "txt" a\b\c.jpg --> "jpg" a\b\c --> ""
filename
- the filename
public static File getFile(String fileName)
fileName
- The name of the file.
File
instance.public static String[] getFilesFromExtension(String directory, String[] extensions)
directory
- DOCUMENT ME!extensions
- DOCUMENT ME!
public static String getPath(String filepath)
dirname
. ie.
a/b/c.txt --> a/b a.txt --> ""
filepath
- the filepath
public static String getPath(String filepath, char fileSeparatorChar)
a/b/c.txt --> a/b a.txt --> ""
filepath
- the filepathfileSeparatorChar
- DOCUMENT ME!
public static String basename(String filename)
filename
- DOCUMENT ME!
public static String basename(String filename, String suffix)
filename
- DOCUMENT ME!suffix
- DOCUMENT ME!
public static String byteCountToDisplaySize(int size)
size
- The number of bytes.
public static String catPath(String lookupPath, String path)
lookupPath
- DOCUMENT ME!path
- DOCUMENT ME!
public static void cleanDirectory(String directory) throws IOException
directory
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void cleanDirectory(File directory) throws IOException
directory
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static boolean contentEquals(File file1, File file2) throws IOException
file1
- the first filefile2
- the second file
IOException
- DOCUMENT ME!public static void copyFile(File source, File destination) throws IOException
destination
will be created if they don't already exist.
destination
will be overwritten if it already exists.
source
- An existing non-directory File
to copy bytes
from.destination
- A non-directory File
to write bytes to
(possibly overwriting).
IOException
- if source
does not exist,
destination
cannot be written to, or an IO error
occurs during copying.public static void copyFileToDirectory(String source, String destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent
directories) will be created. If a file source
in
destinationDirectory
exists, it will be overwritten.
source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.
IOException
- if source
does not exist, the file in
destinationDirectory
cannot be written to, or an IO
error occurs during copying.public static void copyFileToDirectory(File source, File destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent
directories) will be created. If a file source
in
destinationDirectory
exists, it will be overwritten.
source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.
IOException
- if source
does not exist, the file in
destinationDirectory
cannot be written to, or an IO
error occurs during copying.public static void copyURLToFile(URL source, File destination) throws IOException
source
to a file
destination
. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.
source
- A URL
to copy bytes from.destination
- A non-directory File
to write bytes to
(possibly overwriting).
IOException
- if source
URL cannot be
openeddestination
cannot be written
topublic static void deleteDirectory(String directory) throws IOException
directory
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void deleteDirectory(File directory) throws IOException
directory
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static String dirname(String filename)
filename
- DOCUMENT ME!
public static String extension(String filename)
filename
- DOCUMENT ME!
public static void fileCopy(String inFileName, String outFileName) throws Exception
fileRead(String)
and
then fileWrite(String,String)
inFileName
- the file to copyoutFileName
- the file to copy to
Exception
- if fileRead or fileWrite throw itpublic static void fileDelete(String fileName)
fileName
- The name of the file to delete.public static boolean fileExists(String fileName)
fileName
- The name of the file to check.
public static String fileRead(String fileName) throws IOException
fileName
- The name of the file to read.
IOException
- DOCUMENT ME!public static void fileWrite(String fileName, String data) throws Exception
fileName
- The name of the file to write.data
- The content to write to the file.
Exception
- DOCUMENT ME!public static String filename(String filename)
filename
- DOCUMENT ME!
public static void forceDelete(String file) throws IOException
file
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void forceDelete(File file) throws IOException
file
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void forceDeleteOnExit(File file) throws IOException
file
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void forceMkdir(File file) throws IOException
file
- DOCUMENT ME!
IOException
- DOCUMENT ME!public static void mkdir(String dir)
dir
- DOCUMENT ME!public static String normalize(String path)
null
if the ..'s went past the root. Eg:
/foo// --> /foo/ /foo/./ --> /foo/ /foo/../bar --> /bar /foo/../bar/ --> /bar/ /foo/../bar/../baz --> /baz //foo//./bar --> /foo/bar /../ --> null
path
- the path to normalize
null
if too many ..'s.public static String removeExtension(String filename)
foo.txt --> foo a\b\c.jpg --> a\b\c a\b\c --> a\b\c
filename
- the filename
public static String removePath(String filepath)
basename
ie.
a/b/c.txt --> c.txt a.txt --> a.txt
filepath
- the filepath
public static String removePath(String filepath, char fileSeparatorChar)
a/b/c.txt --> c.txt a.txt --> a.txt
filepath
- the filepathfileSeparatorChar
- DOCUMENT ME!
public static File resolveFile(File baseFile, String filename)
filename
to it's canonical form. If
filename
is relative (doesn't start with /
),
it will be resolved relative to baseFile
, otherwise it is
treated as a normal root-relative path.
baseFile
- Where to resolve filename
from, if
filename
is relative.filename
- Absolute or relative file path to resolve.
File
of filename
.public static long sizeOfDirectory(String directory)
directory
- DOCUMENT ME!
public static long sizeOfDirectory(File directory)
directory
- DOCUMENT ME!
public static File toFile(URL url)
URL
to a File
.
url
- File URL.
File
object, or null
if
the URL's protocol is not file
public static URL[] toURLs(File[] files) throws IOException
files
- the array of files
IOException
- if an error occurspublic static boolean waitFor(String fileName, int seconds)
fileName
- The name of the file.seconds
- The maximum time in seconds to wait.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |