C# Class CSJ2K.j2k.io.BufferedRandomAccessFile

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.

Inheritance: RandomAccessIO, EndianType
Afficher le fichier Open project: cureos/csj2k Class Usage Examples

Protected Properties

Свойство Type Description
byteBuffer byte[]
byteBufferChanged bool
byte_Ordering int
isEOFInBuffer bool
maxByte int
offset int
position int

Méthodes publiques

Méthode Description
ToString ( ) : System.String

Returns a string of information about the file

close ( ) : void

Closes the buffered random access file

flush ( ) : void

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.

length ( ) : int

Returns the current length of the stream, in bytes, taking into account any buffering.

read ( ) : byte
readByte ( ) : byte

Reads an unsigned byte of data from the stream. Prior to reading, the stream is realigned at the byte level.

readDouble ( ) : double
readFloat ( ) : float
readFully ( byte b, int off, int len ) : void

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.

readInt ( ) : int
readLong ( ) : long
readShort ( ) : short
readUnsignedByte ( ) : byte
readUnsignedInt ( ) : long
readUnsignedShort ( ) : int
seek ( int off ) : void

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.

skipBytes ( int n ) : int

Skips n bytes from the input. Prior to skipping, the input should be realigned at the byte level.

write ( byte b ) : void

Writes a byte to the stream. Prior to writing, the stream is realigned at the byte level.

write ( byte b, int offset, int length ) : void

Writes aan array of bytes to the stream. Prior to writing, the stream is realigned at the byte level.

write ( int b ) : void

Writes a byte to the stream. Prior to writing, the stream is realigned at the byte level.

writeByte ( int v ) : void

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).

writeDouble ( double param1 ) : void
writeFloat ( float param1 ) : void
writeInt ( int param1 ) : void
writeLong ( long param1 ) : void
writeShort ( int param1 ) : void

Méthodes protégées

Méthode Description
BufferedRandomAccessFile ( IFileInfo file, System mode ) : System

Constructor. Uses the default value for the byte-buffer size (512 bytes).

BufferedRandomAccessFile ( IFileInfo file, System mode, int bufferSize ) : System

Constructor. Always needs a size for the buffer.

BufferedRandomAccessFile ( System.Stream stream, bool isReadOnly ) : System

Constructor. Uses the default value for the byte-buffer size (512 bytes).

BufferedRandomAccessFile ( System.Stream stream, bool isReadOnly, int bufferSize ) : System

Constructor. Always needs a size for the buffer.

BufferedRandomAccessFile ( System name, System mode ) : System

Constructor. Uses the default value for the byte-buffer size (512 bytes).

BufferedRandomAccessFile ( System name, System mode, int bufferSize ) : System

Constructor. Always needs a size for the buffer.

readNewBuffer ( int off ) : void

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.

Method Details

BufferedRandomAccessFile() protected méthode

Constructor. Uses the default value for the byte-buffer size (512 bytes).
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( IFileInfo file, System mode ) : System
file IFileInfo The file associated with the buffer /// ///
mode System "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). /// ///
Résultat System

BufferedRandomAccessFile() protected méthode

Constructor. Always needs a size for the buffer.
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( IFileInfo file, System mode, int bufferSize ) : System
file IFileInfo The file associated with the buffer /// ///
mode System "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 int The number of bytes to buffer /// ///
Résultat System

BufferedRandomAccessFile() protected méthode

Constructor. Uses the default value for the byte-buffer size (512 bytes).
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( System.Stream stream, bool isReadOnly ) : System
stream System.Stream The stream associated with the buffer /// ///
isReadOnly bool Indicates whether file is read-only or not.
Résultat System

BufferedRandomAccessFile() protected méthode

Constructor. Always needs a size for the buffer.
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( System.Stream stream, bool isReadOnly, int bufferSize ) : System
stream System.Stream The stream associated with the buffer /// ///
isReadOnly bool Indicates whether file is read-only or not.
bufferSize int The number of bytes to buffer /// ///
Résultat System

BufferedRandomAccessFile() protected méthode

Constructor. Uses the default value for the byte-buffer size (512 bytes).
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( System name, System mode ) : System
name System The name of the file associated with the buffer /// ///
mode System "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). /// ///
Résultat System

BufferedRandomAccessFile() protected méthode

Constructor. Always needs a size for the buffer.
If an I/O error ocurred. /// ///
protected BufferedRandomAccessFile ( System name, System mode, int bufferSize ) : System
name System The name of the file associated with the buffer /// ///
mode System "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 int The number of bytes to buffer /// ///
Résultat System

ToString() public méthode

Returns a string of information about the file
public ToString ( ) : System.String
Résultat System.String

close() public méthode

Closes the buffered random access file
If an I/O error ocurred. /// ///
public close ( ) : void
Résultat void

flush() public méthode

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.
If an I/O error ocurred. /// ///
public flush ( ) : void
Résultat void

length() public méthode

Returns the current length of the stream, in bytes, taking into account any buffering.
If an I/O error ocurred. /// ///
public length ( ) : int
Résultat int

read() public méthode

public read ( ) : byte
Résultat byte

readByte() public méthode

Reads an unsigned byte of data from the stream. Prior to reading, the stream is realigned at the byte level.
If an I/O error ocurred. /// /// If the end of file was reached /// ///
public readByte ( ) : byte
Résultat byte

readDouble() public abstract méthode

public abstract readDouble ( ) : double
Résultat double

readFloat() public abstract méthode

public abstract readFloat ( ) : float
Résultat float

readFully() public méthode

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.
If the end-of file was reached before /// getting all the necessary data. /// /// If an I/O error ocurred. /// ///
public readFully ( byte b, int off, int len ) : void
b byte The buffer into which the data is to be read. It must be long /// enough. /// ///
off int The index in 'b' where to place the first byte read. /// ///
len int The number of bytes to read. /// ///
Résultat void

readInt() public abstract méthode

public abstract readInt ( ) : int
Résultat int

readLong() public abstract méthode

public abstract readLong ( ) : long
Résultat long

readNewBuffer() protected méthode

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.
If an I/O error ocurred. /// ///
protected readNewBuffer ( int off ) : void
off int The offset where to move to. /// ///
Résultat void

readShort() public abstract méthode

public abstract readShort ( ) : short
Résultat short

readUnsignedByte() public méthode

public readUnsignedByte ( ) : byte
Résultat byte

readUnsignedInt() public abstract méthode

public abstract readUnsignedInt ( ) : long
Résultat long

readUnsignedShort() public abstract méthode

public abstract readUnsignedShort ( ) : int
Résultat int

seek() public méthode

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.
If in read-only and seeking beyond EOF. /// /// If an I/O error ocurred. /// ///
public seek ( int off ) : void
off int The offset where to move to. /// ///
Résultat void

skipBytes() public méthode

Skips n bytes from the input. Prior to skipping, the input should be realigned at the byte level.
If the end-of file was reached before /// all the bytes could be skipped. /// /// If an I/O error ocurred. /// ///
public skipBytes ( int n ) : int
n int The number of bytes to skip /// ///
Résultat int

write() public méthode

Writes a byte to the stream. Prior to writing, the stream is realigned at the byte level.
If an I/O error ocurred. /// ///
public write ( byte b ) : void
b byte The byte to write. /// ///
Résultat void

write() public méthode

Writes aan array of bytes to the stream. Prior to writing, the stream is realigned at the byte level.
If an I/O error ocurred. /// ///
public write ( byte b, int offset, int length ) : void
b byte The array of bytes to write. /// ///
offset int The first byte in b to write /// ///
length int The number of bytes from b to write /// ///
Résultat void

write() public méthode

Writes a byte to the stream. Prior to writing, the stream is realigned at the byte level.
If an I/O error ocurred. /// ///
public write ( int b ) : void
b int The byte to write. The lower 8 bits of b are /// written. /// ///
Résultat void

writeByte() public méthode

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).

If an I/O error ocurred. /// ///
public writeByte ( int v ) : void
v int The value to write to the output /// ///
Résultat void

writeDouble() public abstract méthode

public abstract writeDouble ( double param1 ) : void
param1 double
Résultat void

writeFloat() public abstract méthode

public abstract writeFloat ( float param1 ) : void
param1 float
Résultat void

writeInt() public abstract méthode

public abstract writeInt ( int param1 ) : void
param1 int
Résultat void

writeLong() public abstract méthode

public abstract writeLong ( long param1 ) : void
param1 long
Résultat void

writeShort() public abstract méthode

public abstract writeShort ( int param1 ) : void
param1 int
Résultat void

Property Details

byteBuffer protected_oe property

Buffer of bytes containing the part of the file that is currently being accessed
protected byte[] byteBuffer
Résultat byte[]

byteBufferChanged protected_oe property

Boolean keeping track of whether the byte buffer has been changed since it was read.
protected bool byteBufferChanged
Résultat bool

byte_Ordering protected_oe property

protected int byte_Ordering
Résultat int

isEOFInBuffer protected_oe property

Whether the end of the file is in the current buffer or not
protected bool isEOFInBuffer
Résultat bool

maxByte protected_oe property

The maximum number of bytes that can be read from the buffer
protected int maxByte
Résultat int

offset protected_oe property

The current offset of the buffer (which will differ from the offset of the file)
protected int offset
Résultat int

position protected_oe property

The current position in the byte-buffer
protected int position
Résultat int