edu.northwestern.at.utils

## Class BufferedRandomAccessFile

- java.lang.Object
- - edu.northwestern.at.utils.BufferedRandomAccessFile

- All Implemented Interfaces:
    java.io.DataInput, java.io.DataOutput

      public class BufferedRandomAccessFile
      extends java.lang.Object
      implements java.io.DataInput, java.io.DataOutput

  Extension fo the RandomAccessFile to use buffered I/O as much as possible. Usable with the `com.objectwave.persist.FileBroker` . Publically identical to `java.io.RandomAccessFile` , except for the constuctor and `flush()` .

  Note: This class is not threadsafe.

  Version:
    $Date: 2005/02/20 17:27:32 $ $Revision: 2.3 $
  Author:
    Steven Sinclair
  See Also:
    `

    Modifications by Philip R. Burns. 2007/05/08.

    `

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `BufferedRandomAccessFile.FileBufferStruct`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected BufferedRandomAccessFile.FileBufferStruct` | `altBuf`
    `protected BufferedRandomAccessFile.FileBufferStruct` | `currBuf`
    `(package private) java.io.RandomAccessFile` | `delegate`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BufferedRandomAccessFile(java.io.File file, java.lang.String mode)` Constructor for the BufferedRandomAccessFile object
    `` | `BufferedRandomAccessFile(java.io.File file, java.lang.String mode, int bufferSize)` Constructor for the BufferedRandomAccessFile object

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Description of the Method
    `protected void` | `commitBuffer()` If modified, write buffered bytes to the delegate file
    `protected void` | `fillBuffer()` Description of the Method
    `void` | `flush()` Description of the Method
    `java.io.FileDescriptor` | `getFD()` Gets the FD attribute of the BufferedRandomAccessFile object
    `long` | `getFilePointer()` Gets the FilePointer attribute of the BufferedRandomAccessFile object
    `java.io.Reader` | `getReader()` Gets the Reader attribute of the BufferedRandomAccessFile object
    `java.io.Writer` | `getWriter()` Gets the Writer attribute of the BufferedRandomAccessFile object
    `long` | `length()` Description of the Method
    `int` | `read()` Description of the Method
    `int` | `read(byte[] b)` Description of the Method
    `int` | `read(byte[] b, int pos, int len)` Description of the Method
    `boolean` | `readBoolean()` Description of the Method
    `byte` | `readByte()` Description of the Method
    `char` | `readChar()` Description of the Method
    `double` | `readDouble()` Description of the Method
    `float` | `readFloat()` Description of the Method
    `void` | `readFully(byte[] b)` Description of the Method
    `void` | `readFully(byte[] b, int pos, int len)` Description of the Method
    `int` | `readInt()` Description of the Method
    `java.lang.String` | `readLine()` Description of the Method
    `long` | `readLong()` Description of the Method
    `short` | `readShort()` Description of the Method
    `int` | `readUnsignedByte()` Description of the Method
    `int` | `readUnsignedShort()` Description of the Method
    `java.lang.String` | `readUTF()` Description of the Method
    `void` | `seek(long pos)` Description of the Method
    `void` | `setLength(long newLength)` Sets the Length attribute of the BufferedRandomAccessFile object
    `int` | `skipBytes(int n)` Description of the Method
    `long` | `skipBytes(long n)` Description of the Method
    `protected int` | `syncBuffer(long new_FP)` Save any changes and re-read the currBuf.bytes from the given position.
    `void` | `write(byte[] b)` Description of the Method
    `void` | `write(byte[] b, int pos, int len)` Description of the Method
    `void` | `write(int b)` Description of the Method
    `void` | `writeBoolean(boolean b)` Description of the Method
    `void` | `writeByte(int b)` Description of the Method
    `void` | `writeBytes(java.lang.String s)` Description of the Method
    `void` | `writeChar(int ch)` Description of the Method
    `void` | `writeChars(java.lang.String s)` Description of the Method
    `void` | `writeDouble(double f)` Description of the Method
    `void` | `writeFloat(float f)` Description of the Method
    `void` | `writeInt(int i)` Description of the Method
    `void` | `writeLong(long l)` Description of the Method
    `void` | `writeShort(int s)` Description of the Method
    `void` | `writeUTF(java.lang.String str)` Description of the Method

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### currBuf

          protected BufferedRandomAccessFile.FileBufferStruct currBuf

    - #### altBuf

          protected BufferedRandomAccessFile.FileBufferStruct altBuf

    - #### delegate

          java.io.RandomAccessFile delegate

  - ### Constructor Detail

    - #### BufferedRandomAccessFile

          public BufferedRandomAccessFile(java.io.File file,
                                  java.lang.String mode,
                                  int bufferSize)
                                   throws java.io.IOException

      Constructor for the BufferedRandomAccessFile object
      Parameters:
        `file` - Description of Parameter
        `mode` - Description of Parameter
        `bufferSize` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### BufferedRandomAccessFile

          protected BufferedRandomAccessFile(java.io.File file,
                                  java.lang.String mode)
                                      throws java.io.IOException

      Constructor for the BufferedRandomAccessFile object
      Parameters:
        `file` - Description of Parameter
        `mode` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

  - ### Method Detail

    - #### setLength

          public void setLength(long newLength)
                         throws java.io.IOException

      Sets the Length attribute of the BufferedRandomAccessFile object
      Parameters:
        `newLength` - The new Length value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### getReader

          public java.io.Reader getReader()

      Gets the Reader attribute of the BufferedRandomAccessFile object
      Returns:
        The Reader value

    - #### getWriter

          public java.io.Writer getWriter()

      Gets the Writer attribute of the BufferedRandomAccessFile object
      Returns:
        The Writer value

    - #### getFD

          public java.io.FileDescriptor getFD()
                                       throws java.io.IOException

      Gets the FD attribute of the BufferedRandomAccessFile object
      Returns:
        The FD value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### getFilePointer

          public long getFilePointer()

      Gets the FilePointer attribute of the BufferedRandomAccessFile object
      Returns:
        The FilePointer value

    - #### readBoolean

          public boolean readBoolean()
                              throws java.io.IOException

      Description of the Method
      Specified by:
        `readBoolean` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readUnsignedByte

          public int readUnsignedByte()
                               throws java.io.IOException

      Description of the Method
      Specified by:
        `readUnsignedByte` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readByte

          public byte readByte()
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `readByte` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readShort

          public short readShort()
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `readShort` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readUnsignedShort

          public int readUnsignedShort()
                                throws java.io.IOException

      Description of the Method
      Specified by:
        `readUnsignedShort` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readChar

          public char readChar()
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `readChar` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readInt

          public int readInt()
                      throws java.io.IOException

      Description of the Method
      Specified by:
        `readInt` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readLong

          public long readLong()
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `readLong` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readFloat

          public float readFloat()
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `readFloat` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readDouble

          public double readDouble()
                            throws java.io.IOException

      Description of the Method
      Specified by:
        `readDouble` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readLine

          public java.lang.String readLine()
                                    throws java.io.IOException

      Description of the Method
      Specified by:
        `readLine` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readUTF

          public java.lang.String readUTF()
                                   throws java.io.IOException

      Description of the Method
      Specified by:
        `readUTF` in interface `java.io.DataInput`
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeBoolean

          public void writeBoolean(boolean b)
                            throws java.io.IOException

      Description of the Method
      Specified by:
        `writeBoolean` in interface `java.io.DataOutput`
      Parameters:
        `b` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeByte

          public void writeByte(int b)
                         throws java.io.IOException

      Description of the Method
      Specified by:
        `writeByte` in interface `java.io.DataOutput`
      Parameters:
        `b` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeShort

          public void writeShort(int s)
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `writeShort` in interface `java.io.DataOutput`
      Parameters:
        `s` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeChar

          public void writeChar(int ch)
                         throws java.io.IOException

      Description of the Method
      Specified by:
        `writeChar` in interface `java.io.DataOutput`
      Parameters:
        `ch` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeInt

          public void writeInt(int i)
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `writeInt` in interface `java.io.DataOutput`
      Parameters:
        `i` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeLong

          public void writeLong(long l)
                         throws java.io.IOException

      Description of the Method
      Specified by:
        `writeLong` in interface `java.io.DataOutput`
      Parameters:
        `l` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeFloat

          public void writeFloat(float f)
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `writeFloat` in interface `java.io.DataOutput`
      Parameters:
        `f` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeDouble

          public void writeDouble(double f)
                           throws java.io.IOException

      Description of the Method
      Specified by:
        `writeDouble` in interface `java.io.DataOutput`
      Parameters:
        `f` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeUTF

          public void writeUTF(java.lang.String str)
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `writeUTF` in interface `java.io.DataOutput`
      Parameters:
        `str` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readFully

          public void readFully(byte[] b)
                         throws java.io.IOException

      Description of the Method
      Specified by:
        `readFully` in interface `java.io.DataInput`
      Parameters:
        `b` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### readFully

          public void readFully(byte[] b,
                       int pos,
                       int len)
                         throws java.io.IOException

      Description of the Method
      Specified by:
        `readFully` in interface `java.io.DataInput`
      Parameters:
        `b` - Description of Parameter
        `pos` - Description of Parameter
        `len` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeBytes

          public void writeBytes(java.lang.String s)
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `writeBytes` in interface `java.io.DataOutput`
      Parameters:
        `s` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### writeChars

          public void writeChars(java.lang.String s)
                          throws java.io.IOException

      Description of the Method
      Specified by:
        `writeChars` in interface `java.io.DataOutput`
      Parameters:
        `s` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### length

          public long length()
                      throws java.io.IOException

      Description of the Method
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### read

          public int read()
                   throws java.io.IOException

      Description of the Method
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### read

          public int read(byte[] b)
                   throws java.io.IOException

      Description of the Method
      Parameters:
        `b` - Description of Parameter
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### read

          public int read(byte[] b,
                 int pos,
                 int len)
                   throws java.io.IOException

      Description of the Method
      Parameters:
        `b` - Description of Parameter
        `pos` - Description of Parameter
        `len` - Description of Parameter
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### seek

          public void seek(long pos)
                    throws java.io.IOException

      Description of the Method
      Parameters:
        `pos` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### skipBytes

          public int skipBytes(int n)
                        throws java.io.IOException

      Description of the Method
      Specified by:
        `skipBytes` in interface `java.io.DataInput`
      Parameters:
        `n` - Description of Parameter
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### skipBytes

          public long skipBytes(long n)
                         throws java.io.IOException

      Description of the Method
      Parameters:
        `n` - Description of Parameter
      Returns:
        Description of the Returned Value
      Throws:
        `java.io.IOException` - Description of Exception

    - #### write

          public void write(byte[] b)
                     throws java.io.IOException

      Description of the Method
      Specified by:
        `write` in interface `java.io.DataOutput`
      Parameters:
        `b` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### write

          public void write(byte[] b,
                   int pos,
                   int len)
                     throws java.io.IOException

      Description of the Method
      Specified by:
        `write` in interface `java.io.DataOutput`
      Parameters:
        `b` - Description of Parameter
        `pos` - Description of Parameter
        `len` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### write

          public void write(int b)
                     throws java.io.IOException

      Description of the Method
      Specified by:
        `write` in interface `java.io.DataOutput`
      Parameters:
        `b` - Description of Parameter
      Throws:
        `java.io.IOException` - Description of Exception

    - #### flush

          public void flush()
                     throws java.io.IOException

      Description of the Method
      Throws:
        `java.io.IOException` - Description of Exception

    - #### close

          public void close()
                     throws java.io.IOException

      Description of the Method
      Throws:
        `java.io.IOException` - Description of Exception

    - #### syncBuffer

          protected int syncBuffer(long new_FP)
                            throws java.io.IOException

      Save any changes and re-read the currBuf.bytes from the given position. Note that the read(byte[],int,int) method assumes that this method sets currBuf.pos to 0.
      Parameters:
        `new_FP` - Description of Parameter
      Returns:
        int - the number of bytes available for reading
      Throws:
        `java.io.IOException` - Description of Exception

    - #### fillBuffer

          protected void fillBuffer()
                             throws java.io.IOException

      Description of the Method
      Throws:
        `java.io.IOException` - Description of Exception

    - #### commitBuffer

          protected void commitBuffer()
                               throws java.io.IOException

      If modified, write buffered bytes to the delegate file
      Throws:
        `java.io.IOException` - Description of Exception