| java.lang.Object jj2000.j2k.io.BufferedRandomAccessFile
All known Subclasses: jj2000.j2k.io.BEBufferedRandomAccessFile,
BufferedRandomAccessFile | abstract public class BufferedRandomAccessFile implements RandomAccessIO,EndianType(Code) | | This class defines a Buffered Random Access File. It implements the
BinaryDataInput and BinaryDataOutput interfaces so that
binary data input/output can be performed. This class is abstract since no
assumption is done about the byte ordering type (little Endian, big
Endian). So subclasses will have to implement methods like
readShort(), writeShort(), readFloat(), ...
BufferedRandomAccessFile (BRAF for short) is a
RandomAccessFile containing an extra buffer. When the BRAF is
accessed, it checks if the requested part of the file is in the buffer or
not. If that is the case, the read/write is done on the buffer. If not, the
file is uppdated to reflect the current status of the buffer and the file
is then accessed for a new buffer containing the requested byte/bit.
See Also: RandomAccessIO See Also: BinaryDataOutput See Also: BinaryDataInput See Also: BEBufferedRandomAccessFile |
Method Summary | |
public void | close() | final public void | flush() Any data that has been buffered must be written (including
buffering at the bit level), and the stream should be realigned
at the byte level. | public int | getByteOrdering() Returns the endianess (i.e., byte ordering) of the implementing
class. | public int | getPos() | public int | length() Returns the current length of the stream, in bytes, taking into
account any buffering. | final public int | read() Reads an unsigned byte of data from the stream. | final public byte | readByte() Reads a signed byte (i.e., 8 bit) from the input. | final public void | readFully(byte b, int off, int len) Reads up to len bytes of data from this file into an array of
bytes. | final protected void | readNewBuffer(int off) Reads a new buffer from the file. | final public int | readUnsignedByte() Reads an unsigned byte (i.e., 8 bit) from the input. | public void | seek(int off) Moves the current position to the given offset at which the
next read or write occurs. | public int | skipBytes(int n) Skips n bytes from the input. | public String | toString() | final public void | write(int b) Writes a byte to the stream. | final public void | write(byte b) Writes a byte to the stream. | final public void | write(byte[] b, int offset, int length) Writes aan array of bytes to the stream. | final public void | writeByte(int v) Writes the byte value of v (i.e., 8 least
significant bits) to the output. |
byteBuffer | protected byte[] byteBuffer(Code) | | Buffer of bytes containing the part of the file that is currently being
accessed
|
byteBufferChanged | protected boolean byteBufferChanged(Code) | | Boolean keeping track of whether the byte buffer has been changed since
it was read.
|
byteOrdering | protected int byteOrdering(Code) | | |
isEOFInBuffer | protected boolean isEOFInBuffer(Code) | | Whether the end of the file is in the current buffer or not
|
maxByte | protected int maxByte(Code) | | The maximum number of bytes that can be read from the buffer
|
offset | protected int offset(Code) | | The current offset of the buffer (which will differ from the offset of
the file)
|
pos | protected int pos(Code) | | The current position in the byte-buffer
|
BufferedRandomAccessFile | protected BufferedRandomAccessFile(File file, String mode, int bufferSize) throws IOException(Code) | | Constructor. Always needs a size for the buffer.
Parameters: file - The file associated with the buffer Parameters: mode - "r" for read, "rw" or "rw+" for read and write mode ("rw+"opens the file for update whereas "rw" removes itbefore. So the 2 modes are different only if the filealready exists). Parameters: bufferSize - The number of bytes to buffer exception: java.io.IOException - If an I/O error ocurred. |
BufferedRandomAccessFile | protected BufferedRandomAccessFile(File file, String mode) throws IOException(Code) | | Constructor. Uses the default value for the byte-buffer
size (512 bytes).
Parameters: file - The file associated with the buffer Parameters: mode - "r" for read, "rw" or "rw+" for read and write mode("rw+" opens the file for update whereas "rw" removesit before. So the 2 modes are different only if thefile already exists). exception: java.io.IOException - If an I/O error ocurred. |
BufferedRandomAccessFile | protected BufferedRandomAccessFile(String name, String mode, int bufferSize) throws IOException(Code) | | Constructor. Always needs a size for the buffer.
Parameters: name - The name of the file associated with the buffer Parameters: mode - "r" for read, "rw" or "rw+" for read and write mode("rw+" opens the file for update whereas "rw" removesit before. So the 2 modes are different only if thefile already exists). Parameters: bufferSize - The number of bytes to buffer exception: java.io.IOException - If an I/O error ocurred. |
BufferedRandomAccessFile | protected BufferedRandomAccessFile(String name, String mode) throws IOException(Code) | | Constructor. Uses the default value for the byte-buffer
size (512 bytes).
Parameters: name - The name of the file associated with the buffer Parameters: mode - "r" for read, "rw" or "rw+" for read and write mode("rw+" opens the file for update whereas "rw" removesit before. So the 2 modes are different only if thefile already exists). exception: java.io.IOException - If an I/O error ocurred. |
flush | final public void flush() throws IOException(Code) | | Any data that has been buffered must be written (including
buffering at the bit level), and the stream should be realigned
at the byte level.
exception: java.io.IOException - If an I/O error ocurred. |
getByteOrdering | public int getByteOrdering()(Code) | | Returns the endianess (i.e., byte ordering) of the implementing
class. Note that an implementing class may implement only one
type of endianness or both, which would be decided at creation
time.
Either EndianType.BIG_ENDIAN orEndianType.LITTLE_ENDIAN See Also: EndianType |
getPos | public int getPos()(Code) | | Returns the current offset in the file
|
length | public int length() throws IOException(Code) | | Returns the current length of the stream, in bytes, taking into
account any buffering.
The length of the stream, in bytes. exception: java.io.IOException - If an I/O error ocurred. |
readByte | final public byte readByte() throws EOFException, IOException(Code) | | Reads a signed byte (i.e., 8 bit) from the input. Prior to
reading, the input should be realigned at the byte level.
The next byte-aligned signed byte (8 bit) from theinput. exception: java.io.EOFException - If the end-of file was reached beforegetting all the necessary data. exception: java.io.IOException - If an I/O error ocurred. |
readFully | final public void readFully(byte b, int off, int len) throws IOException(Code) | | Reads up to len bytes of data from this file into an array of
bytes. This method reads repeatedly from the stream until all the bytes
are read. This method blocks until all the bytes are read, the end of
the stream is detected, or an exception is thrown.
Parameters: b - The buffer into which the data is to be read. It must be longenough. Parameters: off - The index in 'b' where to place the first byte read. Parameters: len - The number of bytes to read. exception: EOFException - If the end-of file was reached beforegetting all the necessary data. exception: IOException - If an I/O error ocurred. |
readNewBuffer | final protected void readNewBuffer(int off) throws IOException(Code) | | Reads a new buffer from the file. If there has been any
changes made since the buffer was read, the buffer is
first written to the file.
Parameters: off - The offset where to move to. exception: java.io.IOException - If an I/O error ocurred. |
readUnsignedByte | final public int readUnsignedByte() throws EOFException, IOException(Code) | | Reads an unsigned byte (i.e., 8 bit) from the input. It is
returned as an int since Java does not have an
unsigned byte type. Prior to reading, the input should be
realigned at the byte level.
The next byte-aligned unsigned byte (8 bit) from theinput, as an int. exception: java.io.EOFException - If the end-of file was reached beforegetting all the necessary data. exception: java.io.IOException - If an I/O error ocurred. |
seek | public void seek(int off) throws IOException(Code) | | Moves the current position to the given offset at which the
next read or write occurs. The offset is measured from the
beginning of the stream.
Parameters: off - The offset where to move to. exception: EOFException - If in read-only and seeking beyond EOF. exception: java.io.IOException - If an I/O error ocurred. |
skipBytes | public int skipBytes(int n) throws EOFException, IOException(Code) | | Skips n bytes from the input. Prior to skipping, the
input should be realigned at the byte level.
Parameters: n - The number of bytes to skip exception: java.io.EOFException - If the end-of file was reached beforeall the bytes could be skipped. exception: java.io.IOException - If an I/O error ocurred. |
toString | public String toString()(Code) | | Returns a string of information about the file
|
write | final public void write(int b) throws IOException(Code) | | Writes a byte to the stream. Prior to writing, the stream is
realigned at the byte level.
Parameters: b - The byte to write. The lower 8 bits of b arewritten. exception: java.io.IOException - If an I/O error ocurred. |
write | final public void write(byte b) throws IOException(Code) | | Writes a byte to the stream. Prior to writing, the stream is
realigned at the byte level.
Parameters: b - The byte to write. exception: java.io.IOException - If an I/O error ocurred. |
write | final public void write(byte[] b, int offset, int length) throws IOException(Code) | | Writes aan array of bytes to the stream. Prior to writing, the stream is
realigned at the byte level.
Parameters: b - The array of bytes to write. Parameters: offset - The first byte in b to write Parameters: length - The number of bytes from b to write exception: java.io.IOException - If an I/O error ocurred. |
writeByte | final public void writeByte(int v) throws IOException(Code) | | Writes the byte value of v (i.e., 8 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 byte value as an argument. To
write unsigned data pass the int value as an argument
(it will be automatically casted, and only the 8 least
significant bits will be written).
Parameters: v - The value to write to the output exception: java.io.IOException - If an I/O error ocurred. |
|
|