Package jj2000.j2k.io

Class BEBufferedRandomAccessFile

java.lang.Object
jj2000.j2k.io.BufferedRandomAccessFile
jj2000.j2k.io.BEBufferedRandomAccessFile
All Implemented Interfaces:
BinaryDataInput, BinaryDataOutput, EndianType, RandomAccessIO

public class BEBufferedRandomAccessFile extends BufferedRandomAccessFile implements RandomAccessIO, EndianType
This class defines a Buffered Random Access File, where all I/O is considered to be big-endian, and extends the BufferedRandomAccessFile class.
See Also:
  • Constructor Details

    • BEBufferedRandomAccessFile

      public BEBufferedRandomAccessFile(File file, String mode, int bufferSize) throws IOException
      Constructor. Always needs a size for the buffer.
      Parameters:
      file - The file associated with the buffer
      mode - "r" for read, "rw" or "rw+" for read and write mode ("rw+" opens the file for update whereas "rw" removes it before. So the 2 modes are different only if the file already exists).
      bufferSize - The number of bytes to buffer
      Throws:
      IOException - If an I/O error ocurred.
    • BEBufferedRandomAccessFile

      public BEBufferedRandomAccessFile(File file, String mode) throws IOException
      Constructor. Uses the default value for the byte-buffer size (512 bytes).
      Parameters:
      file - The file associated with the buffer
      mode - "r" for read, "rw" or "rw+" for read and write mode ("rw+" opens the file for update whereas "rw" removes it before. So the 2 modes are different only if the file already exists).
      Throws:
      IOException - If an I/O error ocurred.
    • BEBufferedRandomAccessFile

      public BEBufferedRandomAccessFile(String name, String mode, int bufferSize) throws IOException
      Constructor. Always needs a size for the buffer.
      Parameters:
      name - The name of the file associated with the buffer
      mode - "r" for read, "rw" or "rw+" for read and write mode ("rw+" opens the file for update whereas "rw" removes it before. So the 2 modes are different only if the file already exists).
      bufferSize - The number of bytes to buffer
      Throws:
      IOException - If an I/O error ocurred.
    • BEBufferedRandomAccessFile

      public BEBufferedRandomAccessFile(String name, String mode) throws IOException
      Constructor. Uses the default value for the byte-buffer size (512 bytes).
      Parameters:
      name - The name of the file associated with the buffer
      mode - "r" for read, "rw" or "rw+" for read and write mode ("rw+" opens the file for update whereas "rw" removes it before. So the 2 modes are different only if the file already exists).
      Throws:
      IOException - If an I/O error ocurred.
  • Method Details

    • writeShort

      public final void writeShort(int v) throws IOException
      Writes the short value of v (i.e., 16 least significant bits) to the output. Prior to writing, the output should be realigned at the byte level.

      Signed or unsigned data can be written. To write a signed value just pass the short value as an argument. To write unsigned data pass the int value as an argument (it will be automatically casted, and only the 16 least significant bits will be written).

      Specified by:
      writeShort in interface BinaryDataOutput
      Parameters:
      v - The value to write to the output
      Throws:
      IOException - If an I/O error ocurred.
    • writeInt

      public final void writeInt(int v) throws IOException
      Writes the int value of v (i.e., the 32 bits) to the output. Prior to writing, the output should be realigned at the byte level.
      Specified by:
      writeInt in interface BinaryDataOutput
      Parameters:
      v - The value to write to the output
      Throws:
      IOException - If an I/O error ocurred.
    • writeLong

      public final void writeLong(long v) throws IOException
      Writes the long value of v (i.e., the 64 bits) to the output. Prior to writing, the output should be realigned at the byte level.
      Specified by:
      writeLong in interface BinaryDataOutput
      Parameters:
      v - The value to write to the output
      Throws:
      IOException - If an I/O error ocurred.
    • writeFloat

      public final void writeFloat(float v) throws IOException
      Writes the IEEE float value v (i.e., 32 bits) to the output. Prior to writing, the output should be realigned at the byte level.
      Specified by:
      writeFloat in interface BinaryDataOutput
      Parameters:
      v - The value to write to the output
      Throws:
      IOException - If an I/O error ocurred.
    • writeDouble

      public final void writeDouble(double v) throws IOException
      Writes the IEEE double value v (i.e., 64 bits) to the output. Prior to writing, the output should be realigned at the byte level.
      Specified by:
      writeDouble in interface BinaryDataOutput
      Parameters:
      v - The value to write to the output
      Throws:
      IOException - If an I/O error ocurred.
    • readShort

      public final short readShort() throws IOException, EOFException
      Reads a signed short (i.e., 16 bit) from the input. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readShort in interface BinaryDataInput
      Returns:
      The next byte-aligned signed short (16 bit) from the input.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readUnsignedShort

      public final int readUnsignedShort() throws IOException, EOFException
      Reads an unsigned short (i.e., 16 bit) from the input. It is returned as an int since Java does not have an unsigned short type. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readUnsignedShort in interface BinaryDataInput
      Returns:
      The next byte-aligned unsigned short (16 bit) from the input, as an int.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readInt

      public final int readInt() throws IOException, EOFException
      Reads a signed int (i.e., 32 bit) from the input. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readInt in interface BinaryDataInput
      Returns:
      The next byte-aligned signed int (32 bit) from the input.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readUnsignedInt

      public final long readUnsignedInt() throws IOException, EOFException
      Reads an unsigned int (i.e., 32 bit) from the input. It is returned as a long since Java does not have an unsigned short type. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readUnsignedInt in interface BinaryDataInput
      Returns:
      The next byte-aligned unsigned int (32 bit) from the input, as a long.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readLong

      public final long readLong() throws IOException, EOFException
      Reads a signed long (i.e., 64 bit) from the input. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readLong in interface BinaryDataInput
      Returns:
      The next byte-aligned signed long (64 bit) from the input.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readFloat

      public final float readFloat() throws EOFException, IOException
      Reads an IEEE single precision (i.e., 32 bit) floating-point number from the input. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readFloat in interface BinaryDataInput
      Returns:
      The next byte-aligned IEEE float (32 bit) from the input.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • readDouble

      public final double readDouble() throws IOException, EOFException
      Reads an IEEE double precision (i.e., 64 bit) floating-point number from the input. Prior to reading, the input should be realigned at the byte level.
      Specified by:
      readDouble in interface BinaryDataInput
      Returns:
      The next byte-aligned IEEE double (64 bit) from the input.
      Throws:
      EOFException - If the end-of file was reached before getting all the necessary data.
      IOException - If an I/O error ocurred.
    • toString

      public String toString()
      Returns a string of information about the file and the endianess
      Overrides:
      toString in class BufferedRandomAccessFile