This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Home > Class Reference > ENSLIB namespace > %IO.LibraryStream


class %IO.LibraryStream extends %Library.AbstractStream

Adapts %IO stream classes to provide a legacy %Library.AbstractStream interface

Property Inventory

Method Inventory


property AtEnd as %Boolean;
Inherited description: The AtEnd property is set to true (1) when, during a read, a stream has reached the end of its data source.
Property methods: AtEndDisplayToLogical(), AtEndGet(), AtEndIsValid(), AtEndLogicalToDisplay(), AtEndNormalize(), AtEndSet()
property IOStream as %IO.I.Stream;
The %IO.I.Stream that we are wrapping
Property methods: IOStreamGet(), IOStreamGetSwizzled(), IOStreamIsValid(), IOStreamNewObject(), IOStreamSet()
property LastModified as %TimeStamp [ Calculated , ReadOnly ];
Inherited description: LastModified is a read-only property containing the %TimeStamp of the last modification to this stream. If the stream is null then it will report "".
Property methods: LastModifiedDisplayToLogical(), LastModifiedGet(), LastModifiedIsValid(), LastModifiedLogicalToDisplay(), LastModifiedNormalize(), LastModifiedOdbcToLogical()
property LineTerminator as %String (MAXLEN = 10);
Inherited description: Type of line terminator we use for this stream, defaults to Cr/Lf. Maximum length is 10 characters. This is stored as an attribute of the stream called 'LineTerminator'.
Property methods: LineTerminatorDisplayToLogical(), LineTerminatorGet(), LineTerminatorIsValid(), LineTerminatorLogicalToDisplay(), LineTerminatorLogicalToOdbc(), LineTerminatorNormalize(), LineTerminatorSet()
property Size as %Integer [ Calculated ];
Inherited description: Size is a read-only property containing the current size of the stream (in bytes for a binary stream and characters for a character stream).

If a specific stream implementation cannot determine the size of the stream then Size will be equal to -1.
VMS does not support moving to a position in a file or providing the current position in a file. On VMS if a BOM is included at the start of the file it may be included in the size calculated.

Property methods: SizeDisplayToLogical(), SizeGet(), SizeIsValid(), SizeLogicalToDisplay(), SizeNormalize()


method AtEndGet() as %Boolean
method Clear() as %Status
Inherited description: Clear the contents of this Stream from permanent storage. This will remove the permanent stream storage and any temporary stream and initialise the stream to its initial state that it starts in, including removing all the stream attributes.

Returns a %Status value indicating success or failure.

method CopyFrom(source As %Stream.Object) as %Status
Copy the contents of the given source %IO, %Library or %Stream stream to the wrappered %IO stream
method CopyFromAndSave(source As %Stream.Object) as %Status
Inherited description: Copy the stream from source into the current stream ignoring anything already in the current stream and save the result to the permanent location. This is used to optimise the copying of say a %GlobalCharacterStream to another %GlobalCharacterStream to avoid copying into temporary storage first and then moving this to the permanent storage when SaveStream() is called.

Note that any locking or transaction handling must be done by the caller.

method FindAt(position As %Library.Integer, target As %Library.CacheString, ByRef tmpstr As %Library.CacheString, caseinsensitive As %Library.Boolean = 0) as %Integer
Find the first occurrence of target in the stream starting the search at position. It returns the position at this match starting at the beginning of the stream. If it does not find the target string then return -1. If position=-1 then start searching from the current location and just return the offset from the last search, useful for searching through the entire file. If you are doing this you should pass in tmpstr by reference in every call which is used as a temporary location to store information being read so the next call will start where the last one left off.
method Flush() as %Status
Inherited description: Flush any output in the stream not already saved.
method InputFromDevice(ByRef len As %Integer = 0, timeout As %Integer = 20) as %Status
Input len characters from the current device into the stream. This is equivalent to doing a series of reads and calling Write() for each of them but it may be optimised by the subclasses. On return len will be the number of characters still to read in (if no timeout has occured this should be 0).
method LastModifiedGet() as %TimeStamp
method LineTerminatorGet() as %String
method LineTerminatorSet(terminator As %String) as %Status
method MoveTo(position As %Integer) as %Boolean
Inherited description: Move to this position in the stream. If this suceeds then return true, else return false. Note this implementation is not efficient because it searches from the start of the stream, it can be improved upon in specific subclasses. Note that moving to position 1 will be at the start of the stream, position 2 will be at the second character of the stream, etc.
method MoveToEnd() as %Status
Inherited description: Move to the end of the stream so the next Write will be appended to the end. This allows you to read from a stream, then MoveToEnd() and append new data, where just calling Write() after a read will clear the stream before writing new data.

Returns a %Status value indicating success or failure.

method OutputToDevice(ByRef len As %Integer = -1) as %Status
Write out len characters of the stream to the current device starting from the current position. This method is optimised for performance by the various sub classes. If len is omitted or set to -1 then it will write out the entire stream starting at the beginning.
method OutputToDeviceAt(position As %Integer, ByRef length As %Integer) as %Status
Output the stream to the current device starting at position of length length. The length if passed by reference returns the number of characters output.
method Read(ByRef len As %Integer = 32000, ByRef sc As %Status) as %CacheString
Inherited description: Reads up to len characters from the current position in the stream. The current position is advanced by the number of characters read. Upon exit, len is set to the actual number of characters read. If a read occurs when the stream position is at the end of the stream, len will be set to -1 and Read() will return a null string (""). If no len is passed in, ie. 'Read()' then it is up to the Read implementation as to how much data to return. Some stream classes use this to optimize the amount of data returned to align this with the underlying storage of the stream.

You must call Rewind() if you want to read a stream from the beginning again. Calling Read() after Write() implicitly ends the Write() operation and rewinds to the start of the stream.

Returns a string up to len characters long. The byref argument sc will return a %Status if any error occurred during the read.

method ReadLine(ByRef len As %Integer = 32000, ByRef sc As %Status, ByRef eol As %Boolean) as %CacheString
Inherited description: Read a line from the stream. This will look for the line terminator in the stream and once it finds the terminator it will return the string minus the terminator character/s. If it reaches the end of the stream before it finds a terminator it will return the data it has so far, and if you specify a maximum size in len it will only read up to this number of characters. On exit len will contain the actual number of characters read. The byref argument sc will return a %Status if any error occured during the read and the byref argument eol is true if it found the line terminator and false otherwise. So for example you can read in a stream a line at a time and output the results to the current device with:
While 'stream.AtEnd { Write stream.ReadLine(,.sc,.eol) If $$$ISERR(sc) { Write "ERROR" Quit } If eol { Write ! } }
method ReadLineIntoStream(ByRef sc As %Status) as %Library.AbstractStream
Inherited description: This reads from the stream until it find the LineTerminator and returns this as a stream. If the stream does not contain the line terminator this can potentially be the entire stream.
method Rewind() as %Status
Inherited description: Go back to the start of the stream.
method SizeGet() as %Integer
method Write(data As %CacheString) as %Status
Inherited description: Appends the string data to the stream and advances the current stream position by the number of characters in data.

Note that a write operation immediately following a read or rewind will clear out the existing data in the stream.

Returns a %Status value indicating success or failure.

method WriteLine(data As %CacheString = "") as %Status
Appends the string data along with a line terminator to the stream and advances the current stream position by the number of characters in data plus the line terminator.

Returns a %Status value indicating success or failure.

Inherited Members

Inherited Properties

Inherited Methods