net.metanotion.io

## Class RAIFile

- java.lang.Object
- - net.metanotion.io.RAIFile

- All Implemented Interfaces:
    Closeable, DataInput, DataOutput, AutoCloseable, RandomAccessInterface

      public class RAIFile
      extends Object
      implements RandomAccessInterface, DataInput, DataOutput

  Implementation of RandomAccessInterface using RandomAccessFile. Provides file-based random access with DataInput and DataOutput capabilities.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RAIFile(File file, boolean read, boolean write)`
    `RAIFile(RandomAccessFile file)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canWrite()` Is the file writable? (I2P) Only valid if the File constructor was used, not the RAF constructor
    `void` | `close()`
    `long` | `getFilePointer()`
    `long` | `length()`
    `int` | `read()`
    `int` | `read(byte[] b)`
    `int` | `read(byte[] b, int off, int len)`
    `boolean` | `readBoolean()`
    `byte` | `readByte()`
    `char` | `readChar()`
    `double` | `readDouble()`
    `float` | `readFloat()`
    `void` | `readFully(byte[] b)`
    `void` | `readFully(byte[] b, int off, int len)`
    `int` | `readInt()`
    `String` | `readLine()`
    `long` | `readLong()`
    `short` | `readShort()`
    `int` | `readUnsignedByte()`
    `int` | `readUnsignedInt()` Reads an unsigned 32-bit integer from the file.
    `int` | `readUnsignedShort()`
    `String` | `readUTF()` Read a UTF encoded string with 4-byte length prefix.
    `void` | `seek(long pos)`
    `void` | `setLength(long newLength)`
    `int` | `skipBytes(int n)`
    `String` | `toString()`
    `void` | `write(byte[] b)`
    `void` | `write(byte[] b, int off, int len)`
    `void` | `write(int b)`
    `void` | `writeBoolean(boolean v)`
    `void` | `writeByte(int v)`
    `void` | `writeBytes(String s)`
    `void` | `writeChar(int v)`
    `void` | `writeChars(String s)`
    `void` | `writeDouble(double v)`
    `void` | `writeFloat(float v)`
    `void` | `writeInt(int v)`
    `void` | `writeLong(long v)`
    `void` | `writeShort(int v)`
    `void` | `writeUTF(String str)` Write a UTF encoded string with 4-byte length prefix.

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

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

- - ### Constructor Detail

    - #### RAIFile

          public RAIFile(File file,
                         boolean read,
                         boolean write)
                  throws FileNotFoundException

      Parameters:
        `read` - must be true
      Throws:
        `FileNotFoundException`

    - #### RAIFile

          public RAIFile(RandomAccessFile file)
                  throws FileNotFoundException

      Throws:
        `FileNotFoundException`

  - ### Method Detail

    - #### canWrite

          public boolean canWrite()

      Is the file writable? (I2P) Only valid if the File constructor was used, not the RAF constructor
      Specified by:
        `canWrite` in interface `RandomAccessInterface`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### getFilePointer

          public long getFilePointer()
                              throws IOException

      Specified by:
        `getFilePointer` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### length

          public long length()
                      throws IOException

      Specified by:
        `length` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### read

          public int read()
                   throws IOException

      Specified by:
        `read` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### read

          public int read(byte[] b)
                   throws IOException

      Specified by:
        `read` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### read

          public int read(byte[] b,
                          int off,
                          int len)
                   throws IOException

      Specified by:
        `read` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readBoolean

          public boolean readBoolean()
                              throws IOException

      Specified by:
        `readBoolean` in interface `DataInput`
      Specified by:
        `readBoolean` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readByte

          public byte readByte()
                        throws IOException

      Specified by:
        `readByte` in interface `DataInput`
      Specified by:
        `readByte` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readChar

          public char readChar()
                        throws IOException

      Specified by:
        `readChar` in interface `DataInput`
      Specified by:
        `readChar` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readDouble

          public double readDouble()
                            throws IOException

      Specified by:
        `readDouble` in interface `DataInput`
      Specified by:
        `readDouble` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readFloat

          public float readFloat()
                          throws IOException

      Specified by:
        `readFloat` in interface `DataInput`
      Specified by:
        `readFloat` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readFully

          public void readFully(byte[] b)
                         throws IOException

      Specified by:
        `readFully` in interface `DataInput`
      Specified by:
        `readFully` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readFully

          public void readFully(byte[] b,
                                int off,
                                int len)
                         throws IOException

      Specified by:
        `readFully` in interface `DataInput`
      Specified by:
        `readFully` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readInt

          public int readInt()
                      throws IOException

      Specified by:
        `readInt` in interface `DataInput`
      Specified by:
        `readInt` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readLine

          public String readLine()
                          throws IOException

      Specified by:
        `readLine` in interface `DataInput`
      Specified by:
        `readLine` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readLong

          public long readLong()
                        throws IOException

      Specified by:
        `readLong` in interface `DataInput`
      Specified by:
        `readLong` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readShort

          public short readShort()
                          throws IOException

      Specified by:
        `readShort` in interface `DataInput`
      Specified by:
        `readShort` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readUnsignedByte

          public int readUnsignedByte()
                               throws IOException

      Specified by:
        `readUnsignedByte` in interface `DataInput`
      Specified by:
        `readUnsignedByte` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readUnsignedInt

          public int readUnsignedInt()
                              throws IOException

      Reads an unsigned 32-bit integer from the file. (I2P)
      Specified by:
        `readUnsignedInt` in interface `RandomAccessInterface`
      Throws:
        `IOException` - if the read value is negative

    - #### readUnsignedShort

          public int readUnsignedShort()
                                throws IOException

      Specified by:
        `readUnsignedShort` in interface `DataInput`
      Specified by:
        `readUnsignedShort` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### readUTF

          public String readUTF()
                         throws IOException

      Read a UTF encoded string with 4-byte length prefix. (I2P)

      This method uses a 4-byte length prefix instead of Java's standard 2-byte prefix, allowing for strings up to 16MB in length. The upper byte must be zero for compatibility.

      Specified by:
        `readUTF` in interface `DataInput`
      Specified by:
        `readUTF` in interface `RandomAccessInterface`
      Returns:
        the UTF-8 decoded string
      Throws:
        `IOException` - if the length encoding is invalid or EOF is reached

    - #### seek

          public void seek(long pos)
                    throws IOException

      Specified by:
        `seek` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### setLength

          public void setLength(long newLength)
                         throws IOException

      Specified by:
        `setLength` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### skipBytes

          public int skipBytes(int n)
                        throws IOException

      Specified by:
        `skipBytes` in interface `DataInput`
      Specified by:
        `skipBytes` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### write

          public void write(byte[] b)
                     throws IOException

      Specified by:
        `write` in interface `DataOutput`
      Specified by:
        `write` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### write

          public void write(byte[] b,
                            int off,
                            int len)
                     throws IOException

      Specified by:
        `write` in interface `DataOutput`
      Specified by:
        `write` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### write

          public void write(int b)
                     throws IOException

      Specified by:
        `write` in interface `DataOutput`
      Specified by:
        `write` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeBoolean

          public void writeBoolean(boolean v)
                            throws IOException

      Specified by:
        `writeBoolean` in interface `DataOutput`
      Specified by:
        `writeBoolean` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeByte

          public void writeByte(int v)
                         throws IOException

      Specified by:
        `writeByte` in interface `DataOutput`
      Specified by:
        `writeByte` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeBytes

          public void writeBytes(String s)
                          throws IOException

      Specified by:
        `writeBytes` in interface `DataOutput`
      Specified by:
        `writeBytes` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeChar

          public void writeChar(int v)
                         throws IOException

      Specified by:
        `writeChar` in interface `DataOutput`
      Specified by:
        `writeChar` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeChars

          public void writeChars(String s)
                          throws IOException

      Specified by:
        `writeChars` in interface `DataOutput`
      Specified by:
        `writeChars` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeDouble

          public void writeDouble(double v)
                           throws IOException

      Specified by:
        `writeDouble` in interface `DataOutput`
      Specified by:
        `writeDouble` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeFloat

          public void writeFloat(float v)
                          throws IOException

      Specified by:
        `writeFloat` in interface `DataOutput`
      Specified by:
        `writeFloat` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeInt

          public void writeInt(int v)
                        throws IOException

      Specified by:
        `writeInt` in interface `DataOutput`
      Specified by:
        `writeInt` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeLong

          public void writeLong(long v)
                         throws IOException

      Specified by:
        `writeLong` in interface `DataOutput`
      Specified by:
        `writeLong` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeShort

          public void writeShort(int v)
                          throws IOException

      Specified by:
        `writeShort` in interface `DataOutput`
      Specified by:
        `writeShort` in interface `RandomAccessInterface`
      Throws:
        `IOException`

    - #### writeUTF

          public void writeUTF(String str)
                        throws IOException

      Write a UTF encoded string with 4-byte length prefix. (I2P)

      This method uses a 4-byte length prefix instead of Java's standard 2-byte prefix, allowing for strings up to 16MB in length.

      Specified by:
        `writeUTF` in interface `DataOutput`
      Specified by:
        `writeUTF` in interface `RandomAccessInterface`
      Parameters:
        `str` - the string to write
      Throws:
        `IOException` - if the string is too long for encoding