net.metanotion.io
Class ByteCordRandomAccess

java.lang.Object
  extended by net.metanotion.io.ByteCordRandomAccess
All Implemented Interfaces:
Closeable, Flushable, InputStream, OutputStream, RandomAccess

public final class ByteCordRandomAccess
extends Object
implements RandomAccess


Constructor Summary
ByteCordRandomAccess()
           
ByteCordRandomAccess(byte[] initial)
           
 
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()
           
 ByteCord getBytes()
           
 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 fp)
           
 void replaceCord(ByteCord b)
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteCordRandomAccess

public ByteCordRandomAccess()

ByteCordRandomAccess

public ByteCordRandomAccess(byte[] initial)
Method Detail

replaceCord

public void replaceCord(ByteCord b)

getBytes

public ByteCord getBytes()

getFilePointer

public long getFilePointer()
Specified by:
getFilePointer in interface RandomAccess

seek

public void seek(long pos)
Specified by:
seek in interface RandomAccess

length

public long length()
Specified by:
length in interface OutputStream
Specified by:
length in interface RandomAccess

setLength

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

close

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

flush

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

read

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

read

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

read

public 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
Specified by:
read in interface RandomAccess
Returns:
Next byte in the input stream.

atEOF

public boolean atEOF()
Specified by:
atEOF in interface InputStream
Specified by:
atEOF in interface RandomAccess

skip

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

write

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

write

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

write

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

supportsAtomicAppend

public boolean supportsAtomicAppend()
Description copied from interface: RandomAccess
Determine whether this file supports atomic appends.

Specified by:
supportsAtomicAppend in interface RandomAccess
Returns:
true if appends to the file are atomic, false otherwise.

append

public long append(byte[] b)
Description copied from interface: RandomAccess
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.

Specified by:
append in interface RandomAccess
Returns:
The offset in the file the array of bytes was appended at.

readAtOffset

public int readAtOffset(byte[] b,
                        long fp)
Specified by:
readAtOffset in interface RandomAccess