net.metanotion.io
Interface RandomAccess

All Superinterfaces:
Closeable, Flushable, InputStream, OutputStream
All Known Implementing Classes:
ByteCordRandomAccess, JRandomAccess

public interface RandomAccess
extends Closeable, Flushable, InputStream, OutputStream

An interface for reading and writing a "random access" file. This behaves much like an array of bytes with a cursor(whose position is returned by .length()).


Method Summary
 long append(byte[] b)
          Same as write(byte[] b), except the file pointer is automatically set to the end of the file.
 boolean atEOF()
           
 void close()
           
 void flush()
           
 long getFilePointer()
           
 long length()
           
 byte read()
          Reads the next byte of data from the stream.
 int read(byte[] b)
           
 int read(byte[] b, int offset, int length)
           
 int readAtOffset(byte[] b, long filePointer)
           
 void seek(long pos)
           
 long setLength(long newLength)
           
 long skip(long n)
           
 boolean supportsAtomicAppend()
          Determine whether this file supports atomic appends.
 void write(byte b)
           
 void write(byte[] b)
           
 void write(byte[] b, int offset, int length)
           
 

Method Detail

getFilePointer

long getFilePointer()

seek

void seek(long pos)

length

long length()
Specified by:
length in interface OutputStream

setLength

long setLength(long newLength)
Specified by:
setLength in interface OutputStream

close

void close()
Specified by:
close in interface Closeable
Specified by:
close in interface InputStream
Specified by:
close in interface OutputStream

flush

void flush()
Specified by:
flush in interface Flushable
Specified by:
flush in interface OutputStream

read

int read(byte[] b)
Specified by:
read in interface InputStream

read

int read(byte[] b,
         int offset,
         int length)
Specified by:
read in interface InputStream

read

byte read()
Description copied from interface: InputStream
Reads the next byte of data from the stream. If the end of the stream has been reached, a runtime exception is thrown. This method blocks until data is available or an exception is thrown.

Specified by:
read in interface InputStream
Returns:
Next byte in the input stream.

atEOF

boolean atEOF()
Specified by:
atEOF in interface InputStream

skip

long skip(long n)
Specified by:
skip in interface InputStream

write

void write(byte[] b)
Specified by:
write in interface OutputStream

write

void write(byte[] b,
           int offset,
           int length)
Specified by:
write in interface OutputStream

write

void write(byte b)
Specified by:
write in interface OutputStream

supportsAtomicAppend

boolean supportsAtomicAppend()
Determine whether this file supports atomic appends.

Returns:
true if appends to the file are atomic, false otherwise.

append

long append(byte[] b)
Same as write(byte[] b), except the file pointer is automatically set to the end of the file. If .supportsAtomicAppend() == true, then this write should either succeed with the whole write or completely fail.

Returns:
The offset in the file the array of bytes was appended at.

readAtOffset

int readAtOffset(byte[] b,
                 long filePointer)