This class defines a stream reader for input streams.
More...
#include <QC_StreamReader.dox.h>
This class defines a stream reader for input streams.
- Since
- Qore 0.8.13
- Example: StreamReader basic usage
FileInputStream is("data.txt");
StreamReader sr(is, "UTF-8");
*string line = sr.readLine();
*binary b = sr.readBinary(256);
int i = sr.readi4();
- See also
- Qore::InputStream
◆ constructor()
◆ getEncoding()
string Qore::StreamReader::getEncoding |
( |
| ) |
|
◆ getInputStream()
◆ readBinary()
*binary Qore::StreamReader::readBinary |
( |
int |
limit = -1 | ) |
|
Reads binary data from the input stream up to a given limit.
- Example:
*binary b = sr.readBinary(16);
- Parameters
-
limit | maximum amount of binary data to read; if not given or equal to -1, all the data from the InputStream will be read; if equal to 0, NOTHING will be read |
- Returns
- a Binary value or NOTHING if there is no more data available in the stream
- Note
- a short read (a binary object returned with fewer bytes than requested) indicates that there is no more data left in the stream
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi1()
int Qore::StreamReader::readi1 |
( |
| ) |
|
Reads a 1-byte signed integer from the input stream.
- Example:
- Returns
- a 1-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi2()
int Qore::StreamReader::readi2 |
( |
| ) |
|
Reads a 2-byte (16 bit) signed integer from the input stream in binary big-endian format.
- Example:
- Returns
- a 2-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi2LSB()
int Qore::StreamReader::readi2LSB |
( |
| ) |
|
Reads a 2-byte (16 bit) signed integer from the input stream in binary little-endian format.
- Example:
- Returns
- a 2-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi4()
int Qore::StreamReader::readi4 |
( |
| ) |
|
Reads a 4-byte (32 bit) signed integer from the input stream in binary big-endian format.
- Example:
- Returns
- a 4-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi4LSB()
int Qore::StreamReader::readi4LSB |
( |
| ) |
|
Reads a 4-byte (32 bit) signed integer from the input stream in binary little-endian format.
- Example:
- Returns
- a 4-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi8()
int Qore::StreamReader::readi8 |
( |
| ) |
|
Reads a 8-byte (64 bit) signed integer from the input stream in binary big-endian format.
- Example:
- Returns
- a 8-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readi8LSB()
int Qore::StreamReader::readi8LSB |
( |
| ) |
|
Reads a 8-byte (64 bit) signed integer from the input stream in binary little-endian format.
- Example:
- Returns
- a 8-byte signed integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readLine()
Reads a text line from the input stream.
- Example:
string line = sr.readLine("\n");
- Parameters
-
eol | the optional end of line character(s) to use to detect lines in the data - can be maximally 2 bytes long; if it is longer, the rest is ignored; if this string is not passed, then, if the character-encoding is ASCII-compatible, the end of line character(s) are detected automatically from "\n" , "\r" , or "\r\n" ; if the stream uses a non-ASCII-compatible character encoding, then "\n" is assumed |
trim | if True the returned lines will be trimmed of the eol bytes |
- Returns
- a text line read from the stream or NOTHING if there is no more data available in the stream
- Exceptions
-
ENCODING-CONVERSION-ERROR | this exception could be thrown if the eol argument has a different character encoding from the data's and an error occurs during encoding conversion |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readString()
*string Qore::StreamReader::readString |
( |
int |
limit = -1 | ) |
|
Reads a string from the input stream.
- Example:
string str = sr.read(len);
- Parameters
-
limit | maximum amount of characters of string data to read; if not given or equal to -1, all the data from the InputStream will be read; if equal to 0, NOTHING will be read |
- Returns
- a String value or NOTHING if there is no more data available in the stream
- Exceptions
-
STREAM-ENCODING-ERROR | this exception is thrown if invalid character data is detected on the stream; this exception is not thrown when limit is negative, in such cases the input data is not verified |
- Note
- a short read (a string returned with fewer characters than requested) indicates that there is no more data left in the stream
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readu1()
int Qore::StreamReader::readu1 |
( |
| ) |
|
Reads a 1-byte unsigned integer from the input stream.
- Example:
- Returns
- a 1-byte unsigned integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readu2()
int Qore::StreamReader::readu2 |
( |
| ) |
|
Reads a 2-byte (16 bit) unsigned integer from the input stream in binary big-endian format.
- Example:
- Returns
- a 2-byte unsigned integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readu2LSB()
int Qore::StreamReader::readu2LSB |
( |
| ) |
|
Reads a 2-byte (16 bit) unsigned integer from the input stream in binary little-endian format.
- Example:
- Returns
- a 2-byte unsigned integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readu4()
int Qore::StreamReader::readu4 |
( |
| ) |
|
Reads a 4-byte (32 bit) unsigned integer from the input stream in binary big-endian format.
- Example:
- Returns
- a 4-byte unsigned integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation
◆ readu4LSB()
int Qore::StreamReader::readu4LSB |
( |
| ) |
|
Reads a 4-byte (32 bit) unsigned integer from the input stream in binary little-endian format.
- Example:
- Returns
- a 4-byte unsigned integer
- Exceptions
-
END-OF-STREAM-ERROR | there is not enough data available in the stream |
- Note
- other stream read errors could be thrown here depending on the underlying InputStream implementation