|
Class: ReadWriteStream
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--ReadWriteStream
|
+--ExternalStream
|
+--RWBinaryOrTextStream
- Package:
- stx:libbasic
- Category:
- Streams
- Version:
- rev:
1.44
date: 2018/05/08 18:20:43
- user: cg
- file: ReadWriteStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
ReadWriteStreams allow both read- and write-access to some collection.
To allow this, they reenable some methods blocked in WriteStream.
(being one of the seldom places, where multiple inheritance could be
of good use in smalltalk).
[caveat:]
Basing capabilities like readability/writability/positionability/peekability on inheritance makes
the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
below PositionableStream or ExternalReadStream under WriteStream)
Claus:
I personally find the ReadStream - WriteStream - ReadWriteStream
organization brain-damaged. It would be better to have an attribute
(such as readOnly / writeOnly / readWrite) in an InternalStream subclass
of Stream ...
access-reading
-
next
-
return the next element; advance read position.
If there are no more elements, nil is returned.
-
next: count
-
return the next count elements of the stream as aCollection,
which depends on the streams type - (see #contentsSpecies).
accessing
-
clear
-
re-initialize the stream to write to the beginning and
to not read any data.
-
contents
-
return the contents as written so far;
redefined to prevent confusion resulting due to
my superclasses optimization. (see WriteStream contents).
ST80 users of ReadWriteStream may expect the contents array to remain
unchanged, which we do not guarantee.
-
reset
-
set the read position to the beginning of the collection.
Because I am a read/write stream, the readLimit is set to the current write position.
Thus, the just written data can be read back.
-
resetPosition
-
set the read position to the beginning of the collection.
Because I am a read/write stream, the readLimit is set to the current write position.
Thus, the just written data can be read back.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
converting
-
readStream
-
return the receiver as a readStream - that's myself
-
readStreamOrNil
-
return a readStream from the receiver. Since this is already
a readStream, return self.
This method has been defined for protocol copmatibility with Filename
initialization
-
with: initialCollection
-
redefined from WriteStream, to position to the beginning of the stream
queries
-
isReadable
-
return true if the receiver supports reading - that's true
-
size
-
return the number of elements in the streamed collection.
reading
-
peek
-
return the element to be read next without advancing read position.
If there are no more elements, nil is returned.
|s|
s := ReadWriteStream with:'abcd'.
s reset.
s nextPut:$A.
s contents
|