25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• CopyFrom — Copy the contents of a source stream into this stream.<br />

• NewFileName — Specify a filename for a %FileCharacterStream or %FileBinaryStream<br />

property.<br />

Commonly used properties include the following:<br />

• %Location — The default storage location (directory or global) where the stream will<br />

store its persistent data. If no location is declared for a stream, the %Location for globals<br />

will default to ^ooClassNameS, and the %Location for files will default to the current<br />

<strong>Caché</strong> directory.<br />

• AtEnd — Set to true when a Read encounters the end of the data source.<br />

• Id — The unique identifier for an instance of a stream within the extent specified by<br />

%Location.<br />

• Size — The current size of the stream (in bytes or characters, depending on the type of<br />

stream).<br />

The following sections provide concrete examples using these methods and properties. For<br />

detailed information on individual Stream methods and properties, see the Class Reference<br />

entries for the classes listed at the beginning of this chapter.<br />

15.2.1 Reading and Writing Stream Data<br />

At the core of the Stream interface are the methods Read, Write, and Rewind and the properties<br />

AtEnd and Size.<br />

The following example reads data from the Person.Memo stream and writes it to the console,<br />

100 characters at a time. The value of len is passed by reference, and is reset to 100 before<br />

each Read. The Read method attempts to read the number of characters specified by len,<br />

and then sets it to the actual number of characters read:<br />

Do person.Memo.Rewind()<br />

While (person.Memo.AtEnd = 0) {<br />

Set len = 100<br />

Write person.Memo.Read(.len)<br />

}<br />

Similarly, you can write data into the stream:<br />

Do person.Memo.Write("This is some text. ")<br />

Do person.Memo.Write("This is some more text.")<br />

<strong>Using</strong> the Stream Interface<br />

<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 135

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!