Qore Programming Language Reference Manual  0.8.12
Qore::InputStream Class Referenceabstract

This class defines an abstract interface for input streams. More...

Inheritance diagram for Qore::InputStream:

Public Member Functions

abstract *binary bulkRead (int limit, timeout timeout_ms=-1)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
abstract nothing close ()
 Closes the input stream and releases any resources. More...
 
 constructor ()
 Constructor. More...
 
abstract int read (timeout timeout_ms=-1)
 Reads a single byte from the input stream; returns -1 if the end of the stream has been reached. More...
 

Detailed Description

This class defines an abstract interface for input streams.

Classes inheriting this class can be used to read bytes from various sources.

Since
Qore 0.8.12

Member Function Documentation

abstract *binary Qore::InputStream::bulkRead ( int  limit,
timeout  timeout_ms = -1 
)
pure virtual

Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream.

Parameters
limitthe maximum number of bytes to read
timeout_msa timeout period with a resolution of milliseconds (a relative date/time value; integer arguments will be assumed to be milliseconds); if not given or negative the call will never time out
Returns
the read bytes (the length is between 1 and `limit` inclusive) or NOTHING if no more bytes are available
Example:
1 *binary b;
2 while (b = is.bulkRead(10)) {
3  printf("Read: %y\n", i);
4 }
Exceptions
IO-ERRORif an I/O error occurs
TIMEOUT-ERRORif no byte could be read in the specified timeout

Implemented in Qore::BinaryInputStream, Qore::FileInputStream, and Qore::EncodingConversionInputStream.

abstract nothing Qore::InputStream::close ( )
pure virtual

Closes the input stream and releases any resources.

Any methods called on a closed input stream will thrown an IO-ERROR exception.

Exceptions
IO-ERRORif an I/O error occurs

Implemented in Qore::BinaryInputStream, Qore::FileInputStream, and Qore::EncodingConversionInputStream.

Qore::InputStream::constructor ( )

Constructor.

Used by subclasses defined in the Qore programming language.

abstract int Qore::InputStream::read ( timeout  timeout_ms = -1)
pure virtual

Reads a single byte from the input stream; returns -1 if the end of the stream has been reached.

Parameters
timeout_msa timeout period with a resolution of milliseconds (a relative date/time value; integer arguments will be assumed to be milliseconds); if not given or negative the call will never time out
Returns
the next byte (0 - 255) in the input stream or -1 if the end of the stream has been reached
Example:
1 while ((int i = is.read()) != -1) {
2  printf("Read: %y\n", i);
3 }
Exceptions
IO-ERRORif an I/O error occurs
TIMEOUT-ERRORif no byte could be read in the specified timeout

Implemented in Qore::BinaryInputStream, Qore::FileInputStream, and Qore::EncodingConversionInputStream.