com.ibm.di.util
Class FileUtils

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

public class FileUtils
extends java.lang.Object

Utility class used for file manipulation operations.


Constructor Summary
FileUtils()
           
 
Method Summary
static void delete(java.io.File file)
          Simply calls the delete() method of the provided file object.
static void delete(java.io.File file, Log log)
          Simply calls the delete() method of the provided file object.
static void delete(java.lang.String path)
          Simply calls the delete() method of the provided file object.
static void delete(java.lang.String path, Log log)
          Simply calls the delete() method of the provided file object.
static java.lang.String loadFile(java.io.File file)
          Loads the specified file and returns its content as String.
static java.lang.String loadFile(java.io.File file, java.lang.String encoding)
          Loads the specified file and returns its content as String.
static java.lang.String loadFile(java.lang.String file)
          Loads the specified file and returns its content as String.
static void mkdir(java.io.File file)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(java.io.File file, Log log)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(java.lang.String path)
          Simply calls the mkdir() method of the provided file object.
static void mkdir(java.lang.String path, Log log)
          Simply calls the mkdir() method of the provided file object.
static void mkdirs(java.io.File file)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(java.io.File file, Log log)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(java.lang.String path)
          Simply calls the mkdirs() method of the provided file object.
static void mkdirs(java.lang.String path, Log log)
          Simply calls the mkdirs() method of the provided file object.
static byte[] readInputStream(java.io.InputStream is)
          Reads the provided input stream and returns it as an array of bytes.
static void renameTo(java.io.File from, java.io.File to)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(java.io.File from, java.io.File to, Log log)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(java.lang.String from, java.lang.String to)
          Simply calls the renameTo() method of the provided file object.
static void renameTo(java.lang.String from, java.lang.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 java.lang.String loadFile(java.lang.String file)
                                 throws java.lang.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:
java.lang.Exception - if an I/O error occurs.

loadFile

public static java.lang.String loadFile(java.io.File file)
                                 throws java.lang.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:
java.lang.Exception - if an I/O error occurs.

loadFile

public static java.lang.String loadFile(java.io.File file,
                                        java.lang.String encoding)
                                 throws java.lang.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:
java.lang.Exception - if an I/O error occurs.

readInputStream

public static byte[] readInputStream(java.io.InputStream is)
                              throws java.io.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:
java.io.IOException - if reading error occurs.

delete

public static void delete(java.io.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:
java.lang.IllegalArgumentException - - if either of the parameters is null or the specified file does not exists.
java.lang.SecurityException - if the file could not be deleted.

delete

public static void delete(java.lang.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:
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the file could not be deleted.
java.lang.NullPointerException - if the provided path argument is null.

mkdirs

public static void mkdirs(java.io.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:
java.lang.IllegalArgumentException - - if either of the parameters is null
java.lang.SecurityException - if the directories could not be created

mkdirs

public static void mkdirs(java.lang.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:
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the directories could not be created
java.lang.NullPointerException - if the provided path argument is null.

mkdir

public static void mkdir(java.io.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:
java.lang.IllegalArgumentException - - if either of the parameters is null
java.lang.SecurityException - if the directories could not be created

mkdir

public static void mkdir(java.lang.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:
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the directory could not be created
java.lang.NullPointerException - if the provided path argument is null.

renameTo

public static void renameTo(java.io.File from,
                            java.io.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:
java.lang.IllegalArgumentException - - if either of the parameters is null or the specified file does not renamed.
java.lang.SecurityException - if the file could not be deleted.

renameTo

public static void renameTo(java.lang.String from,
                            java.lang.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:
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the file could not be renamed.
java.lang.NullPointerException - if the provided path argument is null.

delete

public static void delete(java.io.File file)
                   throws java.lang.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:
java.lang.Exception - if the file cannot be deleted.
java.lang.IllegalArgumentException - - if either of the parameters is null or the specified file does not exists.
java.lang.SecurityException - if the file could not be deleted.

delete

public static void delete(java.lang.String path)
                   throws java.lang.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:
java.lang.Exception - if the file could not be deleted.
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the file could not be deleted.
java.lang.NullPointerException - if the provided path argument is null.

mkdirs

public static void mkdirs(java.io.File file)
                   throws java.lang.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:
java.lang.Exception - if the directories could not be created.
java.lang.IllegalArgumentException - - if either of the parameters is null
java.lang.SecurityException - if the directories could not be created

mkdirs

public static void mkdirs(java.lang.String path)
                   throws java.lang.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:
java.lang.Exception - if the directories could not be created.
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the directories could not be created
java.lang.NullPointerException - if the provided path argument is null.

mkdir

public static void mkdir(java.io.File file)
                  throws java.lang.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:
java.lang.Exception - if the directory could not be created.
java.lang.IllegalArgumentException - - if either of the parameters is null
java.lang.SecurityException - if the directories could not be created

mkdir

public static void mkdir(java.lang.String path)
                  throws java.lang.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:
java.lang.Exception
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the directory could not be created
java.lang.NullPointerException - if the provided path argument is null.

renameTo

public static void renameTo(java.io.File from,
                            java.io.File to)
                     throws java.lang.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:
java.lang.Exception - if the file could not be renamed.
java.lang.IllegalArgumentException - - if either of the parameters is null or the specified file does not renamed.
java.lang.SecurityException - if the file could not be renamed.

renameTo

public static void renameTo(java.lang.String from,
                            java.lang.String to)
                     throws java.lang.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:
java.lang.Exception - if the file could not be renamed.
java.lang.IllegalArgumentException - - if either of the parameters is null.
java.lang.SecurityException - if the file could not be renamed.
java.lang.NullPointerException - if the provided path argument is null.