Forge - Addon Container 2.0.0.Alpha3

org.jboss.forge.container.util
Class Files

java.lang.Object
  extended by org.jboss.forge.container.util.Files

public final class Files
extends Object

Author:
Lincoln Baxter, III

Field Summary
static String HOME_ALIAS
           
static long ONE_GB
          The number of bytes in a gigabyte.
static long ONE_KB
          The number of bytes in a kilobyte.
static long ONE_MB
          The number of bytes in a megabyte.
static String SLASH
           
 
Constructor Summary
Files()
           
 
Method Summary
static String canonicalize(String target)
          Replace instances of internal tokens with actual file equivalents.
static void copyDirectory(File srcDir, File destDir)
          Copies a whole directory to a new location.
static void copyDirectory(File srcDir, File destDir, FileFilter filter)
          Copies a filtered directory to a new location.
static void copyFile(File srcFile, File destFile)
          Copies a file to a new location.
static void copyFileToDirectory(File srcFile, File destDir)
          Copies a file to a directory optionally preserving the file date.
static boolean delete(File file)
           
static boolean delete(File file, boolean recursive)
           
static void deleteOnExit(File file)
          Requests that the file or directory denoted by this resource be deleted when the virtual machine terminates.
static File getWorkingDirectory()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOME_ALIAS

public static final String HOME_ALIAS
See Also:
Constant Field Values

SLASH

public static final String SLASH

ONE_KB

public static final long ONE_KB
The number of bytes in a kilobyte.

See Also:
Constant Field Values

ONE_MB

public static final long ONE_MB
The number of bytes in a megabyte.

See Also:
Constant Field Values

ONE_GB

public static final long ONE_GB
The number of bytes in a gigabyte.

See Also:
Constant Field Values
Constructor Detail

Files

public Files()
Method Detail

delete

public static boolean delete(File file)

deleteOnExit

public static void deleteOnExit(File file)
Requests that the file or directory denoted by this resource be deleted when the virtual machine terminates.

Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care.


delete

public static boolean delete(File file,
                             boolean recursive)

canonicalize

public static String canonicalize(String target)
Replace instances of internal tokens with actual file equivalents.


getWorkingDirectory

public static File getWorkingDirectory()

copyFileToDirectory

public static void copyFileToDirectory(File srcFile,
                                       File destDir)
                                throws IOException
Copies a file to a directory optionally preserving the file date.

This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.

Note: Setting preserveFileDate to true tries to preserve the file's last modified date/times using File.setLastModified(long), however it is not guaranteed that the operation will succeed. If the modification operation fails, no indication is provided.

Parameters:
srcFile - an existing file to copy, must not be null
destDir - the directory to place the copy in, must not be null
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
IOException - if an IO error occurs during copying
Since:
Commons IO 1.3
See Also:
copyFile(File, File)

copyFile

public static void copyFile(File srcFile,
                            File destFile)
                     throws IOException
Copies a file to a new location.

This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.

Parameters:
srcFile - an existing file to copy, must not be null
destFile - the new file, must not be null
preserveFileDate - true if the file date of the copy should be the same as the original
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
IOException - if an IO error occurs during copying
See Also:
#copyFileToDirectory(File, File, boolean)

copyDirectory

public static void copyDirectory(File srcDir,
                                 File destDir)
                          throws IOException
Copies a whole directory to a new location.

This method copies the contents of the specified source directory to within the specified destination directory.

The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.

Note: Setting preserveFileDate to true tries to preserve the files' last modified date/times using File.setLastModified(long), however it is not guaranteed that those operations will succeed. If the modification operation fails, no indication is provided.

Parameters:
srcDir - an existing directory to copy, must not be null
destDir - the new directory, must not be null
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
IOException - if an IO error occurs during copying
Since:
1.1

copyDirectory

public static void copyDirectory(File srcDir,
                                 File destDir,
                                 FileFilter filter)
                          throws IOException
Copies a filtered directory to a new location.

This method copies the contents of the specified source directory to within the specified destination directory.

The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.

Note: Setting preserveFileDate to true tries to preserve the files' last modified date/times using File.setLastModified(long), however it is not guaranteed that those operations will succeed. If the modification operation fails, no indication is provided.

Example: Copy directories only

 // only copy the directory structure
 FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY, false);
 

Example: Copy directories and txt files

 // Create a filter for ".txt" files
 IOFileFilter txtSuffixFilter = FileFilterUtils.suffixFileFilter(".txt");
 IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.FILE, txtSuffixFilter);

 // Create a filter for either directories or ".txt" files
 FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles);

 // Copy using the filter
 FileUtils.copyDirectory(srcDir, destDir, filter, false);
 

Parameters:
srcDir - an existing directory to copy, must not be null
destDir - the new directory, must not be null
filter - the filter to apply, null means copy all directories and files
preserveFileDate - true if the file date of the copy should be the same as the original
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
IOException - if an IO error occurs during copying
Since:
1.4

Forge - Addon Container 2.0.0.Alpha3

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.