|
Class: ReadWriteStream
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--ReadWriteStream
|
+--ExternalStream
|
+--RWBinaryOrTextStream
- Package:
- stx:libbasic
- Category:
- Streams
- Version:
- rev:
1.51
date: 2021/11/27 13:50:39
- user: cg
- file: ReadWriteStream.st directory: libbasic
- module: stx stc-classLibrary: libbasic
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 ...
copyrightCOPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
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.
Obsolete - use #reset.
** 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
-
collectionSize
-
return the overall number of elements in the streamed collection
(both already read and to be read).
-
remainingSize
-
return the number of remaining elements to read in the streamed collection.
-
size
-
return the number of elements in the streamed collection.
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 stream's type - (see #contentsSpecies).
-
peek
-
return the element to be read next without advancing read position.
If there are no more elements, nil is returned.
testing
-
isEmpty
-
redefinde from WriteStream
-
isReadable
-
return true if the receiver supports reading - that's true
|s|
s := ReadWriteStream with:'abcd'.
s reset.
s nextPut:$A.
s contents
|