com.go.trove.io
Class FileByteBuffer

java.lang.Object
  |
  +--com.go.trove.io.FileByteBuffer
All Implemented Interfaces:
ByteBuffer, ByteData
Direct Known Subclasses:
FileByteBuffer

public class FileByteBuffer
extends java.lang.Object
implements ByteBuffer

A ByteBuffer implementation that can read from an open file or can write to it. This implementation is best suited for temporary byte data that is too large to hold in memory.

Version:
17 5 00/12/05
Author:
Brian S O'Neill

Constructor Summary
FileByteBuffer(java.io.RandomAccessFile file)
          Creates a FileByteBuffer on a RandomAccessFile.
 
Method Summary
 void addCaptureBuffer(ByteBuffer buffer)
          Add a ByteBuffer that will receive a copy of all the data appended to this ByteBuffer.
 void append(byte b)
          Add one byte to the end of this buffer.
 void append(byte[] bytes)
          Copy the given bytes to the end of this buffer.
 void append(byte[] bytes, int offset, int length)
          Copy the given bytes to the end of this buffer, starting at the offset, using the length provided.
 void appendSurrogate(ByteData s)
          Append ByteData that will not be touched until this ByteBuffer needs to calculate its byte count, or it needs to write out.
 long getBaseByteCount()
          Returns the base byte count, which excludes surrogates.
 long getByteCount()
          Return the amount of bytes that will be written by the writeTo method.
 void removeCaptureBuffer(ByteBuffer buffer)
          Remove a capture buffer that was previously added by addCaptureBuffer.
 void reset()
          Reset any transient data stored in this ByteData.
 void writeTo(java.io.OutputStream out)
          Writes all the bytes to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileByteBuffer

public FileByteBuffer(java.io.RandomAccessFile file)
               throws java.io.IOException
Creates a FileByteBuffer on a RandomAccessFile. If the file is opened read-only, then the append operations will fail.
Parameters:
file - The file to use as a buffer.
Method Detail

getBaseByteCount

public long getBaseByteCount()
                      throws java.io.IOException
Description copied from interface: ByteBuffer
Returns the base byte count, which excludes surrogates.
Specified by:
getBaseByteCount in interface ByteBuffer

getByteCount

public long getByteCount()
                  throws java.io.IOException
Description copied from interface: ByteData
Return the amount of bytes that will be written by the writeTo method.
Specified by:
getByteCount in interface ByteData

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Description copied from interface: ByteData
Writes all the bytes to the given OutputStream.
Specified by:
writeTo in interface ByteData

append

public void append(byte b)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Add one byte to the end of this buffer.
Specified by:
append in interface ByteBuffer

append

public void append(byte[] bytes)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Copy the given bytes to the end of this buffer.
Specified by:
append in interface ByteBuffer

append

public void append(byte[] bytes,
                   int offset,
                   int length)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Copy the given bytes to the end of this buffer, starting at the offset, using the length provided.
Specified by:
append in interface ByteBuffer

appendSurrogate

public void appendSurrogate(ByteData s)
                     throws java.io.IOException
Description copied from interface: ByteBuffer
Append ByteData that will not be touched until this ByteBuffer needs to calculate its byte count, or it needs to write out. A null surrogate is not appended.
Specified by:
appendSurrogate in interface ByteBuffer

addCaptureBuffer

public void addCaptureBuffer(ByteBuffer buffer)
Description copied from interface: ByteBuffer
Add a ByteBuffer that will receive a copy of all the data appended to this ByteBuffer.
Specified by:
addCaptureBuffer in interface ByteBuffer

removeCaptureBuffer

public void removeCaptureBuffer(ByteBuffer buffer)
Description copied from interface: ByteBuffer
Remove a capture buffer that was previously added by addCaptureBuffer.
Specified by:
removeCaptureBuffer in interface ByteBuffer

reset

public void reset()
           throws java.io.IOException
Description copied from interface: ByteData
Reset any transient data stored in this ByteData. A call to getByteCount or writeTo will force this data to be restored.
Specified by:
reset in interface ByteData