Memory based stream.
Class StringStream( [buffer] ) from \ Stream( )
buffer | The buffer that will be used as stream |
The StringStream class inherits from stream. It can be used to provide functions that are supposed to write to streams with a memory buffer; for example, variables may be serialized on a string stream which can be then written completely on a physical stream, or sent over the network, or written in a database blob field. The reverse is of course possible: a string can be read from any source and then used to construct a StringStream, that can be then fed to function expecting streams as parameters.
Of course, all the methods listed in the Stream class are available also here.
The StringStream is always available for read and write operations, and supports seek operations. Writing past the end of the stream will cause the StringStream to grow.
If the parameter buffer is a numeric value, the constructor preallocates the given size. Writes up to buffer size won't require re-allocation, and the size will be used as a hint to grow the stream buffer sensibly.
If a string is provided, it is used as initial contents of the StringStream; subsequent reads will return the data contained in the string.
Methods | |
closeToString | Close the stream and returns its contents. |
getString | Returns the data currently stored in the stream. |
Properties inherited from class Stream | |
encoding | Name of the set encoding, if given, for text operations |
eolMode | Mode of EOL conversion in text operations. |
Methods inherited from class Stream | |
clone | Clone the stream handle. |
close | Closes the stream. |
eof | Checks if the last read operation hit the end of the file. |
errorDescription | Returns a system specific textual description of the last error. |
flush | Flushes a stream. |
getBuffering | Returns the size of I/O buffering active on this stream. |
grab | Grabs binary data from the stream. |
grabLine | Grabs a line of text encoded data. |
grabText | Grabs text encoded data from the stream. |
isOpen | Checks if the stream is currently open. |
lastError | Return the last system error. |
lastMoved | Return the amount of data moved by the last operation. |
read | Reads binary data from the stream. |
readAvailable | Checks if data can be read, or wait for available data. |
readLine | Reads a line of text encoded data. |
readText | Reads text encoded data from the stream. |
seek | Moves the file pointer on seekable streams. |
seekCur | Moves the file pointer on seekable streams relative to current position. |
seekEnd | Moves the file pointer on seekable streams relative to end of file. |
setBuffering | Set the buffering state of this stream. |
setEncoding | Set the text encoding and EOL mode for text-based operations. |
tell | Return the current position in a stream. |
truncate | Resizes a file. |
write | Write binary data to a stream. |
writeAvailable | Checks if data can be written, or wait until it's possible to write. |
writeText | Write text data to a stream. |
Close the stream and returns its contents.
StringStream.closeToString()
Return | The stream contents. |
Closes the stream and returns the contents of the stream as a string. The object is internally destroyed, and the whole content is transformed into the returned string. In this way, an extra allocation and copy can be spared.
Returns the data currently stored in the stream.
StringStream.getString()
Return | A copy of the contents of this stream. |
The data currently held in the stream is left untouched, and a new copy of the data is returned.