ProGAL.io
Class IOToolbox

java.lang.Object
  extended by ProGAL.io.IOToolbox

public abstract class IOToolbox
extends java.lang.Object

A wrapper class for static file input/output methods. All of the methods have a policy of not throwing IOExceptions (and similar) if an error occurs. Instead they throw RuntimeExceptions such that try-catch-statements can be excluded if desired. All methods (TODO: Only implemented for writeToFile and readFromFile) supports reading (writing) from (to) gzipped files. This feature is implicitly activated when the specified file name ends with '.gz'.

Author:
R.Fonseca

Constructor Summary
IOToolbox()
           
 
Method Summary
static java.lang.String readFromFile(java.lang.String fName)
          Read the contents of the specified file and return it in a string.
static java.lang.String readFromInternalFile(java.lang.String fName)
          Read the contents of the specified file and return it in a string.
static java.lang.Object readSerializedFile(java.lang.String fName)
          Reads a serialized object from the specified file-name.
static void writeSerializedFile(java.io.Serializable obj, java.lang.String fName)
          Writes a serialized object to the specified file-name.
static void writeToFile(java.lang.String contents, java.lang.String fileName, boolean append)
          Writes a string to the specified file-name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOToolbox

public IOToolbox()
Method Detail

writeToFile

public static void writeToFile(java.lang.String contents,
                               java.lang.String fileName,
                               boolean append)
Writes a string to the specified file-name. If append is true and the file already exists then the contents are appended to the end of the file. If anything goes wrong (e.g. insufficient permissions or bad file-name) a stack-trace is written and a RuntimeException is thrown (so that no try-catch is required). If fileName ends with '.gz' then the file is zipped.


readFromFile

public static java.lang.String readFromFile(java.lang.String fName)
Read the contents of the specified file and return it in a string. If anything goes wrong (e.g. insufficient permissions or bad file-name) a stack-trace is written and a RuntimeException is thrown (so that no try-catch is required). If fileName ends with '.gz' then the file is assumed to be zipped.


readFromInternalFile

public static java.lang.String readFromInternalFile(java.lang.String fName)
                                             throws java.lang.Error
Read the contents of the specified file and return it in a string. This file is assumed to be located within the project, e.g. wrapped in a jar-file with the main method. If something goes wrong (e.g. insufficient permissions or bad file-name) a stack-trace is written and a RuntimeException is thrown (so that no try-catch is required).

Throws:
java.lang.Error

writeSerializedFile

public static void writeSerializedFile(java.io.Serializable obj,
                                       java.lang.String fName)
Writes a serialized object to the specified file-name. If something goes wrong (e.g. insufficient permissions or bad file-name) a stack-trace is written and a RuntimeException is thrown (so that no try-catch is required).


readSerializedFile

public static java.lang.Object readSerializedFile(java.lang.String fName)
Reads a serialized object from the specified file-name. If something goes wrong (e.g. insufficient permissions or bad file-name) a stack-trace is written and a RuntimeException is thrown (so that no try-catch is required).