uk.org.retep.util.io
Class FileUtils

java.lang.Object
  extended by uk.org.retep.util.io.FileUtils

public class FileUtils
extends java.lang.Object

Common methods used in our own binary file formats.

Author:
peter

Field Summary
static java.io.FileFilter DIRECTORY_FILTER
          A FileFilter that will accept Directories that can be read
static java.io.FileFilter EVERYTHING_FILTER
          A FileFilter that will accept everything passed to it.
static java.io.FileFilter FILE_FILTER
          A FileFilter that will accept plain File's that can be read
static java.io.FileFilter JAR_FILTER
          A FileFilter that will accept plain File's that can be read and who's name ends with .jar
static java.io.FileFilter JAVA_FILTER
          A FileFilter that will accept plain File's that can be read and who's name ends with .java
 
Method Summary
static void assertFileInsideDirectory(java.io.File baseDirectory, java.io.File file)
          Checks that the file is in the baseDirectory, or a subdirectory of it.
static int copy(java.nio.channels.FileChannel src, java.nio.channels.FileChannel dst)
          Copy the content of one FileChannel to another
static int copy(java.io.InputStream is, java.io.OutputStream os)
          Copy from a source InputStream and write to an OutputStream
static int copy(java.io.Reader r, java.io.Writer w)
          Copy from a source InputStream and write to an OutputStream
static int copyFile(java.io.File sourceFile, java.io.File destinationFile)
          Copy from one File and write to another
static int copyFile(java.io.File file, java.io.OutputStream os)
          Copy from a File and write to an OutputStream
static int copyFile(java.io.InputStream is, java.io.File file)
          Copy from a source InputStream and write to a File
static boolean delete(java.io.File file)
          Delete a File.
static boolean delete(java.io.File file, Log log)
          Delete a File.
static java.util.List<java.io.File> findFiles(java.io.File directory, java.io.FileFilter filter, boolean recurse)
           
static java.util.List<java.io.File> findFiles(java.io.FileFilter fileFilter, java.util.List<java.io.File> sources)
          Scan the list of sources returning all files that match the supplied FileFilter.
static java.util.List<java.io.File> findFiles(java.util.List<java.io.File> files, java.io.File directory, java.io.FileFilter filter, boolean recurse)
           
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(Log log, java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(Log log, java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(Log log, java.lang.String message, java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexCopyFileVisitor(Log log, java.lang.String message, java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetExecutableVisitor(boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetExecutableVisitor(boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetExecutableVisitor(Log log, boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetExecutableVisitor(Log log, boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetReadOnlyVisitor(boolean state)
          A convenience method to get a FileVisitor to set the owner's read permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetReadOnlyVisitor(boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's read permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetReadOnlyVisitor(Log log, boolean state)
          A convenience method to get a FileVisitor to set the owner's read permission.
static
<F extends ComplexFile>
ComplexFileVisitor<F>
getComplexSetReadOnlyVisitor(Log log, boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static java.io.FileFilter getContentsFileFilter(java.io.File directory)
          Returns a FileFilter which will include any file or directory that is contained within the specified directory
static FileVisitor getCopyFileVisitor(java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static FileVisitor getCopyFileVisitor(java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static FileVisitor getCopyFileVisitor(Log log, java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static FileVisitor getCopyFileVisitor(Log log, java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static FileVisitor getCopyFileVisitor(Log log, java.lang.String message, java.io.File destinationDirectory)
          Create a FileVisitor what will copy the visited file to the destination directory.
static FileVisitor getCopyFileVisitor(Log log, java.lang.String message, java.io.File destinationDirectory, boolean overwrite)
          Create a FileVisitor what will copy the visited file to the destination directory.
static java.io.FileFilter getExtensionFileFilter(java.lang.String fileExtension)
          Returns a FileFilter which will accept all files whos names end with a specific extension
static FileVisitor getSetExecutableVisitor(boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetExecutableVisitor(boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetExecutableVisitor(Log log, boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetExecutableVisitor(Log log, boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetReadOnlyVisitor(boolean state)
          A convenience method to get a FileVisitor to set the owner's read permission.
static FileVisitor getSetReadOnlyVisitor(boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's read permission.
static FileVisitor getSetReadOnlyVisitor(Log log, boolean state)
          A convenience method to get a FileVisitor to set the owner's read permission.
static FileVisitor getSetReadOnlyVisitor(Log log, boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetWritableVisitor(boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetWritableVisitor(boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetWritableVisitor(Log log, boolean state)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static FileVisitor getSetWritableVisitor(Log log, boolean state, boolean ownerOnly)
          A convenience method to get a FileVisitor to set the owner's execute permission.
static java.io.File makeFileRelative(java.io.File baseDir, java.io.File file)
          Ensure that a File is relative from a base directory
static java.io.File mkdir(java.io.File dir, Log log)
          Identical to File.mkdir() but will log if the logger is not null
static java.io.File mkdirs(java.io.File dir, Log log)
          Identical to File.mkdir() but will log if the logger is not null
static java.lang.StringBuilder read(java.io.File f)
           
static java.lang.StringBuilder read(java.io.File f, java.lang.StringBuilder sb)
           
static java.lang.StringBuilder read(java.io.InputStream is)
           
static java.lang.StringBuilder read(java.io.InputStream is, java.lang.StringBuilder sb)
           
static java.lang.StringBuilder read(java.io.Reader r)
           
static java.lang.StringBuilder read(java.io.Reader r, java.lang.StringBuilder sb)
           
static byte[] readBytes(java.io.File file)
          Read the content of a file into a byte array
static byte[] readBytes(java.io.InputStream is)
          Read the content of an InputStream into a byte array
static java.util.List<java.lang.String> readLines(BufferedCharReader r)
           
static java.util.List<java.lang.String> readLines(BufferedCharReader r, java.util.List<java.lang.String> list)
           
static java.util.List<java.lang.String> readLines(java.io.File f)
           
static java.util.List<java.lang.String> readLines(java.io.File f, java.util.List<java.lang.String> list)
           
static java.util.List<java.lang.String> readLines(java.io.InputStream is)
           
static java.util.List<java.lang.String> readLines(java.io.InputStream is, java.util.List<java.lang.String> list)
           
static java.util.List<java.lang.String> readLines(java.io.Reader r)
           
static java.util.List<java.lang.String> readLines(java.io.Reader r, java.util.List<java.lang.String> list)
           
static java.util.List<java.io.File> scanFiles(java.io.FileFilter fileFilter, java.util.List<java.lang.String> sources)
          Scan the list of sources returning all files that match the supplied FileFilter.
static java.util.List<java.io.File> scanFiles(java.io.FileFilter fileFilter, java.lang.String... sources)
          Scan the list of sources returning all files that match the supplied FileFilter.
static java.util.List<java.net.URL> toURL(java.util.Collection<java.io.File> files)
           
static java.net.URL[] toURL(java.io.File... files)
           
static java.net.URL[] toURLArray(java.util.Collection<java.io.File> files)
           
static int transferFrom(java.io.File sourceFile, java.nio.channels.WritableByteChannel dst)
          Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.
static int transferFrom(java.io.File sourceFile, java.nio.channels.WritableByteChannel dst, int bufferSize)
          Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.
static int transferFrom(java.nio.channels.ReadableByteChannel src, java.nio.channels.WritableByteChannel dst)
          Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.
static int transferFrom(java.nio.channels.ReadableByteChannel src, java.nio.channels.WritableByteChannel dst, int bufferSize)
          Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.
static boolean visitFiles(ComplexFileVisitor visitor, java.util.Collection<ComplexFile> files)
          Run a FileVisitor over the supplied files.
static boolean visitFiles(ComplexFileVisitor visitor, java.util.Collection<ComplexFile> files, boolean allModified)
          Run a FileVisitor over the supplied files.
static boolean visitFiles(FileVisitor visitor, java.util.Collection<java.io.File> files)
          Run a FileVisitor over the supplied files.
static boolean visitFiles(FileVisitor visitor, java.util.Collection<java.io.File> files, boolean allModified)
          Run a FileVisitor over the supplied files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORY_FILTER

public static final java.io.FileFilter DIRECTORY_FILTER
A FileFilter that will accept Directories that can be read


FILE_FILTER

public static final java.io.FileFilter FILE_FILTER
A FileFilter that will accept plain File's that can be read


JAVA_FILTER

public static final java.io.FileFilter JAVA_FILTER
A FileFilter that will accept plain File's that can be read and who's name ends with .java


JAR_FILTER

public static final java.io.FileFilter JAR_FILTER
A FileFilter that will accept plain File's that can be read and who's name ends with .jar


EVERYTHING_FILTER

public static final java.io.FileFilter EVERYTHING_FILTER
A FileFilter that will accept everything passed to it. Useful for use with API's that require a FileFilter.

The only thing this FileFilter will not accept is a null File.

Method Detail

getExtensionFileFilter

public static final java.io.FileFilter getExtensionFileFilter(java.lang.String fileExtension)
Returns a FileFilter which will accept all files whos names end with a specific extension

Parameters:
fileExtension - File extension. If it does not start with '.' then one will be added to it
Returns:
FileFilter

getContentsFileFilter

public static java.io.FileFilter getContentsFileFilter(java.io.File directory)
                                                throws java.io.IOException
Returns a FileFilter which will include any file or directory that is contained within the specified directory

Parameters:
directory - File of directory to include
Returns:
FileFilter
Throws:
java.io.IOException

makeFileRelative

public static java.io.File makeFileRelative(java.io.File baseDir,
                                            java.io.File file)
                                     throws java.io.IOException
Ensure that a File is relative from a base directory

Parameters:
baseDir - File representing the base directory
file - File to make relative
Returns:
File relative to baseDir
Throws:
java.io.IOException - if a canonical path cannot be found
java.lang.IllegalArgumentException - if file is not beneath baseDir

toURL

public static java.net.URL[] toURL(java.io.File... files)
                            throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

toURLArray

public static java.net.URL[] toURLArray(java.util.Collection<java.io.File> files)
                                 throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

toURL

public static java.util.List<java.net.URL> toURL(java.util.Collection<java.io.File> files)
                                          throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

readBytes

public static byte[] readBytes(java.io.File file)
                        throws java.io.IOException
Read the content of a file into a byte array

Parameters:
file - File to read
Returns:
byte[]
Throws:
java.io.IOException - on error

readBytes

public static byte[] readBytes(java.io.InputStream is)
                        throws java.io.IOException
Read the content of an InputStream into a byte array

Parameters:
is - InputStream to read from
Returns:
byte[]
Throws:
java.io.IOException - on error

copyFile

public static final int copyFile(java.io.File sourceFile,
                                 java.io.File destinationFile)
                          throws java.io.IOException
Copy from one File and write to another

Parameters:
sourceFile - File to read from
destinationFile - File to write to
Returns:
number of bytes copied
Throws:
java.io.IOException

copy

public static final int copy(java.nio.channels.FileChannel src,
                             java.nio.channels.FileChannel dst)
                      throws java.io.IOException
Copy the content of one FileChannel to another

Parameters:
src - source FileChannel
dst - destination FileChannel
Returns:
number of bytes copied
Throws:
java.io.IOException

transferFrom

public static final int transferFrom(java.io.File sourceFile,
                                     java.nio.channels.WritableByteChannel dst)
                              throws java.io.IOException
Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF. This method uses a transfer block size of 100K

Parameters:
sourceFile - File to read from
dst - destination
Returns:
number of bytes copied
Throws:
java.io.IOException
See Also:
#transferFrom(java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, long)

transferFrom

public static final int transferFrom(java.io.File sourceFile,
                                     java.nio.channels.WritableByteChannel dst,
                                     int bufferSize)
                              throws java.io.IOException
Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.

Parameters:
sourceFile - File to read from
dst - destination
bufferSize - The buffer size to use
Returns:
number of bytes copied
Throws:
java.io.IOException

transferFrom

public static final int transferFrom(java.nio.channels.ReadableByteChannel src,
                                     java.nio.channels.WritableByteChannel dst)
                              throws java.io.IOException
Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF. This method uses a transfer block size of 100K

Parameters:
src - source
dst - destination
Returns:
number of bytes copied
Throws:
java.io.IOException
See Also:
#transferFrom(java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, long)

transferFrom

public static final int transferFrom(java.nio.channels.ReadableByteChannel src,
                                     java.nio.channels.WritableByteChannel dst,
                                     int bufferSize)
                              throws java.io.IOException
Copy the content of a ReadableByteChannel and write to a WritableByteChannel until the source returns EOF.

Parameters:
src - source
dst - destination
bufferSize - The buffer size to use. If this is < 1K then the default bufferSize of 100K will be used.
Returns:
number of bytes copied
Throws:
java.io.IOException

copyFile

public static final int copyFile(java.io.File file,
                                 java.io.OutputStream os)
                          throws java.io.IOException
Copy from a File and write to an OutputStream

Parameters:
file - File to read from
os - OutputStream
Returns:
number of bytes copied
Throws:
java.io.IOException

copyFile

public static final int copyFile(java.io.InputStream is,
                                 java.io.File file)
                          throws java.io.IOException
Copy from a source InputStream and write to a File

Parameters:
is - InputStream
file - File to write to
Returns:
number of bytes copied
Throws:
java.io.IOException

copy

public static final int copy(java.io.InputStream is,
                             java.io.OutputStream os)
                      throws java.io.IOException
Copy from a source InputStream and write to an OutputStream

Parameters:
is - InputStream
os - OutputStream
Returns:
number of bytes copied
Throws:
java.io.IOException

copy

public static final int copy(java.io.Reader r,
                             java.io.Writer w)
                      throws java.io.IOException
Copy from a source InputStream and write to an OutputStream

Parameters:
r - Reader
w - Writer
Returns:
number of bytes copied
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.File f)
                                          throws java.io.IOException
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.File f,
                                                 java.lang.StringBuilder sb)
                                          throws java.io.IOException
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.InputStream is)
                                          throws java.io.IOException
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.Reader r)
                                          throws java.io.IOException
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.InputStream is,
                                                 java.lang.StringBuilder sb)
                                          throws java.io.IOException
Throws:
java.io.IOException

read

public static final java.lang.StringBuilder read(java.io.Reader r,
                                                 java.lang.StringBuilder sb)
                                          throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.File f)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.File f,
                                                               java.util.List<java.lang.String> list)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.InputStream is)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.Reader r)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.InputStream is,
                                                               java.util.List<java.lang.String> list)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(java.io.Reader r,
                                                               java.util.List<java.lang.String> list)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(BufferedCharReader r)
                                                        throws java.io.IOException
Throws:
java.io.IOException

readLines

public static final java.util.List<java.lang.String> readLines(BufferedCharReader r,
                                                               java.util.List<java.lang.String> list)
                                                        throws java.io.IOException
Throws:
java.io.IOException

findFiles

public static java.util.List<java.io.File> findFiles(java.io.File directory,
                                                     java.io.FileFilter filter,
                                                     boolean recurse)

findFiles

public static java.util.List<java.io.File> findFiles(java.util.List<java.io.File> files,
                                                     java.io.File directory,
                                                     java.io.FileFilter filter,
                                                     boolean recurse)

assertFileInsideDirectory

public static void assertFileInsideDirectory(java.io.File baseDirectory,
                                             java.io.File file)
Checks that the file is in the baseDirectory, or a subdirectory of it. If the file is outside baseDirectory (even by a symlink), then a SecuritException is thrown, otherwise nothing happens.

Parameters:
baseDirectory - File defining the base directory
file - File to test
Throws:
java.lang.SecurityException - if the file is outside the baseDirectory

mkdir

public static java.io.File mkdir(java.io.File dir,
                                 Log log)
Identical to File.mkdir() but will log if the logger is not null

Parameters:
dir - Directory to make
log - Log to use if not null
Returns:
dir

mkdirs

public static java.io.File mkdirs(java.io.File dir,
                                  Log log)
Identical to File.mkdir() but will log if the logger is not null

Parameters:
dir - Directory to make
log - Log to use if not null
Returns:
dir

visitFiles

public static boolean visitFiles(FileVisitor visitor,
                                 java.util.Collection<java.io.File> files)
                          throws java.io.IOException
Run a FileVisitor over the supplied files. The return value of this method will be true if at least one file visited returned true.

Parameters:
visitor - FileVisitor
files - List of File's to visit
Returns:
true if atleast one file was modified
Throws:
java.io.IOException - if an error occurs.

visitFiles

public static boolean visitFiles(FileVisitor visitor,
                                 java.util.Collection<java.io.File> files,
                                 boolean allModified)
                          throws java.io.IOException
Run a FileVisitor over the supplied files. The return value of this method will be true dependent on the value of allModified. If allModified is false, then the return value will be true if at least one file visited returned true. If allModified is true, then the return value will be true only if all files visited returned true.

Parameters:
visitor - FileVisitor
files - List of File's to visit
allModified - the logical operation performed to generate the return
Returns:
true or false dependent on the return values of the visitor and the allModified flag
Throws:
java.io.IOException - if an error occurs.

visitFiles

public static boolean visitFiles(ComplexFileVisitor visitor,
                                 java.util.Collection<ComplexFile> files)
                          throws java.io.IOException
Run a FileVisitor over the supplied files. The return value of this method will be true if at least one file visited returned true.

Parameters:
visitor - FileVisitor
files - List of File's to visit
Returns:
true if atleast one file was modified
Throws:
java.io.IOException - if an error occurs.

visitFiles

public static boolean visitFiles(ComplexFileVisitor visitor,
                                 java.util.Collection<ComplexFile> files,
                                 boolean allModified)
                          throws java.io.IOException
Run a FileVisitor over the supplied files. The return value of this method will be true dependent on the value of allModified. If allModified is false, then the return value will be true if at least one file visited returned true. If allModified is true, then the return value will be true only if all files visited returned true.

Parameters:
visitor - FileVisitor
files - List of File's to visit
allModified - the logical operation performed to generate the return
Returns:
true or false dependent on the return values of the visitor and the allModified flag
Throws:
java.io.IOException - if an error occurs.

scanFiles

public static java.util.List<java.io.File> scanFiles(java.io.FileFilter fileFilter,
                                                     java.lang.String... sources)
Scan the list of sources returning all files that match the supplied FileFilter.

Parameters:
sources - List of sources, may not be null
fileFilter - FileFilter, may not be null
Returns:
List of File's

scanFiles

public static java.util.List<java.io.File> scanFiles(java.io.FileFilter fileFilter,
                                                     java.util.List<java.lang.String> sources)
Scan the list of sources returning all files that match the supplied FileFilter.

Parameters:
sources - List of sources, may not be null
fileFilter - FileFilter, may not be null
Returns:
List of File's

findFiles

public static java.util.List<java.io.File> findFiles(java.io.FileFilter fileFilter,
                                                     java.util.List<java.io.File> sources)
Scan the list of sources returning all files that match the supplied FileFilter.

Parameters:
sources - List of sources, may not be null
fileFilter - FileFilter, may not be null
Returns:
List of File's

getComplexSetExecutableVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetExecutableVisitor(boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Type Parameters:
F - ComplexFile implementation
Parameters:
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetExecutableVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetExecutableVisitor(boolean state,
                                                                                           boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Type Parameters:
F - ComplexFile implementation
Parameters:
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetExecutableVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetExecutableVisitor(Log log,
                                                                                           boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetExecutableVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetExecutableVisitor(Log log,
                                                                                           boolean state,
                                                                                           boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetExecutableVisitor

public static FileVisitor getSetExecutableVisitor(boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetExecutableVisitor

public static FileVisitor getSetExecutableVisitor(boolean state,
                                                  boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetExecutableVisitor

public static FileVisitor getSetExecutableVisitor(Log log,
                                                  boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetExecutableVisitor

public static FileVisitor getSetExecutableVisitor(Log log,
                                                  boolean state,
                                                  boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetReadOnlyVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetReadOnlyVisitor(boolean state)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetReadOnlyVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetReadOnlyVisitor(boolean state,
                                                                                         boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetReadOnlyVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetReadOnlyVisitor(Log log,
                                                                                         boolean state)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getComplexSetReadOnlyVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexSetReadOnlyVisitor(Log log,
                                                                                         boolean state,
                                                                                         boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetReadOnlyVisitor

public static FileVisitor getSetReadOnlyVisitor(boolean state)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetReadOnlyVisitor

public static FileVisitor getSetReadOnlyVisitor(boolean state,
                                                boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetReadOnlyVisitor

public static FileVisitor getSetReadOnlyVisitor(Log log,
                                                boolean state)
A convenience method to get a FileVisitor to set the owner's read permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetReadOnlyVisitor

public static FileVisitor getSetReadOnlyVisitor(Log log,
                                                boolean state,
                                                boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetWritableVisitor

public static FileVisitor getSetWritableVisitor(boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetWritableVisitor

public static FileVisitor getSetWritableVisitor(boolean state,
                                                boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetWritableVisitor

public static FileVisitor getSetWritableVisitor(Log log,
                                                boolean state)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getSetWritableVisitor

public static FileVisitor getSetWritableVisitor(Log log,
                                                boolean state,
                                                boolean ownerOnly)
A convenience method to get a FileVisitor to set the owner's execute permission.

An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation

 getSetExecutableVisitor(arg, true)
 

Parameters:
log - Log to use, ignored if null
state - true to set executable, false to clear
ownerOnly - If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. If the underlying file system can not distinguish the owner's execute permission from that of others, then the permission will apply to everybody, regardless of this value.
Returns:
true if and only if the operation succeeded for all files. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. If executable is false and the underlying file system does not implement an execute permission, then the operation will fail.

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Parameters:
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(java.io.File destinationDirectory,
                                             boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Parameters:
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(Log log,
                                             java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Parameters:
log - Optional Log
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(Log log,
                                             java.lang.String message,
                                             java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Parameters:
log - Optional Log
message - Message to log per file if log != null
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(Log log,
                                             java.io.File destinationDirectory,
                                             boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Parameters:
log - Optional Log
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

getCopyFileVisitor

public static FileVisitor getCopyFileVisitor(Log log,
                                             java.lang.String message,
                                             java.io.File destinationDirectory,
                                             boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Parameters:
log - Optional Log
message - Message to log per file if log != null
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Type Parameters:
F - ComplexFile implementation
Parameters:
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(java.io.File destinationDirectory,
                                                                                      boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Type Parameters:
F - ComplexFile implementation
Parameters:
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(Log log,
                                                                                      java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Optional Log
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(Log log,
                                                                                      java.lang.String message,
                                                                                      java.io.File destinationDirectory)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only. Existing files will be overwritten

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Optional Log
message - Message to log per file if log != null
destinationDirectory - File of destinationDirectory
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(Log log,
                                                                                      java.io.File destinationDirectory,
                                                                                      boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Optional Log
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

getComplexCopyFileVisitor

public static <F extends ComplexFile> ComplexFileVisitor<F> getComplexCopyFileVisitor(Log log,
                                                                                      java.lang.String message,
                                                                                      java.io.File destinationDirectory,
                                                                                      boolean overwrite)
Create a FileVisitor what will copy the visited file to the destination directory. This implementation does not handle subdirectories in the source, so all files written will be in the destinationDirectory only.

Type Parameters:
F - ComplexFile implementation
Parameters:
log - Optional Log
message - Message to log per file if log != null
destinationDirectory - File of destinationDirectory
overwrite - true to overwrite existing files
Returns:
FileVisitor

delete

public static boolean delete(@Nonnull
                             java.io.File file)
Delete a File. This is the same as File.delete() except that this method will delete all content if it's a directory

Parameters:
file - File to delete
Returns:
true only if the file was really deleted

delete

public static boolean delete(@Nonnull
                             java.io.File file,
                             @Nullable
                             Log log)
Delete a File. This is the same as File.delete() except that this method will delete all content if it's a directory

Parameters:
file - File to delete
log - Log to log progress to, null for no logging
Returns:
true only if the file was really deleted


Copyright © 1998-2010 Retep Development Group. All Rights Reserved.