com.ibm.di.util
Class FileUtils

java.lang.Object
  extended by com.ibm.di.util.FileUtils

public class FileUtils
extends Object

Utility class used for file manipulation operations.


Constructor Summary
FileUtils()
           
 
Method Summary
static boolean copyFile(File fromFile, File toFile, boolean overwrite)
          Copy file.
static boolean copyFile(String fromPath, String toPath, boolean overwrite)
          Copy file.
static void delete(File file)
          Simply calls the delete() method of the provided file object.
static void delete(File file, Log log)
          Simply calls the delete() method of the provided file object.
static void delete(String path)
          Simply calls the delete() method of the provided file object.
static void delete(String path, Log log)
          Simply calls the delete() method of the provided file object.
static void deleteRecursively(File toDelete)
          Deletes the provided File.
static void deleteRecursively(String toDelete)
          Convenience method that delegates to deleteRecursively(File).
static String loadFile(File file)
          Loads the specified file and returns its content as String.
static String loadFile(File file, String encoding)
          Loads the specified file and returns its content as String.
static String loadFile(String file)
          Loads the specified file and returns its content as String.
static void mkdir(File file)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(File file, Log log)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(String path)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(String path, Log log)
          Simply calls the mkdir() method of the provided file object.
static void mkdirs(File file)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(File file, Log log)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(String path)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(String path, Log log)
          Simply calls the mkdirs() method of the provided file object.
static byte[] readInputStream(InputStream is)
          Reads the provided input stream and returns it as an array of bytes.
static void renameTo(File from, File to)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(File from, File to, Log log)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(String from, String to)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(String from, String to, Log log)
          Simply calls the renameTo() method of the provided file object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

loadFile

public static String loadFile(String file)
                       throws Exception
Loads the specified file and returns its content as String.

Parameters:
file - the path to the file to load.
Returns:
the content of the file.
Throws:
Exception - if an I/O error occurs.

loadFile

public static String loadFile(File file)
                       throws Exception
Loads the specified file and returns its content as String. The default platform character encoding will be used for this operation.

Parameters:
file - the file to load.
Returns:
the content of the file.
Throws:
Exception - if an I/O error occurs.

loadFile

public static String loadFile(File file,
                              String encoding)
                       throws Exception
Loads the specified file and returns its content as String. The specified character encoding will be used for this operation.

Parameters:
file - the file to load.
encoding - the name of the encoding to use, if this is null the platform default encoding will be used.
Returns:
the content of the file.
Throws:
Exception - if an I/O error occurs.

readInputStream

public static byte[] readInputStream(InputStream is)
                              throws IOException
Reads the provided input stream and returns it as an array of bytes. This method does not invoke the close() method on the provided InputStream object.

Parameters:
is - the input stream to read
Returns:
the bites from the input stream.
Throws:
IOException - if reading error occurs.

delete

public static void delete(File file,
                          Log log)
Simply calls the delete() method of the provided file object. Additionally the returned value is checked and logged if the file could not be deleted.

Parameters:
file - the file to delete
log -
Throws:
IllegalArgumentException - - if either of the parameters is null or the specified file does not exists.
SecurityException - if the file could not be deleted.

delete

public static void delete(String path,
                          Log log)
Simply calls the delete() method of the provided file object. Additionally the returned value is checked and logged if the file could not be deleted.

Parameters:
path - the file to delete
log -
Throws:
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the file could not be deleted.
NullPointerException - if the provided path argument is null.

mkdirs

public static void mkdirs(File file,
                          Log log)
Simply calls the mkdirs() method of the provided file object. Additionally the returned value is checked and logged if the directories could not be created.

Parameters:
file - the directory to create
log -
Throws:
IllegalArgumentException - - if either of the parameters is null
SecurityException - if the directories could not be created

mkdirs

public static void mkdirs(String path,
                          Log log)
Simply calls the mkdirs() method of the provided file object. Additionally the returned value is checked and logged if the directories could not be created.

Parameters:
path - the directory to create
log -
Throws:
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the directories could not be created
NullPointerException - if the provided path argument is null.

mkdir

public static void mkdir(File file,
                         Log log)
Simply calls the mkdir() method of the provided file object. Additionally the returned value is checked and logged if the directory could not be created.

Parameters:
file - the directory to create
log -
Throws:
IllegalArgumentException - - if either of the parameters is null
SecurityException - if the directories could not be created

mkdir

public static void mkdir(String path,
                         Log log)
Simply calls the mkdir() method of the provided file object. Additionally the returned value is checked and logged if the directories could not be created.

Parameters:
path - the directory to create
log -
Throws:
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the directory could not be created
NullPointerException - if the provided path argument is null.

renameTo

public static void renameTo(File from,
                            File to,
                            Log log)
Simply calls the renameTo() method of the provided file object. Additionally the returned value is checked and logged if the file could not be renamed.

Parameters:
from - the file to rename
to - the name of the file to set
log -
Throws:
IllegalArgumentException - - if either of the parameters is null or the specified file does not renamed.
SecurityException - if the file could not be deleted.

renameTo

public static void renameTo(String from,
                            String to,
                            Log log)
Simply calls the renameTo() method of the provided file object. Additionally the returned value is checked and logged if the file could not be renamed.

Parameters:
from - the file to rename
to - the name of the file to set
log -
Throws:
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the file could not be renamed.
NullPointerException - if the provided path argument is null.

delete

public static void delete(File file)
                   throws Exception
Simply calls the delete() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the file could not be deleted.

Parameters:
file - the file to delete
Throws:
Exception - if the file cannot be deleted.
IllegalArgumentException - - if either of the parameters is null or the specified file does not exists.
SecurityException - if the file could not be deleted.

deleteRecursively

public static void deleteRecursively(File toDelete)
                              throws Exception
Deletes the provided File. If the File denotes a directory it will be deleted recursively whit all of the files it contains. Additionally the returned value is checked and an exception is thrown if the file could not be deleted.

Parameters:
file - the file to delete
Throws:
Exception - if the file cannot be deleted.
IllegalArgumentException - - if either of the parameters is null or the specified file does not exists.
SecurityException - if the file could not be deleted.

deleteRecursively

public static void deleteRecursively(String toDelete)
                              throws Exception
Convenience method that delegates to deleteRecursively(File).

Parameters:
toDelete - the file to delete
Throws:
Exception - if the file cannot be deleted.

delete

public static void delete(String path)
                   throws Exception
Simply calls the delete() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the file could not be deleted.

Parameters:
path - the file to delete
Throws:
Exception - if the file could not be deleted.
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the file could not be deleted.
NullPointerException - if the provided path argument is null.

mkdirs

public static void mkdirs(File file)
                   throws Exception
Simply calls the mkdirs() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the directories could not be created.

Parameters:
file - the directory to create
Throws:
Exception - if the directories could not be created.
IllegalArgumentException - - if either of the parameters is null
SecurityException - if the directories could not be created

mkdirs

public static void mkdirs(String path)
                   throws Exception
Simply calls the mkdirs() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the directories could not be created.

Parameters:
path - the directory to create
Throws:
Exception - if the directories could not be created.
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the directories could not be created
NullPointerException - if the provided path argument is null.

mkdir

public static void mkdir(File file)
                  throws Exception
Simply calls the mkdir() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the directory could not be created.

Parameters:
file - the directory to create
Throws:
Exception - if the directory could not be created.
IllegalArgumentException - - if either of the parameters is null
SecurityException - if the directories could not be created

mkdir

public static void mkdir(String path)
                  throws Exception
Simply calls the mkdir() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the directories could not be created.

Parameters:
path - the directory to create
Throws:
Exception
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the directory could not be created
NullPointerException - if the provided path argument is null.

renameTo

public static void renameTo(File from,
                            File to)
                     throws Exception
Simply calls the renameTo() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the file could not be renamed.

Parameters:
from - the file to rename
to - the name of the file to set
Throws:
Exception - if the file could not be renamed.
IllegalArgumentException - - if either of the parameters is null or the specified file does not renamed.
SecurityException - if the file could not be renamed.

renameTo

public static void renameTo(String from,
                            String to)
                     throws Exception
Simply calls the renameTo() method of the provided file object. Additionally the returned value is checked and an exception is thrown if the file could not be renamed.

Parameters:
from - the file to rename
to - the name of the file to set
Throws:
Exception - if the file could not be renamed.
IllegalArgumentException - - if either of the parameters is null.
SecurityException - if the file could not be renamed.
NullPointerException - if the provided path argument is null.

copyFile

public static boolean copyFile(String fromPath,
                               String toPath,
                               boolean overwrite)
                        throws Exception
Copy file. This method copies fromPath to toPath. The overwrite flag specifies whether the destination file should be overwritten. This method is called by com.ibm.di.function.UserFunctions.copyFile(String, String, boolean) method.

Parameters:
fromPath - The source file
toPath - The destination file
overwrite - Specify true if destination should be overwritten.
Returns:
true if file was copied, false if toPath exists and overwrite=false.
Throws:
Exception

copyFile

public static boolean copyFile(File fromFile,
                               File toFile,
                               boolean overwrite)
                        throws Exception
Copy file. This method copies fromPath to toPath. The overwrite flag specifies whether the destination file should be overwritten. This method is called by com.ibm.di.function.UserFunctions.copyFile(File, File, boolean) method.

Parameters:
fromFile - The source file
toFile - The destination file
overwrite - Specify true if destination should be overwritten.
Returns:
true if file was copied, false if toPath exists and overwrite=false.
Throws:
Exception