
- Pete Townshend
StreamIO
StreamIO Methods
| StreamIO() | Constructor for the StreamIO class |
| IOMode() | Method to return the I/O mode for this stream (Read, Write, ReadWrite) |
| Blocking() | Method to return true if blocking is on and false if blocking is off |
| SetBlocking() | Method to set blocking on or off |
| BytesAvailable() | Abstract method to return the number of bytes available to read before blocking |
| Pos() | Virtual method to return the current position within the stream |
| SetPos() | Virtual method to set the current position within the stream |
| DirectAccess() | Virtual method to return true if Direct Access I/O is available and false if not (false by default) |
| EndOfStream() | Abstract method to return true if currently at end of stream |
| BytesRead() | Abstract method to return number of bytes read during the last read operation |
| BytesWritten() | Abstract method to return number of bytes written during the last write operation |
| Read() | Abstract method to read a single integer from the stream (1, 2, 4 or 8 bytes) |
| Read() | Abstract method to read a single float from the stream (4 or 8 bytes) |
| Read() | Abstract method to read a text string from the stream (default length or specific length) |
| Read() | Abstract method to read a boolean from the stream |
| Read() | Abstract method to read a binary buffer (stream) from the stream |
| Write() | Abstract method to write a single integer to the stream (1, 2, 4 or 8 bytes) |
| Write() | Abstract method to write a single float to the stream (4 or 8 bytes) |
| Write() | Abstract method to write a single text string (default or specific length) |
| Write() | Abstract method to write a single boolean to the stream |
| Write() | Abstract method to write a binary buffer (stream) to the stream |
StreamIO Constants
| Constant Data Item | Data Type | Value |
| StreamIO.Read | int | 1 |
| StreamIO.Write | int | 2 |
| StreamIO.ReadWrite | int | 3 |
Derived Classes
FileStream, MemoryStream, SocketStream, FilterStream
See Also
Class Hierarchy, StreamException
public method StreamIO(int IOMode = StreamIO.Read, bool Blocking = false)
Parameters
IOMode
Indicates type of I/O which is valid
Blocking
Indicates if blocking is on or off
Return Value
None
Description
Constructor for the abstract StreamIO class. The I/O mode (Read, Write or ReadWrite) and the blocking flag are specified. The blocking flag is off by default.
StreamIO Class
public virtual method<int> IOMode()
Parameters
None
Return Value
I/O Mode - Read, ReadWrite, Write
Description
Returns the I/O Mode that the stream I/O object was created with, either Read, ReadWrite or Write.
StreamIO Class
public virtual method<bool> Blocking()
Parameters
None
Return Value
Returns true if blocking is on
Description
Returns true if blocking is currently on for the stream. If blocking is on and read request is made for more bytes than are available, the thread will block until the data is available. The method is defined as virtual mainly for the FilterStream family of classes so they can override and handle appropriately.
StreamIO Class
public virtual method SetBlocking(bool Blocking)
Parameters
Blocking
Blocking flag - true for on and false for off
Return Value
None
Description
Sets the blocking flag for the stream. A value of true turns blocking on and false turns it off. The method is defined as virtual mainly for the FilterStream family of classes so they can override and handle appropriately.
StreamIO Class
public abstract method<int> BytesAvailable()
Parameters
None
Return Value
Number of bytes available to read
Description
Returns the number of bytes available to read. If blocking is on, and a read request asks for more bytes than what is available, then the thread will block until data becomes available tor read. If blocking is not on, the read request fails..
StreamIO Class
public virtual method<int> Pos()
Parameters
None
Return Value
Current read/write pointer position (or zero if N/A)
Description
Virtual method to return the current pointer position within the stream (one based). The next read or write operation will take place at this position (if direct access is supported). If direct access is not supported, this method has no meaning and returns zero.
StreamIO Class
public virtual method<bool> SetPos(int PointerPosition)
Parameters
PointerPosition
One based position in stream to read/write
Return Value
true if successful
Description
Virtual method to set the current read/write pointer position with the stream (one based). This only applies to stream classes which have direct access turned on. This base class implementation does nothing with the value and it returns a value of false, so it must be overidden by the derived class if it supports direct access.
StreamIO Class
public virtual method<bool> DirectAccess()
Parameters
None
Return Value
Returns true if direct access is supported
Description
Virtual method to return the direct access mode. If true, direct access is supported and if false, direct access is not supported. Direct access means that the Pos() and SetPos() can be used to adjust the next read or write operation.
This implementation of the method always returns false (direct access is not supported). In order to support direct access, a derived class should override this method and return true, as well as the SetPos() method.
StreamIO Class
public abstract method<bool> EndOfStream()
Parameters
None
Return Value
Returns true if at end of stream
Description
Abstract method to return the value of the "end of stream" flag. If there are no bytes available to read, this method returns true and false if there are one or more bytes available to read. Each derived class must override this method and handle it individually.
StreamIO Class
public abstract method Read(int ref IntBucket, int ReadSize = 8, bool PeekOnly = false)
Parameters
IntBucket
Integer reference to receive the value
ReadSize
Size of the read operation
PeekOnly
If true, peek without reading/removing
Return Value
None
Description
Abstract method to read a single binary integer value from the stream and copy the value into the IntBucket. The size of the integer read operation can be specified as 1, 2, 4 or 8 (8 is default).
If the stream is specified as "Write", this method will fire a StreamException.
StreamIO Class
public abstract method Read(float ref FloatBucket, int ReadSize = 8, bool PeekOnly = false)
Parameters
FloatBucket
Float reference to receive the value
ReadSize
Size of the read operation
PeekOnly
If true, peek without reading/removing
Return Value
None
Description
Abstract method to read a single binary floating point value from the stream and copy the value into the FloatBucket. The size of the float read operation can be specified as 4 or 8 (8 is default). A size of 10 will be supported in the future.
If the stream is specified as "Write", this method will fire a StreamException.
StreamIO Class
public abstract method Read(string ref StringBucket, bool ExtractLength = true, int ReadSize = 0, bool PeekOnly = false)
Parameters
StringBucket
String reference to receive the value
ExtractLength
Read the string length from the stream if true
ReadSize
Size of the read operation if ExtractLength is false
PeekOnly
If true, peek without reading/removing
Return Value
None
Description
Abstract method to read a single string from the stream and copy the value into the StringBucket. This supports reading a variable length string, and there are two ways of handling this. If the "ExtractLength" flag is true, the size of the string is actually read from the stream (as a 4 byte integer) and then the string read operation is dictacted by that size. If the "ExtractLength" flag is false, the "ReadSize" value is then used to dictate the length of the string to be read.
If the stream is specified as "Write", this method will fire a StreamException.
StreamIO Class
public abstract method Read(bool ref BoolBucket, bool PeekOnly = false)
Parameters
BoolBucket
Boolean reference to receive the value
PeekOnly
If true, peek without reading/removing
Return Value
None
Description
Abstract method to read a single binary boolean value from the stream and copy the value into the BoolBucket. It is read as a one byte value.
If the stream is specified as "Write", this method will fire a StreamException.
StreamIO Class
public abstract method Read(StreamIO StreamBucket, int ReadSize = 0, bool PeekOnly = false)
Parameters
StreamBucket
Stream reference to receive the value
ReadSize
Size of the binary read operation
PeekOnly
If true, peek without reading/removing
Return Value
None
Description
Abstract method to read a binary block of data from the stream and write it into the target stream (StreamBucket). The size of the read operation is specified. If the target stream supports "random access", the data is written at the current pointer position within that target stream.
If the ReadSize is specified as zero, the read operation goes all the way to the end of this stream.
If the stream is specified as "Write", this method will fire a StreamException.
StreamIO Class
public abstract method Write(int Value, int WriteSize = 8)
Parameters
Value
Integer value to be written
WriteSize
Size of the write operation
Return Value
None
Description
Abstract method to write a single binary integer value to the stream. The size of the integer write operation can be specified as 1, 2, 4 or 8 (8 is default).
If the stream is specified as "Read", this method will fire a StreamException.
StreamIO Class
public abstract method Write(float Value, int WriteSize = 8)
Parameters
Value
Float value to be written
WriteSize
Size of the write operation
Return Value
None
Description
Abstract method to write a single binary floating point value to the stream. The size of the float write operation can be specified as 4 or 8 (8 is default).
If the stream is specified as "Read", this method will fire a StreamException.
StreamIO Class
public abstract method Write(string Value, bool EmbedLength = true, int OverrideLength = 0)
Parameters
Value
String value to be written to stream
EmbedLength
If true, embed string length into stream before the string
OverrideLength
Override length for string to be written
Return Value
None
Description
Abstract method to write a single string to the stream. If the "EmbedLength" flag is true, the length of the string is embedded in the stream before the text string itself (as a 4 byte integer). By default, the entire string is written to the stream, but if "OverrideLength" is greater than zero, then the override length will be used instead.
If the stream is specified as "Read", this method will fire a StreamException.
StreamIO Class
public abstract method Write(bool Value)
Parameters
Value
Boolean value to be written
Return Value
None
Description
Abstract method to write a single binary boolean value to the stream. It is written as a one byte value.
If the stream is specified as "Read", this method will fire a StreamException.
StreamIO Class
public abstract method Write(StreamIO SourceStream, int WriteSize = 0)
Parameters
SourceStream
Source stream reference
WriteSize
Size of the binary write operation
Return Value
None
Description
Abstract method to read a binary block of data from the source stream and write it into this stream. The size of the read and write operation is specified by "WriteSize". If the source stream supports "random access", the data is read from the current pointer position within that source stream and then written into this stream (also at current pointer position if applicable). If the WriteSize is specified as zero, the read operation from the source stream goes all the way to the end of that stream.
If the stream is specified as "Read", this method will fire a StreamException.
StreamIO Class