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
파일 보기 프로젝트 열기: cureos/csj2k 1 사용 예제들

공개 메소드들

메소드 설명
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