org.ibisph.util
Class FileLib

java.lang.Object
  extended by org.ibisph.util.FileLib

public abstract class FileLib
extends java.lang.Object

Abstract library class that provides miscellaneous file helper methods.

Author:
Garth Braithwaite, STG

Constructor Summary
FileLib()
           
 
Method Summary
static boolean createDir(java.io.File file)
          Creates a directory based on the file object.
static boolean createDir(java.lang.String path)
          Creates a directory based on the path.
static boolean createDirAndSave(java.lang.String pathAndFilename, byte[] content)
          Save the contents of the byte array to the specified filename and create any directories needed if they don't already exist.
static boolean delete(java.lang.String filename)
          Deletes the specified file.
static java.lang.String getContent(java.io.File file)
          Gets the contents of the specified file as a string.
static java.lang.String getContent(java.lang.String filename)
          Gets the contents of the specified file as a string.
static int save(java.io.File file, byte[] content)
          Save the contents of the byte array to the specified file.
static int save(java.lang.String filename, byte[] content)
          Save the contents of the byte array to the specified filename.
static int save(java.lang.String filename, java.io.InputStream inputStream)
          Save the contents of the input stream to the specified filename.
static int save(java.lang.String filename, java.lang.String content)
          Save the contents of the string to the specified filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLib

public FileLib()
Method Detail

delete

public static boolean delete(java.lang.String filename)
Deletes the specified file.

Parameters:
filename - relative or explicit Filename and path of the file to be deleted.
Returns:
file.delete() value.

getContent

public static java.lang.String getContent(java.lang.String filename)
                                   throws java.io.IOException
Gets the contents of the specified file as a string.

Parameters:
filename - relative or explicit Filename and path of the file to be opened and read.
Returns:
String representation of the file's contents.
Throws:
java.io.IOException

getContent

public static java.lang.String getContent(java.io.File file)
                                   throws java.io.IOException
Gets the contents of the specified file as a string.

Parameters:
file - File to be opened and read.
Returns:
String representation of the file's contents.
Throws:
java.io.IOException

save

public static int save(java.io.File file,
                       byte[] content)
                throws java.io.IOException
Save the contents of the byte array to the specified file.

Parameters:
file - File to use to write the contents to.
content - Content to be written into the file.
Returns:
Number of bytes written.
Throws:
java.io.IOException - Associated with the file and stream operations.

save

public static int save(java.lang.String filename,
                       byte[] content)
                throws java.io.IOException
Save the contents of the byte array to the specified filename.

Parameters:
filename - relative or explicit filename and path of the file to be opened and written to.
content - Content to be written into the file.
Returns:
Number of bytes written.
Throws:
java.io.IOException - Associated with the file and stream operations.

save

public static int save(java.lang.String filename,
                       java.lang.String content)
                throws java.io.IOException
Save the contents of the string to the specified filename.

Parameters:
filename - relative or explicit filename and path of the file to be opened and written to.
content - Content to be written into the file.
Returns:
Number of bytes written.
Throws:
java.io.IOException - Associated with the file and stream operations.

save

public static int save(java.lang.String filename,
                       java.io.InputStream inputStream)
                throws java.io.IOException
Save the contents of the input stream to the specified filename.

Parameters:
filename - relative or explicit filename and path of the file to be opened and written to.
inputStream - Streamed content to be written into the file.
Returns:
Number of bytes successfully written.
Throws:
java.io.IOException - Associated with the file and stream operations.

createDirAndSave

public static boolean createDirAndSave(java.lang.String pathAndFilename,
                                       byte[] content)
                                throws java.io.IOException
Save the contents of the byte array to the specified filename and create any directories needed if they don't already exist.

Parameters:
pathAndFilename - relative or explicit filename and path of the file to be opened and written to.
content - Content to be written into the file.
Returns:
Number of bytes successfully written.
Throws:
java.io.IOException - Associated with the file and stream operations.

createDir

public static boolean createDir(java.io.File file)
Creates a directory based on the file object.

Parameters:
file - Contains the directory to be created.
Returns:
file.mkdirs. True if and only if the directory was created, along with all necessary parent directories; false otherwise.

createDir

public static boolean createDir(java.lang.String path)
Creates a directory based on the path.

Parameters:
path - Contains the directory path to be created.
Returns:
file.mkdirs. True if and only if the directory was created, along with all necessary parent directories; false otherwise.