1.34Class StringStream

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
closeToStringClose the stream and returns its contents.
getStringReturns 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
cloneClone the stream handle.
closeCloses the stream.
eofChecks if the last read operation hit the end of the file.
errorDescriptionReturns a system specific textual description of the last error.
flushFlushes a stream.
getBufferingReturns the size of I/O buffering active on this stream.
grabGrabs binary data from the stream.
grabLineGrabs a line of text encoded data.
grabTextGrabs text encoded data from the stream.
isOpenChecks if the stream is currently open.
lastErrorReturn the last system error.
lastMovedReturn the amount of data moved by the last operation.
readReads binary data from the stream.
readAvailableChecks if data can be read, or wait for available data.
readLineReads a line of text encoded data.
readTextReads text encoded data from the stream.
seekMoves the file pointer on seekable streams.
seekCurMoves the file pointer on seekable streams relative to current position.
seekEndMoves the file pointer on seekable streams relative to end of file.
setBufferingSet the buffering state of this stream.
setEncodingSet the text encoding and EOL mode for text-based operations.
tellReturn the current position in a stream.
truncateResizes a file.
writeWrite binary data to a stream.
writeAvailableChecks if data can be written, or wait until it's possible to write.
writeTextWrite text data to a stream.

Methods

closeToString

Close the stream and returns its contents.

StringStream.closeToString()
ReturnThe 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.

getString

Returns the data currently stored in the stream.

StringStream.getString()
ReturnA 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.

Made with http://www.falconpl.org