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. It extends the BufferedRandomAccessFile class.

See Also:
RandomAccessIO, BinaryDataOutput, BinaryDataInput, BufferedRandomAccessFile

Field Summary
 
Fields inherited from class jj2000.j2k.io.BufferedRandomAccessFile
byteBuffer, byteBufferChanged, byteOrdering, isEOFInBuffer, maxByte, offset, pos
 
Fields inherited from interface jj2000.j2k.io.EndianType
BIG_ENDIAN, LITTLE_ENDIAN
 
Constructor Summary
BEBufferedRandomAccessFile(java.io.File file, java.lang.String mode)
          Constructor.
BEBufferedRandomAccessFile(java.io.File file, java.lang.String mode, int bufferSize)
          Constructor.
BEBufferedRandomAccessFile(java.lang.String name, java.lang.String mode)
          Constructor.
BEBufferedRandomAccessFile(java.lang.String name, java.lang.String mode, int bufferSize)
          Constructor.
 
Method Summary
 double readDouble()
          Reads an IEEE double precision (i.e., 64 bit) floating-point number from the input.
 float readFloat()
          Reads an IEEE single precision (i.e., 32 bit) floating-point number from the input.
 int readInt()
          Reads a signed int (i.e., 32 bit) from the input.
 long readLong()
          Reads a signed long (i.e., 64 bit) from the input.
 short readShort()
          Reads a signed short (i.e.
 long readUnsignedInt()
          Reads an unsigned int (i.e., 32 bit) from the input.
 int readUnsignedShort()
          Reads an unsigned short (i.e., 16 bit) from the input.
 java.lang.String toString()
          Returns a string of information about the file and the endianess
 void writeDouble(double v)
          Writes the IEEE double value v (i.e., 64 bits) to the output.
 void writeFloat(float v)
          Writes the IEEE float value v (i.e., 32 bits) to the output.
 void writeInt(int v)
          Writes the int value of v (i.e., the 32 bits) to the output.
 void writeLong(long v)
          Writes the long value of v (i.e., the 64 bits) to the output.
 void writeShort(int v)
          Writes the short value of v (i.e., 16 least significant bits) to the output.
 
Methods inherited from class jj2000.j2k.io.BufferedRandomAccessFile
close, flush, getByteOrdering, getPos, length, read, readByte, readFully, readNewBuffer, readUnsignedByte, seek, skipBytes, write, write, write, writeByte
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jj2000.j2k.io.RandomAccessIO
close, getPos, length, read, readFully, seek, write
 
Methods inherited from interface jj2000.j2k.io.BinaryDataInput
getByteOrdering, readByte, readUnsignedByte, skipBytes
 
Methods inherited from interface jj2000.j2k.io.BinaryDataOutput
flush, getByteOrdering, writeByte
 

Constructor Detail

BEBufferedRandomAccessFile

public BEBufferedRandomAccessFile(java.io.File file,
                                  java.lang.String mode,
                                  int bufferSize)
                           throws java.io.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:
java.io.IOException - If an I/O error ocurred.

BEBufferedRandomAccessFile

public BEBufferedRandomAccessFile(java.io.File file,
                                  java.lang.String mode)
                           throws java.io.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:
java.io.IOException - If an I/O error ocurred.

BEBufferedRandomAccessFile

public BEBufferedRandomAccessFile(java.lang.String name,
                                  java.lang.String mode,
                                  int bufferSize)
                           throws java.io.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:
java.io.IOException - If an I/O error ocurred.

BEBufferedRandomAccessFile

public BEBufferedRandomAccessFile(java.lang.String name,
                                  java.lang.String mode)
                           throws java.io.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:
java.io.IOException - If an I/O error ocurred.
Method Detail

writeShort

public final void writeShort(int v)
                      throws java.io.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:
java.io.IOException - If an I/O error ocurred.

writeInt

public final void writeInt(int v)
                    throws java.io.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:
java.io.IOException - If an I/O error ocurred.

writeLong

public final void writeLong(long v)
                     throws java.io.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:
java.io.IOException - If an I/O error ocurred.

writeFloat

public final void writeFloat(float v)
                      throws java.io.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:
java.io.IOException - If an I/O error ocurred.

writeDouble

public final void writeDouble(double v)
                       throws java.io.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:
java.io.IOException - If an I/O error ocurred.

readShort

public final short readShort()
                      throws java.io.IOException,
                             java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException,
                                   java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readInt

public final int readInt()
                  throws java.io.IOException,
                         java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readUnsignedInt

public final long readUnsignedInt()
                           throws java.io.IOException,
                                  java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readLong

public final long readLong()
                    throws java.io.IOException,
                           java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readFloat

public final float readFloat()
                      throws java.io.EOFException,
                             java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

readDouble

public final double readDouble()
                        throws java.io.IOException,
                               java.io.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:
java.io.EOFException - If the end-of file was reached before getting all the necessary data.
java.io.IOException - If an I/O error ocurred.

toString

public java.lang.String toString()
Returns a string of information about the file and the endianess

Overrides:
toString in class BufferedRandomAccessFile