eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ReadWriteStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ReadWriteStream


Inheritance:

   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

Description:


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 ...


Instance protocol:

access-reading
o  next
return the next element; advance read position.
If there are no more elements, nil is returned.

o  next: count
return the next count elements of the stream as aCollection,
which depends on the streams type - (see #contentsSpecies).

accessing
o  clear
re-initialize the stream to write to the beginning and
to not read any data.

o  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.

o  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.

o  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
o  readStream
return the receiver as a readStream - that's myself

o  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
o  with: initialCollection
redefined from WriteStream, to position to the beginning of the stream

queries
o  isReadable
return true if the receiver supports reading - that's true

o  size
return the number of elements in the streamed collection.

reading
o  peek
return the element to be read next without advancing read position.
If there are no more elements, nil is returned.


Examples:


|s| s := ReadWriteStream with:'abcd'. s reset. s nextPut:$A. s contents

ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 22 Jul 2018 03:05:25 GMT