Qore Programming Language Reference Manual  0.8.12
Qore::BinaryInputStream Class Reference

This class implements the InputStream interface for reading bytes from a Binary variable. More...

Inheritance diagram for Qore::BinaryInputStream:

Public Member Functions

*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...
 
nothing close ()
 Closes the input stream and releases any resources. More...
 
 constructor (binary src)
 Creates the BinaryInputStream based on the Binary given. More...
 
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...
 
- Public Member Functions inherited from Qore::InputStream
 constructor ()
 Constructor. More...
 

Detailed Description

This class implements the InputStream interface for reading bytes from a Binary variable.

Since
Qore 0.8.12
Example: BinaryInputStream basic usage
1 binary src = <2AFF04>;
2 BinaryInputStream bis(src);
3 while ((int i = bis.read()) != -1) {
4  printf("read %d\n", i);
5 }
6 
7 read 42
8 read 255
9 read 4

Member Function Documentation

*binary Qore::BinaryInputStream::bulkRead ( int  limit,
timeout  timeout_ms = -1 
)
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_msignored
Returns
the read bytes (the length is between 1 and `limit` inclusive) or NOTHING if no more bytes are available
Example:
1 binary src = <2AFF04>;
2 BinaryInputStream is(src);
3 *binary b;
4 while (b = is.bulkRead(2)) {
5  printf("read %s\n", make_hex_string(b));
6 }
7 
8 read 2aff
9 read 04

Implements Qore::InputStream.

nothing Qore::BinaryInputStream::close ( )
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

Implements Qore::InputStream.

Qore::BinaryInputStream::constructor ( binary  src)

Creates the BinaryInputStream based on the Binary given.

Parameters
srcthe Binary to read bytes from
int Qore::BinaryInputStream::read ( timeout  timeout_ms = -1)
virtual

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

Parameters
timeout_msignored
Returns
the next byte (0 - 255) in the input stream or -1 if the end of the stream has been reached
Example:
1 binary src = <2AFF04>;
2 BinaryInputStream bis(src);
3 while ((int i = bis.read()) != -1) {
4  printf("read %d\n", i);
5 }
6 
7 read 42
8 read 255
9 read 4

Implements Qore::InputStream.