GeoSoft API

no.geosoft.cc.io
Class FileAccessor

Object
  |
  +--FileAccessor

public class FileAccessor
extends Object

Base class for file accessors (file readers and writers).

Features:

This class is not abstract as a subclass will overload only one of readFile() and writeFile() depending wether it is a reader or a writer class (it can only be one of the two).

There are some convenience methods for actually accessing the files (readLine() and write()), for more detailed access a reader class will use the reader_/binaryReader_ and a writer will use the writer/binaryWriter_ objects.

Author:
GeoSoft

Nested Class Summary
 class FileAccessor.DefaultLogger
          Dummy logger instance in case none is specified.
 
Constructor Summary
FileAccessor(File file)
          Create a file accessor without a logger.
FileAccessor(File file, FileLogger logger)
          Create a file accessor for the specified file and with the specified logger instance.
 
Method Summary
 long getChecksum()
          Return the checksum for this file.
 Object readFile()
          To be overridden by a file reader class.
 String readLine()
          Read one line from the file.
 void reportProgress()
          Force the progress to be reported to the logger.
 void setLogger(FileLogger logger)
          Set logger.
 void skip(long n)
          Skip n bytes during read.
 void write(String string)
          Write a line to the file.
 void writeFile(Object object)
          To be overridden by a file writer class.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileAccessor

public FileAccessor(File file,
                    FileLogger logger)
Create a file accessor for the specified file and with the specified logger instance.

Parameters:
file - File to create accessor for.
logger - Logger.

FileAccessor

public FileAccessor(File file)
Create a file accessor without a logger.

Parameters:
file - File to create accessor for.
Method Detail

setLogger

public void setLogger(FileLogger logger)
Set logger.

Parameters:
logger - File accessor logger.

getChecksum

public long getChecksum()
Return the checksum for this file.

Returns:
Checksum for this file.

readLine

public String readLine()
                throws IOException
Read one line from the file.

Returns:
Next line from the file (or null if done or an error occured).
IOException

write

public void write(String string)
           throws IOException
Write a line to the file.

Parameters:
string - Line to write.
IOException

skip

public void skip(long n)
          throws IOException
Skip n bytes during read.

Parameters:
n - Number of bytes to skip.
IOException

reportProgress

public void reportProgress()
Force the progress to be reported to the logger.


readFile

public Object readFile()
To be overridden by a file reader class.

Returns:
File content as some java object.

writeFile

public void writeFile(Object object)
To be overridden by a file writer class.

Parameters:
object - Object to write.

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no