ch.javasoft.jbase
Interface RandomAccessPersister

All Superinterfaces:
Stateful
All Known Implementing Classes:
BufferedRandomAccessPersister, RandomAccessFilePersistor

public interface RandomAccessPersister
extends Stateful

Abstraction of storage which can be accessed randomly, such as RandomAccessFiles.

Random access of a storage device means setting a byte offset, and reading or writing at this offset position in the sequal.


Method Summary
 void close(boolean erase)
          Closes this persistor, subsequent read or write calls will cause an exception.
 RandomAccessPersister createReadCopy(ReadWriteLock lock)
          Override to specialize return type
 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.
 

Method Detail

getPosition

long getPosition()
                 throws IOException
Returns the current byte position. Note that any read or write operation increments the position.

Throws:
IOException

setPosition

void setPosition(long bytePos)
                 throws IOException
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.

Throws:
IOException

setLength

void setLength(long byteLength)
               throws IOException
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.

Throws:
IOException

getInput

DataInput getInput()
                   throws IOException
Returns a data input object to read from. Read operations increment the current byte position

Throws:
IOException

getOutput

DataOutput getOutput()
                     throws IOException
Returns a data input object to write to. Write operations increment the current byte position

Throws:
IOException

flush

void flush()
           throws IOException
Ensures that any possibly cached data is written to the underlying store

Throws:
IOException

close

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

Parameters:
erase - if true, underlying files are deleted upon close
Throws:
IOException

createReadCopy

RandomAccessPersister createReadCopy(ReadWriteLock lock)
                                     throws IOException
Override to specialize return type

Specified by:
createReadCopy in interface Stateful
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)