|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.lucidviews.util.io.Streams net.lucidviews.util.io.Files
public class Files
A collection of methods for manipualting File
s.
Nested Class Summary | |
---|---|
static class |
Files.NewFileNameModel
Helper class that creates a new file name based on some rules/configuration. |
Field Summary | |
---|---|
private static String |
DEFAULT_PATH_SEPARATOR
The character used to separate folder paths in the classpath. |
Fields inherited from class net.lucidviews.util.io.Streams |
---|
DEFAULT_BUFFER_SIZE |
Constructor Summary | |
---|---|
protected |
Files()
Suppresses default constructor, ensuring non-instantiability. |
Method Summary | |
---|---|
static File |
copyFile(File original,
File destination)
Copy a file to a given folder or file location. |
static File |
copyFile(File original,
File destination,
int bufferSize)
Copy a file to a given folder or file location. |
static File |
copyFile(File original,
File destinationFolder,
String fileName)
Copy a file to a folder, giving the copy a new name. |
static File |
copyFile(File original,
File destinationFolder,
String fileName,
int bufferSize)
Copy a file to a folder, giving the copy a new name. |
static boolean |
copyFolder(File original,
File destination)
Copy a folder, and all its contents, to another location. |
static boolean |
copyFolder(File original,
File destination,
FileFilter filter)
Copy a folder, and all its contents, to another location. |
static boolean |
copyFolder(File original,
File destination,
FilenameFilter filter)
Copy a folder, and all its contents, to another location. |
static boolean |
copyFolderContents(File original,
File destination)
Copy the contents of a folder to another location. |
static boolean |
copyFolderContents(File original,
File destination,
FileFilter filter)
Copy the contents of a folder to another location. |
static boolean |
copyFolderContents(File original,
File destination,
FilenameFilter filter)
Copy the contents of a folder to another location. |
static File |
createNewFile(File folder,
String preferredFileName)
Create a new, blank file in the given folder. |
static File |
createNewFile(String fileName,
File folder)
Create a new, blank file with a given name. |
static List |
createPatch(File currentFolder,
boolean recursive,
File oldFolder,
File destFolder)
Create a patch for an old set of files. |
static List |
createPatch(File currentFolder,
boolean recursive,
File oldFolder,
File destFolder,
boolean patchModifiedFiles)
Create a patch for an old set of files. |
static List<File> |
createPatch(File currentFolder,
boolean recursive,
File oldFolder,
File destFolder,
boolean patchModifiedFiles,
Comparator<File> fileComparator)
Create a patch for an old set of files. |
static List |
createPatch(File currentFolder,
File oldFolder,
File destFolder)
Create a patch for an old set of files. |
static List |
createPatch(File currentFolder,
File oldFolder,
File destFolder,
boolean patchModifiedFiles)
Create a patch for an old set of files. |
static boolean |
deleteFolder(File folder)
Delete a folder and all files and sub-folders. |
static File |
deriveRootFolder(File file)
Recurse down to find the root of a file path. |
static File |
findFile(String fileName)
Find a file with the given name, located somewhere on the classpath. |
static File |
getExistingParentFile(File file)
Get the existing parent (folder) for the given file. |
static boolean |
isDescendant(File folder,
File suspectedChild)
Checks if the suspectedChild file (or folder) is contained
within the specified folder or one of its sub-folders. |
static boolean |
isDuplicate(File file,
File compare)
Checks if one file is a duplicate of another. |
static List |
listFiles(File folder,
Comparator<File> comparator)
Get a sorted list of files for a given directory. |
static List |
listFiles(File folder,
FileFilter filter,
Comparator<File> comparator)
Get a filtered, sorted list of files for a given directory. |
static List |
listFiles(File folder,
FilenameFilter filter,
Comparator<File> comparator)
Get a filtered, sorted list of files for a given directory. |
static List |
sortFiles(File[] files,
Comparator<File> comparator)
Convert an array of File s to a sorted List . |
Methods inherited from class net.lucidviews.util.io.Streams |
---|
close, close, compare, compare, pipe, pipe |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String DEFAULT_PATH_SEPARATOR
Constructor Detail |
---|
protected Files()
Method Detail |
---|
public static File getExistingParentFile(File file)
null
value is returned.
file
- the file
public static File deriveRootFolder(File file)
file
- a File
File
reference to the root folderpublic static File findFile(String fileName) throws FileNotFoundException
fileName
- the name of the file
File
with the given name, located somewhere on the
classpath, the object is guaranteed to be non-null
and
the file is guaranteed to exist
FileNotFoundException
- if the file could not be found on the
classpathpublic static boolean isDuplicate(File file, File compare) throws IOException
file
- file to testcompare
- second file to compare the file to
true
if the two files are the same
IOException
- error reading content of the two files being comparedpublic static boolean isDescendant(File folder, File suspectedChild)
suspectedChild
file (or folder) is contained
within the specified folder or one of its sub-folders.
false
(not a descendant).
folder
- the folder that could be the parent or grand-parentsuspectedChild
- the file or folder that is suspected to be a
descendant
true
if the suspectedChild
is a
descendant of the folder
public static File createNewFile(File folder, String preferredFileName) throws IOException
folder
. The file will have a name
based on the preferredFileName
. If a file with the
preferred name already exists then a numeric suffix will be added (e.g.
./filename_2.dat
).
folder
- the directory where the new file is to be createdpreferredFileName
- the desired name of the file
File
reference to a new file in the given folder
IOException
- error creating the new file
SecurityException
- access to write the file was denied by the system
security managerpublic static File createNewFile(String fileName, File folder) throws IOException
fileName
. The file will be placed within
folder
, either directly in that folder or in a sub-folder.
If a file with the preferred name already exists then a sub-folder will
be created with a numeric suffix (e.g.
./filename_2/filename_2.dat
).
fileName
- the name of the new filefolder
- the desired directory where the new file is to be created
File
reference to a new file in the given folder
IOException
- error creating the new file
SecurityException
- access to write the file was denied by the system
security managerpublic static List sortFiles(File[] files, Comparator<File> comparator)
File
s to a sorted List
.
Comparator
.
files
- an array of File
comparator
- the Comparator
used to sort the files
List
of sorted File
s
ClassCastException
- the specified comparator
was not
compatible with File
objects
UnsupportedOperationException
- the generated List
did
not support a sort operationFileComparator
public static List listFiles(File folder, Comparator<File> comparator)
folder
- the folder whose contents are to be listedcomparator
- a Comparator
that will sort the files
List
of File
s
SecurityException
- read access to the folder was denied
ClassCastException
- the specified comparator
was not
compatible with File
objects
UnsupportedOperationException
- the generated List
did
not support a sort operationFileComparator
public static List listFiles(File folder, FilenameFilter filter, Comparator<File> comparator)
folder
- the folder whose contents are to be listedfilter
- a filter that determines which files are added to the listcomparator
- a Comparator
that will sort the files
List
of File
s
SecurityException
- read access to the folder was denied
ClassCastException
- the specified comparator
was not
compatible with File
objects
UnsupportedOperationException
- the generated List
did
not support a sort operationFilenameFilter
,
FileComparator
public static List listFiles(File folder, FileFilter filter, Comparator<File> comparator)
folder
- the folder whose contents are to be listedfilter
- a filter that determines which files are added to the listcomparator
- a Comparator
that will sort the files
List
of File
s
SecurityException
- read access to the folder was denied
ClassCastException
- the specified comparator
was not
compatible with File
objects
UnsupportedOperationException
- the generated List
did
not support a sort operationFileFilter
,
FileComparator
public static File copyFile(File original, File destination, int bufferSize) throws IOException
File
can reference either a directory or a
file. In the case of a directory, a copy of the original file will be
placed in this directory with the same name. If a file is specified, the
destination file will be overwritten with the file at the
original
location.
original
- the file to be copieddestination
- the destination of the copy - either a file or a directorybufferSize
- the size of the buffer to use when copying the data
SecurityException
- error creating a new file
IOException
- error copying the content of the filepublic static File copyFile(File original, File destination) throws IOException
destination
File
can reference either a
directory or a file. In the case of a directory, a copy of the original
file will be placed in this directory with the same name. If a file is
specified, the destination file will be overwritten with the file at the
original
location.
original
- the file to be copieddestination
- the destination of the copy - either a file or a
directory
SecurityException
- error creating a new file
IOException
- error copying the content of the filepublic static File copyFile(File original, File destinationFolder, String fileName, int bufferSize) throws IOException
original
- the file to be copieddestinationFolder
- the folder where the file is to be copied tofileName
- the name of the new copybufferSize
- the size of the buffer to use when copying the data
SecurityException
- error creating a new file
IOException
- error copying the content of the filepublic static File copyFile(File original, File destinationFolder, String fileName) throws IOException
original
- the file to be copieddestinationFolder
- the folder where the file is to be copied tofileName
- the name of the new copy
SecurityException
- error creating a new file
IOException
- error copying the content of the filepublic static boolean copyFolder(File original, File destination, FilenameFilter filter)
destination
folder already contains a folder with the
same name as the original
then the contents of the
original
folder will be merged into that folder, overwriting
any writable files already in the destination
(read-only
files will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will be an exact copy of the
original
.
• A return value of false
indicates the
destination
folder may not exist.
• In the case of a security exception, there is no guarantee as
to which files have been copied, including the root folder.
original
- the folder to be copieddestination
- the folder where the original folder is to be copied tofilter
- a filter used to choose which files to copy
true
if the folder and its contents were copied
successfully, false
otherwisepublic static boolean copyFolder(File original, File destination, FileFilter filter)
destination
folder already contains a folder with the
same name as the original
then the contents of the
original
folder will be merged into that folder, overwriting
any writable files already in the destination
(read-only
files will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will be an exact copy of the
original
.
• A return value of false
indicates the
destination
folder may not exist.
• In the case of a security exception, there is no guarantee as
to which files have been copied, including the root folder.
original
- the folder to be copieddestination
- the folder where the original folder is to be copied tofilter
- a filter used to choose which files to copy
true
if the folder and its contents were copied
successfully, false
otherwisepublic static boolean copyFolder(File original, File destination)
destination
folder already contains a folder with the
same name as the original
then the contents of the
original
folder will be merged into that folder, overwriting
any writable files already in the destination
(read-only
files will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will be an exact copy of the
original
.
• A return value of false
indicates the
destination
folder may not exist.
• In the case of a security exception, there is no guarantee as
to which files have been copied, including the root folder.
original
- the folder to be copieddestination
- the folder where the original folder is to be copied to
true
if the folder and its contents were copied
successfully, false
otherwisepublic static boolean copyFolderContents(File original, File destination, FilenameFilter filter)
original
folder will overwrite any
writable files already in the destination
(read-only files
will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will contain all the files and folder in
the original
.
• A return value of false
indicates the
destination
folder may not contain any of the files or folders
from the original
.
• In the case of a security exception, there is no guarantee as
to which files have been copied.
original
- the folder whose content is to be copieddestination
- the folder where the content is to be copied tofilter
- a filter used to choose which files to copy
true
if the contents were copied successfully,
false
otherwisepublic static boolean copyFolderContents(File original, File destination, FileFilter filter)
original
folder will overwrite any
writable files already in the destination
(read-only files
will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will contain all the files and folder in
the original
.
• A return value of false
indicates the
destination
folder may not contain any of the files or folders
from the original
.
• In the case of a security exception, there is no guarantee as
to which files have been copied.
original
- the folder whose content is to be copieddestination
- the folder where the content is to be copied tofilter
- a filter used to choose which files to copy
true
if the contents were copied successfully,
false
otherwisepublic static boolean copyFolderContents(File original, File destination)
original
folder will overwrite any
writable files already in the destination
(read-only files
will not be overwritten, but will cause this copy to be incomplete,
acknowledged by a false
return value).
original
folder. If one file or folder cannot be copied the
routine will continue copying the remaining contents.
true
if all files and sub-folders were
successfully copied. This method returns false
if any file or
folder could not be deleted.
true
indicates the
destination
folder will contain all the files and folder in
the original
.
• A return value of false
indicates the
destination
folder may not contain any of the files or folders
from the original
.
• In the case of a security exception, there is no guarantee as
to which files have been copied.
original
- the folder whose content is to be copieddestination
- the folder where the content is to be copied to
true
if the contents were copied successfully,
false
otherwisepublic static boolean deleteFolder(File folder)
true
if all files and sub-folders were
successfully deleted. This method returns false
if any file or
folder could not be deleted.
true
indicates the
folder
will no longer exist.
• A return value of false
indicates the
folder
will still exist, however there is no guarantee that
any of its files or sub-folders will still exist.
• In the case of a security exception, there is no guarantee as
to which files have been deleted, including the specified
folder
.
folder
- the folder to be deleted
SecurityException
- delete access to the folder was denied by the
security managerpublic static List createPatch(File currentFolder, File oldFolder, File destFolder)
currentFolder
- the root folder containing the current set of files
(latest version)oldFolder
- the root folder containing the old set of filesdestFolder
- the folder where the patch is to be created (this folder
need not exist, it will automatically be created) it is
recommended the folder either does not exist or is empty
before this method is called
List
of File
references to files in the
'current' folder that could not be copied/included in the patch due
to an I/O exception - the value is never null
- always
check the list is empty to ensure the patch was completepublic static List createPatch(File currentFolder, File oldFolder, File destFolder, boolean patchModifiedFiles)
patchModifiedFiles
parameter to true
. (The
definition of 'modified' being those files whose timestamp is more recent
than the old copy of the file).
currentFolder
- the root folder containing the current set of files
(latest version)oldFolder
- the root folder containing the old set of filesdestFolder
- the folder where the patch is to be created (this folder
need not exist, it will automatically be created) it is
recommended the folder either does not exist or is empty
before this method is calledpatchModifiedFiles
- indicates if modified files should be included
in the patch
List
of File
references to files in the
'current' folder that could not be copied/included in the patch due
to an I/O exception - the value is never null
- always
check the list is empty to ensure the patch was completepublic static List createPatch(File currentFolder, boolean recursive, File oldFolder, File destFolder)
recursive
parameter to true
. It will
automatically include modified files in the patch. (The definition of
'modified' being those files whose timestamp is more recent than the old
copy of the file).
currentFolder
- the root folder containing the current set of files
(latest version)recursive
- indicates if the patch should include sub-foldersoldFolder
- the root folder containing the old set of filesdestFolder
- the folder where the patch is to be created (this folder
need not exist, it will automatically be created) it is
recommended the folder either does not exist or is empty
before this method is called
List
of File
references to files in the
'current' folder that could not be copied/included in the patch due
to an I/O exception - the value is never null
- always
check the list is empty to ensure the patch was completepublic static List createPatch(File currentFolder, boolean recursive, File oldFolder, File destFolder, boolean patchModifiedFiles)
recursive
parameter to true
. It will only
include modified files in the patch if instructed to, by setting the
patchModifiedFiles
parameter to true
. (The
definition of 'modified' being those files whose timestamp is more recent
than the old copy of the file).
currentFolder
- the root folder containing the current set of files
(latest version)recursive
- indicates if the patch should include sub-foldersoldFolder
- the root folder containing the old set of filesdestFolder
- the folder where the patch is to be created (this folder
need not exist, it will automatically be created) it is
recommended the folder either does not exist or is empty
before this method is calledpatchModifiedFiles
- indicates if modified files should be included
in the patch
List
of File
references to files in the
'current' folder that could not be copied/included in the patch due
to an I/O exception - the value is never null
- always
check the list is empty to ensure the patch was completepublic static List<File> createPatch(File currentFolder, boolean recursive, File oldFolder, File destFolder, boolean patchModifiedFiles, Comparator<File> fileComparator)
recursive
parameter to true
. It will only
include modified files in the patch if instructed to, by setting the
patchModifiedFiles
parameter to true
.
fileComparator
. If the fileComparator
concludes
the current file is 'greater' than the old file, then the file is
considered more recent and therefore needs replacing.
currentFolder
- the root folder containing the current set of files
(latest version)recursive
- indicates if the patch should include sub-foldersoldFolder
- the root folder containing the old set of filesdestFolder
- the folder where the patch is to be created (this folder
need not exist, it will automatically be created) it is
recommended the folder either does not exist or is empty
before this method is calledpatchModifiedFiles
- indicates if modified files should be included
in the patchfileComparator
- the comparator used to determine which file is more
recent and therefore if it needs to be patched
List
of File
references to files in the
'current' folder that could not be copied/included in the patch due
to an I/O exception - the value is never null
- always
check the list is empty to ensure the patch was complete
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |