Stream classes
The stream classes are ReadStream, ReadWriteStream, and WriteStream. Described in Chapter 12 of the Blue Book, streams provide an abstraction that enables store and retrieve operations to be performed on the elements of an underlying composite data structure, usually an indexed collection. In particular, a stream remembers the position of the last element in the data structure to be read or written. Streams are positionable, that is, the current read/write position can be changed using the stream's public interface. This allows elements to be accessed in either a sequential or nonsequential fashion.
It is implicit in stream semantics that the elements of the underlying data structure are sequentially ordered. With respect to the CLDT classes, a ReadWriteStream or WriteStream can stream over a String, DBString, OrderedCollection, ByteArray, or Array. A ReadStream can stream over the same set of classes plus Interval, SortedCollection, or Symbol.
Note:
One significant change has been made to Blue Book streams -- each CLDT stream has an instance variable that holds a string called a line delimiter. By far the most common use of streams in practice is to read or write String data. Every platform uses a sequence of one or two characters to mark the end of a line in a multiline string or text file. This character sequence is referred to as the platform line delimiter. Platforms use different line delimiters. For example, the UNIX line delimiter is a Line Feed, while Windows uses the sequence Carriage Return followed by Line Feed. The platform line delimiters that are supported by CLDT are all available in the pool dictionary CldtConstantsand are listed in Table 3. When a new CLDT stream is created, its line delimiter is always set to be the correct line delimiter for the platform.
However, the line delimiter can also be changed dynamically, and it is not necessary to always use the platform line delimiter. Prior to VA Smalltalk 9.1, it was necessary to allow developers to easily read or write a String obtained from or intended for other platforms to eliminate a serious obstacle to portability. In VA Smalltalk 9.1 the streams auto-detect the line endings when using nextLine which makes reading stream content not only portable but also seamless.
The following table lists protocols supported by Stream classes.
Table 4. Protocols supported by Stream classes
 
Accessing
Copying
Enumer- ating
Position- ing
Reading
Testing
Truncating
Writing
ReadStream
X
X
X
X
X
X
 
 
ReadWrite- Stream
X
X
X
X
X
X
X
X
WriteStream
X
 
 
X
 
X
 
X
 
Last modified date: 02/17/2021