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.
-
Field Summary
Fields inherited from class jj2000.j2k.io.BufferedRandomAccessFile
byteBuffer, byteBufferChanged, byteOrdering, isEOFInBuffer, maxByte, offset, posFields inherited from interface jj2000.j2k.io.EndianType
BIG_ENDIAN, LITTLE_ENDIAN -
Constructor Summary
ConstructorsConstructorDescriptionBEBufferedRandomAccessFile(File file, String mode) Constructor.BEBufferedRandomAccessFile(File file, String mode, int bufferSize) Constructor.BEBufferedRandomAccessFile(String name, String mode) Constructor.BEBufferedRandomAccessFile(String name, String mode, int bufferSize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal doubleReads an IEEE double precision (i.e., 64 bit) floating-point number from the input.final floatReads an IEEE single precision (i.e., 32 bit) floating-point number from the input.final intreadInt()Reads a signed int (i.e., 32 bit) from the input.final longreadLong()Reads a signed long (i.e., 64 bit) from the input.final shortReads a signed short (i.e., 16 bit) from the input.final longReads an unsigned int (i.e., 32 bit) from the input.final intReads an unsigned short (i.e., 16 bit) from the input.toString()Returns a string of information about the file and the endianessfinal voidwriteDouble(double v) Writes the IEEE double value v (i.e., 64 bits) to the output.final voidwriteFloat(float v) Writes the IEEE float value v (i.e., 32 bits) to the output.final voidwriteInt(int v) Writes the int value of v (i.e., the 32 bits) to the output.final voidwriteLong(long v) Writes the long value of v (i.e., the 64 bits) to the output.final voidwriteShort(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, writeByteMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jj2000.j2k.io.BinaryDataInput
getByteOrdering, readByte, readUnsignedByte, skipBytesMethods inherited from interface jj2000.j2k.io.BinaryDataOutput
flush, getByteOrdering, writeByte
-
Constructor Details
-
BEBufferedRandomAccessFile
Constructor. Always needs a size for the buffer.- Parameters:
file- The file associated with the buffermode- "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
Constructor. Uses the default value for the byte-buffer size (512 bytes).- Parameters:
file- The file associated with the buffermode- "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
Constructor. Always needs a size for the buffer.- Parameters:
name- The name of the file associated with the buffermode- "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
Constructor. Uses the default value for the byte-buffer size (512 bytes).- Parameters:
name- The name of the file associated with the buffermode- "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
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:
writeShortin interfaceBinaryDataOutput- Parameters:
v- The value to write to the output- Throws:
IOException- If an I/O error ocurred.
-
writeInt
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:
writeIntin interfaceBinaryDataOutput- Parameters:
v- The value to write to the output- Throws:
IOException- If an I/O error ocurred.
-
writeLong
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:
writeLongin interfaceBinaryDataOutput- Parameters:
v- The value to write to the output- Throws:
IOException- If an I/O error ocurred.
-
writeFloat
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:
writeFloatin interfaceBinaryDataOutput- Parameters:
v- The value to write to the output- Throws:
IOException- If an I/O error ocurred.
-
writeDouble
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:
writeDoublein interfaceBinaryDataOutput- Parameters:
v- The value to write to the output- Throws:
IOException- If an I/O error ocurred.
-
readShort
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:
readShortin interfaceBinaryDataInput- 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
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:
readUnsignedShortin interfaceBinaryDataInput- 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
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:
readIntin interfaceBinaryDataInput- 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
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:
readUnsignedIntin interfaceBinaryDataInput- 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
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:
readLongin interfaceBinaryDataInput- 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
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:
readFloatin interfaceBinaryDataInput- 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
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:
readDoublein interfaceBinaryDataInput- 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
Returns a string of information about the file and the endianess- Overrides:
toStringin classBufferedRandomAccessFile
-