ie.tomallen.utils
Class FileHandler

java.lang.Object
  |
  +--java.io.File
        |
        +--ie.tomallen.utils.FileHandler
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class FileHandler
extends java.io.File

Implements a FileHandler object, to read and write files. Dependencies: java.io.File, java.io.RandomAccessFile, java.io.FileReader

Version:
0.2
Author:
Tom Allen
See Also:
Serialized Form

Field Summary
 java.lang.String filename
          filename of file handled by this object.
 long length
          number of bytes in file.
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
FileHandler(java.io.File filep)
          Constructor.
FileHandler(java.lang.String filename)
          Constructor.
 
Method Summary
 boolean isValid()
          read.
 java.lang.String read(long offset, long length)
          read.
 java.lang.String readFile()
          readFile, reads a entire file and returns a string.
 int write(java.lang.String str, boolean append)
          write.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

length

public long length
number of bytes in file.


filename

public java.lang.String filename
filename of file handled by this object.

Constructor Detail

FileHandler

public FileHandler(java.lang.String filename)
            throws TException
Constructor. opens files and setups the public class variables.

Parameters:
filename - String name of filename
Throws:
TException, - whether an file is found to be a directory or does not exist.
TException

FileHandler

public FileHandler(java.io.File filep)
            throws TException
Constructor. opens files and setups the public class variables.

Throws:
TException, - whether an file is found to be a directory or does not exist.
TException
Method Detail

isValid

public boolean isValid()
read.

Returns:
String str

readFile

public java.lang.String readFile()
                          throws TException
readFile, reads a entire file and returns a string. The string only contains up to the first NULL, so this method should not be used for binary files

Returns:
String str
Throws:
TException

read

public java.lang.String read(long offset,
                             long length)
                      throws TException
read.

Parameters:
offset - int
Returns:
String str
Throws:
TException

write

public int write(java.lang.String str,
                 boolean append)
          throws TException
write. The TestObject PostCheck when the Autotest finishes.

Parameters:
str - The string to write to file
append - boolean if..
  • true, append at the end of file, created if does not exist
  • false, deleted if exists, write to file
Returns:
int returns 0 for success, 1 for IOException
TException