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

This class implements the OutputStream interface for writing bytes to a String buffer. More...

Inheritance diagram for Qore::StringOutputStream:

Public Member Functions

nothing close ()
 Closes the output stream and releases any resources. More...
 
 constructor ()
 Creates the StringOutputStream. More...
 
 constructor (string encoding)
 Creates the StringOutputStream. More...
 
string getData ()
 Returns the data written to the stream, clearing the internal buffer. More...
 
string getEncoding ()
 Returns the character encoding for the StringOutputStream. More...
 
nothing write (binary data)
 Writes bytes to the output stream. More...
 
- Public Member Functions inherited from Qore::OutputStream
 constructor ()
 Constructor. More...
 

Detailed Description

This class implements the OutputStream interface for writing bytes to a String buffer.

Since
Qore 0.8.13
Example: StringOutputStream basic usage
1 StringOutputStream sos();
2 sos.write(<41>);
3 sos.write(<42>);
4 sos.write(<43>);
5 sos.getData(); # returns "ABC"

Member Function Documentation

nothing Qore::StringOutputStream::close ( )
virtual

Closes the output stream and releases any resources.

Any methods called on a closed output stream will throw an exception.

Implements Qore::OutputStream.

Qore::StringOutputStream::constructor ( )

Creates the StringOutputStream.

This variant assumes the Default Character Encoding for the string

Note
raw binary data will be written to the string; it's up to the caller to ensure that only valid character data for the given encoding is written to the StringOutputStream object, otherwise a string with invalid character data will be returned by getData()
Qore::StringOutputStream::constructor ( string  encoding)

Creates the StringOutputStream.

Parameters
encodingthe encoding to tag the string data with
Note
raw binary data will be written to the string; it's up to the caller to ensure that only valid character data for the given encoding is written to the StringOutputStream object, otherwise a string with invalid character data will be returned by getData()
string Qore::StringOutputStream::getData ( )

Returns the data written to the stream, clearing the internal buffer.

Returns
the data written to the StringOutputStream
Example:
1 StringOutputStream sos();
2 sos.write(<41>);
3 sos.write(<42>);
4 sos.write(<43>);
5 sos.getData(); # returns "ABC"
string Qore::StringOutputStream::getEncoding ( )

Returns the character encoding for the StringOutputStream.

Code Flags:
CONSTANT
Example:
1 StringOutputStream sos("latin1");
2 string encoding = sos.getEncoding();
Returns
the character encoding for the StringOutputStream
nothing Qore::StringOutputStream::write ( binary  data)
virtual

Writes bytes to the output stream.

Parameters
datathe data to write
Example:
1 StringOutputStream sos();
2 sos.write(<41>);
3 sos.write(<42>);
4 sos.write(<43>);
5 sos.getData(); # returns "ABC"

Implements Qore::OutputStream.