Qore Programming Language Reference Manual  0.8.12.3
Qore::StringInputStream Class Reference

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

Inheritance diagram for Qore::StringInputStream:

Public Member Functions

 constructor (string src)
 Creates the StringInputStream based on the String given. More...
 
string getEncoding ()
 Returns the character encoding for the StringInputStream. More...
 
*binary read (int limit)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
- Public Member Functions inherited from Qore::InputStream
 constructor ()
 Constructor. More...
 

Detailed Description

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

Since
Qore 0.8.13
Example: StringInputStream basic usage
1 string src = "abc";
2 StringInputStream sis(src);
3 *binary b;
4 while (b = sis.read(2)) {
5  printf("read %s\n", make_hex_string(b));
6 }
7 
8 read 6162
9 read 63

Member Function Documentation

Qore::StringInputStream::constructor ( string  src)

Creates the StringInputStream based on the String given.

Parameters
srcthe String to read bytes from
string Qore::StringInputStream::getEncoding ( )

Returns the character encoding for the StringInputStream.

Code Flags:
CONSTANT
Example:
1 string src = "xyz";
2 StringInputStream is(src);
3 string encoding = is.getEncoding();
Returns
the character encoding for the StringInputStream
*binary Qore::StringInputStream::read ( int  limit)
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
Returns
the read bytes (the length is between 1 and `limit` inclusive) or NOTHING if no more bytes are available
Example:
1 string src = "xyz";
2 StringInputStream is(src);
3 *binary b;
4 while (b = is.read(2)) {
5  printf("read %s\n", make_hex_string(b));
6 }
7 
8 read 7879
9 read 7a

Implements Qore::InputStream.