C# Класс CSJ2K.j2k.util.ISRandomAccessIO

This class implements a wrapper to turn an InputStream into a RandomAccessIO. To provide random access, the input data from the InputStream is cached in an in-memory buffer. The in-memory buffer size can be limited to a specified size. The data is read into the cache on a as needed basis, blocking only when necessary.

The cache grows automatically as necessary. However, if the data length is known prior to the creation of a ISRandomAccessIO object, it is best to specify that as the initial in-memory buffer size. That will minimize data copying and multiple allocation.

Multi-byte data is read in big-endian order. The in-memory buffer storage is released when 'close()' is called. This class can only be used for data input, not output. The wrapped InputStream is closed when all the input data is cached or when 'close()' is called.

If an out of memory condition is encountered when growing the in-memory buffer an IOException is thrown instead of an OutOfMemoryError. The exception message is "Out of memory to cache input data".

This class is intended for use as a "quick and dirty" way to give network connectivity to RandomAccessIO based classes. It is not intended as an efficient means of implementing network connectivity. Doing such requires reimplementing the RandomAccessIO based classes to directly use network connections.

This class does not use temporary files as buffers, because that would preclude the use in unsigned applets.

Наследование: RandomAccessIO
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
ISRandomAccessIO ( System is_Renamed ) : System

Creates a new RandomAccessIO wrapper for the given InputStream 'is'. The internal cache buffer size and increment is to to 256 kB. The maximum buffer size is set to Integer.MAX_VALUE (2 GB).

ISRandomAccessIO ( System is_Renamed, int size, int inc, int maxsize ) : System

Creates a new RandomAccessIO wrapper for the given InputStream 'is'. The internal cache buffer will have size 'size' and will increment by 'inc' each time it is needed. The maximum buffer size is limited to 'maxsize'.

close ( ) : void

Closes this object for reading as well as the wrapped InputStream, if not already closed. The memory used by the cache is released.

flush ( ) : void

Does nothing since this class does not implement data output.

length ( ) : int

Returns the length of the stream. This will cause all the data to be read. This method will block until all the data is read, which can be lengthy across the network.

read ( ) : byte
readByte ( ) : byte

Reads a byte of data from the stream.

readDouble ( ) : double

Reads an IEEE double precision (i.e., 64 bit) floating-point number from the input.

readFloat ( ) : float

Reads an IEEE single precision (i.e., 32 bit) floating-point number from the input.

readFully ( byte b, int off, int n ) : void

Reads '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

Reads a signed int (32 bit) from the input.

readLong ( ) : long

Reads a signed long (64 bit) from the input.

readShort ( ) : short

Reads a signed short (16 bit) from the input.

readUnsignedByte ( ) : byte

Reads an unsigned byte (8 bit) from the input.

readUnsignedInt ( ) : long

Reads a unsigned int (32 bit) from the input.

readUnsignedShort ( ) : int

Reads an unsigned short (16 bit) from the input.

seek ( int off ) : void

Moves the current position for the next read operation to offset. The offset is measured from the beginning of the stream. If the offset is set beyond the currently cached data, the missing data will be read only when a read operation is performed. Setting the offset beyond the end of the data will cause an EOFException only if the data length is currently known, otherwise an IOException will occur when a read operation is attempted at that position.

skipBytes ( int n ) : int

Skips 'n' bytes from the input.

write ( byte b ) : void

Throws an IOException since this class does not implement data output.

writeByte ( int v ) : void

Throws an IOException since this class does not implement data output.

writeDouble ( double v ) : void

Throws an IOException since this class does not implement data output.

writeFloat ( float v ) : void

Throws an IOException since this class does not implement data output.

writeInt ( int v ) : void

Throws an IOException since this class does not implement data output.

writeLong ( long v ) : void

Throws an IOException since this class does not implement data output.

writeShort ( int v ) : void

Throws an IOException since this class does not implement data output.

Приватные методы

Метод Описание
growBuffer ( ) : void

Grows the cache buffer by 'inc', upto a maximum of 'maxsize'. The buffer size will be increased by at least one byte, if no exception is thrown.

readInput ( ) : void

Reads data from the wrapped InputStream and places it in the cache buffer. Reads all input data that will not cause it to block, but at least on byte is read (even if it blocks), unless EOF is reached. This method can not be called if EOF has been already reached (i.e. 'complete' is true). The wrapped InputStream is closed if the EOF is reached.

Описание методов

ISRandomAccessIO() публичный Метод

Creates a new RandomAccessIO wrapper for the given InputStream 'is'. The internal cache buffer size and increment is to to 256 kB. The maximum buffer size is set to Integer.MAX_VALUE (2 GB).
public ISRandomAccessIO ( System is_Renamed ) : System
is_Renamed System
Результат System

ISRandomAccessIO() публичный Метод

Creates a new RandomAccessIO wrapper for the given InputStream 'is'. The internal cache buffer will have size 'size' and will increment by 'inc' each time it is needed. The maximum buffer size is limited to 'maxsize'.
public ISRandomAccessIO ( System is_Renamed, int size, int inc, int maxsize ) : System
is_Renamed System
size int The initial size for the cache buffer, in bytes. /// ///
inc int The size increment for the cache buffer, in bytes. /// ///
maxsize int The maximum size for the cache buffer, in bytes. /// ///
Результат System

close() публичный Метод

Closes this object for reading as well as the wrapped InputStream, if not already closed. The memory used by the cache is released.
If an I/O error occurs while closing the /// underlying InputStream. /// ///
public close ( ) : void
Результат void

flush() публичный Метод

Does nothing since this class does not implement data output.
public flush ( ) : void
Результат void

length() публичный Метод

Returns the length of the stream. This will cause all the data to be read. This method will block until all the data is read, which can be lengthy across the network.
If an I/O error ocurred. /// ///
public length ( ) : int
Результат int

read() публичный Метод

public read ( ) : byte
Результат byte

readByte() публичный Метод

Reads a byte of data from the stream.
If the end-of file was reached. /// /// If an I/O error ocurred. /// ///
public readByte ( ) : byte
Результат byte

readDouble() публичный Метод

Reads an IEEE double precision (i.e., 64 bit) floating-point number from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readDouble ( ) : double
Результат double

readFloat() публичный Метод

Reads an IEEE single precision (i.e., 32 bit) floating-point number from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readFloat ( ) : float
Результат float

readFully() публичный Метод

Reads '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 n ) : 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. /// ///
n int
Результат void

readInt() публичный Метод

Reads a signed int (32 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readInt ( ) : int
Результат int

readLong() публичный Метод

Reads a signed long (64 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readLong ( ) : long
Результат long

readShort() публичный Метод

Reads a signed short (16 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readShort ( ) : short
Результат short

readUnsignedByte() публичный Метод

Reads an unsigned byte (8 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readUnsignedByte ( ) : byte
Результат byte

readUnsignedInt() публичный Метод

Reads a unsigned int (32 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readUnsignedInt ( ) : long
Результат long

readUnsignedShort() публичный Метод

Reads an unsigned short (16 bit) from the input.
If the end-of file was reached before getting /// all the necessary data. /// /// If an I/O error ocurred. /// ///
public readUnsignedShort ( ) : int
Результат int

seek() публичный Метод

Moves the current position for the next read operation to offset. The offset is measured from the beginning of the stream. If the offset is set beyond the currently cached data, the missing data will be read only when a read operation is performed. Setting the offset beyond the end of the data will cause an EOFException only if the data length is currently known, otherwise an IOException will occur when a read operation is attempted at that position.
If seeking beyond EOF and the data length is /// known. /// /// If an I/O error ocurred. /// ///
public seek ( int off ) : void
off int The offset where to move to. /// ///
Результат void

skipBytes() публичный Метод

Skips 'n' bytes from the input.
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 /// ///
Результат int

write() публичный Метод

Throws an IOException since this class does not implement data output.
public write ( byte b ) : void
b byte
Результат void

writeByte() публичный Метод

Throws an IOException since this class does not implement data output.
public writeByte ( int v ) : void
v int
Результат void

writeDouble() публичный Метод

Throws an IOException since this class does not implement data output.
public writeDouble ( double v ) : void
v double
Результат void

writeFloat() публичный Метод

Throws an IOException since this class does not implement data output.
public writeFloat ( float v ) : void
v float
Результат void

writeInt() публичный Метод

Throws an IOException since this class does not implement data output.
public writeInt ( int v ) : void
v int
Результат void

writeLong() публичный Метод

Throws an IOException since this class does not implement data output.
public writeLong ( long v ) : void
v long
Результат void

writeShort() публичный Метод

Throws an IOException since this class does not implement data output.
public writeShort ( int v ) : void
v int
Результат void