ch.javasoft.jbase
Class RandomAccessFilePersistor

java.lang.Object
  extended by ch.javasoft.jbase.RandomAccessFilePersistor
All Implemented Interfaces:
Stateful, RandomAccessPersister

public class RandomAccessFilePersistor
extends Object
implements RandomAccessPersister

The RandomAccessFilePersistor implements RandomAccessPersister using RandomAccessFiles.


Constructor Summary
  RandomAccessFilePersistor(File file)
           
protected RandomAccessFilePersistor(File file, RandomAccessFile raf)
           
  RandomAccessFilePersistor(File folder, String fileName)
           
 
Method Summary
 void close(boolean erase)
          Closes this persistor, subsequent read or write calls will cause an exception.
 RandomAccessFilePersistor createReadCopy(ReadWriteLock lock)
          Returns a copy of this persistor for read access.
 void flush()
          Ensures that any possibly cached data is written to the underlying store
 DataInput getInput()
          Returns a data input object to read from.
 DataOutput getOutput()
          Returns a data input object to write to.
 long getPosition()
          Returns the current byte position.
 void setLength(long byteLength)
          Sets the length of the storage.
 void setPosition(long bytePos)
          Sets the byte offset position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessFilePersistor

public RandomAccessFilePersistor(File folder,
                                 String fileName)
                          throws FileNotFoundException
Throws:
FileNotFoundException

RandomAccessFilePersistor

public RandomAccessFilePersistor(File file)
                          throws FileNotFoundException
Throws:
FileNotFoundException

RandomAccessFilePersistor

protected RandomAccessFilePersistor(File file,
                                    RandomAccessFile raf)
                             throws FileNotFoundException
Throws:
FileNotFoundException
Method Detail

getPosition

public long getPosition()
                 throws IOException
Description copied from interface: RandomAccessPersister
Returns the current byte position. Note that any read or write operation increments the position.

Specified by:
getPosition in interface RandomAccessPersister
Throws:
IOException

setPosition

public void setPosition(long bytePos)
                 throws IOException
Description copied from interface: RandomAccessPersister
Sets the byte offset position. Subsequent read or write operations start at the specified position, even if it is after the actual length of the file or store. However, the length does not change before actually writing at this position.

Specified by:
setPosition in interface RandomAccessPersister
Throws:
IOException

setLength

public void setLength(long byteLength)
               throws IOException
Description copied from interface: RandomAccessPersister
Sets the length of the storage. If this is shorter than the current length, the data will be truncated. If it is after the current length, additional data is appended, but its content is undefined.

Specified by:
setLength in interface RandomAccessPersister
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: RandomAccessPersister
Ensures that any possibly cached data is written to the underlying store

Specified by:
flush in interface RandomAccessPersister
Throws:
IOException

close

public void close(boolean erase)
           throws IOException
Description copied from interface: RandomAccessPersister
Closes this persistor, subsequent read or write calls will cause an exception. Multiple close calls, however, do not cause any exceptions.

Specified by:
close in interface RandomAccessPersister
Parameters:
erase - if true, underlying files are deleted upon close
Throws:
IOException

getInput

public DataInput getInput()
                   throws IOException
Description copied from interface: RandomAccessPersister
Returns a data input object to read from. Read operations increment the current byte position

Specified by:
getInput in interface RandomAccessPersister
Throws:
IOException

getOutput

public DataOutput getOutput()
                     throws IOException
Description copied from interface: RandomAccessPersister
Returns a data input object to write to. Write operations increment the current byte position

Specified by:
getOutput in interface RandomAccessPersister
Throws:
IOException

createReadCopy

public RandomAccessFilePersistor createReadCopy(ReadWriteLock lock)
                                         throws IOException
Returns a copy of this persistor for read access. The new reader is opened and the position is set to this persistor's position. The returned instance does not support write operations, thus, invoking getOutput() or setLength(long) causes an UnsupportedOperationException.

Specified by:
createReadCopy in interface Stateful
Specified by:
createReadCopy in interface RandomAccessPersister
Parameters:
lock - A read/write lock, the write lock is held. The lock, however, might also be used for other functionality of the returned read copy, for instance, if the read copy has to be put in sync with the main object.
Returns:
a new read copy instance, with copied state compared to other read copy instances
Throws:
IOException
See Also:
Stateful.createReadCopy(ReadWriteLock)