uk.org.ogsadai.common
Class FileUtilities

java.lang.Object
  |
  +--uk.org.ogsadai.common.FileUtilities

public class FileUtilities
extends java.lang.Object

Provides utilities for reading, writing and deleting files. Keeps files locked whilst in use, but allows many threads to read from the same file concurrently.


Method Summary
 void closeStreamFromFile(java.lang.String fileName, java.io.InputStream fileDataStream)
          Method closeStreamFromFile.
 void closeStreamToFile(java.lang.String fileName, java.io.OutputStream fileDataStream)
          Method closeStreamToFile.
 void deleteFile(java.lang.String fileName)
          Method deleteFile.
static FileUtilities getInstance()
          Method getInstance.
 java.io.InputStream openStreamFromFile(java.lang.String fileName)
          Method openStreamFromFile.
 java.io.OutputStream openStreamToFile(java.lang.String fileName)
          Method openStreamToFile.
 byte[] readByteArrayFromFile(java.lang.String fileName)
          Method readByteArrayFromFile.
 java.lang.String readStringFromFile(java.lang.String fileName)
          Method readStringFromFile.
 void renameFile(java.lang.String fileName, java.lang.String newFileName)
          Method renameFile.
 void replaceWriteStringToFile(java.lang.String fileName, java.lang.String data)
          Method writeStringToFile.
 void writeByteArrayToFile(java.lang.String fileName, byte[] data)
          Method writeByteArrayToFile.
 void writeStringToFile(java.lang.String fileName, java.lang.String data)
          Method writeStringToFile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static FileUtilities getInstance()
Method getInstance. Gets the singleton instance of the FileUtilities class

Returns:
FileUtilities

readStringFromFile

public java.lang.String readStringFromFile(java.lang.String fileName)
                                    throws CommonUserException,
                                           CommonSystemException
Method readStringFromFile. Reads all the data from a file into a String

Parameters:
fileName -
Returns:
String
Throws:
CommonUserException - if the File does not exist
CommonSystemException

readByteArrayFromFile

public byte[] readByteArrayFromFile(java.lang.String fileName)
                             throws CommonUserException,
                                    CommonSystemException
Method readByteArrayFromFile. Reads all the data from a file into a byte array

Parameters:
fileName -
Returns:
byte[]
Throws:
CommonUserException - if the File does not exist
CommonSystemException

openStreamFromFile

public java.io.InputStream openStreamFromFile(java.lang.String fileName)
                                       throws CommonUserException,
                                              CommonSystemException
Method openStreamFromFile. Opens a stream to read data from a file.

Parameters:
fileName -
Returns:
InputStream
Throws:
CommonUserException - if the File does not exist
CommonSystemException

closeStreamFromFile

public void closeStreamFromFile(java.lang.String fileName,
                                java.io.InputStream fileDataStream)
                         throws CommonSystemException
Method closeStreamFromFile. Closes an open stream (ensures the file referenced is unlocked, etc).

Parameters:
fileDataStream - the input stream returned by openStreamFromFile
fileName - the name of the file
Returns:
void
Throws:
CommonSystemException

writeStringToFile

public void writeStringToFile(java.lang.String fileName,
                              java.lang.String data)
                       throws CommonUserException,
                              CommonSystemException
Method writeStringToFile. Writes a String into a new file

Parameters:
fileName -
data -
Throws:
CommonUserException - if the File already exists
CommonSystemException

replaceWriteStringToFile

public void replaceWriteStringToFile(java.lang.String fileName,
                                     java.lang.String data)
                              throws CommonUserException,
                                     CommonSystemException
Method writeStringToFile. If file exists, replace it Writes a String into a new file

Parameters:
fileName -
data -
Throws:
CommonUserException - if the File already exists
CommonSystemException

writeByteArrayToFile

public void writeByteArrayToFile(java.lang.String fileName,
                                 byte[] data)
                          throws CommonUserException,
                                 CommonSystemException
Method writeByteArrayToFile. Writes a byte array into a new file

Parameters:
fileName -
data -
Throws:
CommonUserException - if the File already exists
CommonSystemException

openStreamToFile

public java.io.OutputStream openStreamToFile(java.lang.String fileName)
                                      throws CommonUserException,
                                             CommonSystemException
Method openStreamToFile. Opens a stream to write data into a new file

Parameters:
fileName -
Returns:
FileOutputStream
Throws:
CommonUserException
CommonSystemException

closeStreamToFile

public void closeStreamToFile(java.lang.String fileName,
                              java.io.OutputStream fileDataStream)
                       throws CommonSystemException
Method closeStreamToFile. Closes an open stream (ensures the file referenced is unlocked, etc).

Parameters:
fileDataStream - the output stream returned by openStreamToFile
fileName - the name of the file
Returns:
void
Throws:
CommonSystemException

deleteFile

public void deleteFile(java.lang.String fileName)
                throws CommonUserException,
                       CommonSystemException
Method deleteFile. Deletes a file.

Parameters:
fileName -
Throws:
CommonUserException - if the file does not exist
CommonSystemException

renameFile

public void renameFile(java.lang.String fileName,
                       java.lang.String newFileName)
                throws CommonUserException,
                       CommonSystemException
Method renameFile. Renames a file.

Parameters:
fileName -
newFileName -
Throws:
CommonUserException - if the file does not exist
CommonSystemException