Programmer Reference : Unicode Support : UnicodeReadWriteStream
UnicodeReadWriteStream
Description
This is an adapter class used for bridging <UnicodeView>s with <ReadWriteStream>s. By default, this streams 'graphemes' which are user-perceived characters. A grapheme is represented in VAST by a <Grapheme> object.
Instance State
refreshView: <Boolean> true if the internal view needs to be refreshed (i.e. write occurred)
Class Methods
on:
  Answer a new instance of the receiver, streaming over argument
     aSequenceableCollection.
Instance Methods
asStream
  Answer the receiver.
contents
  Answer a Collection which is a copy collection that the receiver is
     streaming over, truncated to the current position reference.

     Example:
        | stream |
        stream := UnicodeReadWriteStream on: UnicodeString new.
        stream nextPutAll: 'Smalltalk'.
        self assert: [stream contents = 'Smalltalk']

     Answers:
        <UnicodeString>
next
  Answer an Object that is the next accessible by the
     receiver. Change the state of the receiver so that
     returned object is no longer accessible.

     Example:
        self assert: [('Smalltalk' asUnicodeString readStream next; next; next) = $a asGrapheme].
        self assert: [('Smalltalk' asUnicodeString readStream switchToUnicodeScalarMode; next; next; next) = $a asUnicodeScalar].

     Answers:
        <Object> view object
next:
  Answer a collection containing the next @anInteger elements from the view.
     If @anInteger < 1, an empty collection is answered

     Example:
        self assert: [('Smalltalk' asUnicodeString readStream next: 5) = 'Small'].
        self assert: [| stream |
            stream := 'Smalltalk' asUnicodeString readStream.
            (stream switchToUnicodeScalarMode; next: 5) = 'Small' unicodeScalars contents]

     Arguments:
        anInteger - <Integer>
     Answers:
        <Object> instance of view collection class
     Raises:
        <Exception> ExCLDTIndexOutOfRange
next:into:startingAt:
  Answer @anIndexedCollection with the next @anInteger number of items from
     the receiver, stored starting at position @initialPosition.

     If the receiver's state is such that there are fewer than anInteger
     elements between its current position and the end of the stream,
     the operation will fail, and the receiver will be left in a state
     such that it answers true to the atEnd message.

     Example:
        | col |
        col := Array new: 5.
        'Smalltalk' asUnicodeString readStream next: 5 into: col startingAt: 1.
        self assert: [col = 'Small' asUnicodeString asArray]

     Arguments:
        anInteger - <Integer>
        anIndexedCollection - <Collection>
        initialPosition - <Integer>
     Answers:   
        <Collection> - anIndexedCollection
nextLine
  Answer the elements between the current position and the next lineDelimiter.

     Example:
        | stream |
        stream := ('Small' , String lf , 'talk' , String cr , 'er' , String crlf , 's') asUnicodeString readStream.
        self assert: [stream nextLine = 'Small'].
        self assert: [stream nextLine = 'talk'].
        self assert: [stream nextLine = 'er'].
        self assert: [stream nextLine = 's'].
        stream switchToUnicodeScalarMode.
        self assert: [stream nextLine = 'Small' unicodeScalars contents].
        self assert: [stream nextLine = 'talk' unicodeScalars contents].
        self assert: [stream nextLine = 'er' unicodeScalars contents].
        self assert: [stream nextLine = 's' unicodeScalars contents].
        self assert: stream atEnd.

     Answers:
        <Object> view-dependent
nextPut:
  Store the argument anObject at the next position
     accessible to the receiver. Answer anObject. Change the
     state of the receiver so that the argument anObject is no
     longer accessible.

     This sets the 'refreshView' flag so we are sure to update
     the view on a subsequent read.

     Example:
        self assert: [((UnicodeReadWriteStream on: UnicodeString new)
                                nextPut: $S;
                                nextPut: $T;
                                position: 0;
                                upToEnd) = 'ST']

     Arguments:
        anObject - <Object> @see implementors of #asGrapheme
     Answers:
        <Grapheme> anObject converted to Grapheme
nextPutAll:
  Store each of the elements of aCollection starting at the current
     position accessible to the receiver.  Answer aCollection.  Change
     the state of the receiver so that the objects contained with
     aCollection are no longer accessible.

     This sets the 'refreshView' flag so we are sure to update
     the view on a subsequent read.

     Example:
        self assert: [((UnicodeString new writeStream)
                                nextPutAll: 'Smalltalk' asUnicodeString;
                                position: 0;
                                upToEnd) = 'Smalltalk']

     Arguments:
        aCollection - <Object> @see implementors of #asUnicodeString
     Answers:
        <UnicodeString> aCollection converted to UnicodeString
peek
  Answer an Object that is the next accessible by the receiver.
     Change the state of the receiver so that returned object is no longer accessible.
     Answer nil if the view is atEnd

     Example:
        self assert: [('' asUnicodeString readStream peek) isNil].
        self assert: [('Smalltalk' asUnicodeString readStream peek) = $S asGrapheme].
        self assert: [('Smalltalk' asUnicodeString readStream switchToUnicodeScalarMode; peek) = $S asUnicodeScalar].       

     Answers:
        <Object> or nil if at end
position:
  Set the receiver's position reference to argument anInteger.

     Arguments:
        anInteger - <Integer>
     Answers:
        <UnicodeWriteStream> receiver
     Raises:
        <Exception> ExCLDTIndexOutOfRange if anInteger is out of range
skip:
  Increment the receiver's current reference position by anInteger.
     Fail if anInteger is not a kind of Integer.

     Example:
        self assert: [('abcde' asUnicodeString readStream skip: 2; upToEnd) = 'cde']

     Arguments:
        anInteger - <Integer>
     Raises:
        <Exception> ExCLDTIndexOutOfRange
skipTo:
  Read and discard elements just past the occurrence of @anObject.

     Example:
        self assert: [('abcde' asUnicodeString readStream skipTo: $c; upToEnd) = 'de'].
        self assert: [('abcde' asUnicodeString readStream skipTo: $z; upToEnd) = '']

     Arguments:
        anObject - <Object>
     Answers:
        <Boolean> true if found, false otherwise
skipToAll:
  Attempt to read and discard elements just past the occurrence of @aSequentialCollection.
     Answer true if all elements in @aSequentialCollection occurred, else answer false.

     Note:
        If aSequentialCollection is an EsString, then we attempt ot convert to a UnicodeString

     Example:
        self assert: ['abcde' asUnicodeString readStream skipToAll: 'bc'].
        self assert: [('abcde' asUnicodeString readStream skipToAll: 'bc'; upToEnd) = 'de'].
        self assert: [('abcde' asUnicodeString readStream skipToAll: 'zzz') not].
        self assert: [('abcde' asUnicodeString readStream skipToAll: 'zzz'; upToEnd) = ''].

     Arguments:
        aSequentialCollection - <aSequentialCollection>
     Answers:
        <Boolean>
skipToAny:
  Read and discard elements beyond the next occurrence
     of an element that exists in @aSequentialCollection or if none,
     to the end of stream.

     Answer true if an element in @aSequentialCollection
     occurred, else answer false.

     Note:
        If aSequentialCollection is an EsString, then we attempt ot convert to a UnicodeString

     Example:
        self assert: ['abcde' asUnicodeString readStream skipToAny: 'bd'].
        self assert: [('abcde' asUnicodeString readStream skipToAny: 'bd'; upToEnd) = 'cde'].
        self assert: [('abcde' asUnicodeString readStream skipToAny: 'zzz') not].
        self assert: [('abcde' asUnicodeString readStream skipToAny: 'zzz'; upToEnd) = ''].

     Arguments:
        aSequentialCollection - <aSequentialCollection>
     Answers:
        <Boolean>
truncate
  Set the size of the receiver stream to its current position.

     Example:
        | stream |
        stream := ReadWriteStream on: UnicodeString new.
        stream nextPutAll: 'Smalltalk'.
        self assert: [stream contents = 'Smalltalk'].
        stream position: 5.
        self assert: [stream contents = 'Smalltalk'].
        stream truncate.
        self assert: [stream contents = 'Small'].

upTo:
  Answers a collection of all of the objects in the view
     beginning from the current position up to, but not including,
     @anObject.

     Example:
        self assert: [('abcde' asUnicodeString readStream upTo: $c) = 'ab'].
        self assert: [('abcde' asUnicodeString readStream upTo: $z) = 'abcde']

     Arguments:
        anObject - <Object>
     Answers:
        <Object> instance of view collection class
upToAll:
  Answers a collection of all of the objects in the view beginning from the current position up to,
     but not including, @aSequenceableCollection

     Note:
        If aSequenceableCollection is an EsString, then we attempt ot convert to a UnicodeString

     Example:
        self assert: [('abcde' asUnicodeString readStream upToAll: 'bc') = 'a'].
        self assert: [('abcde' asUnicodeString readStream upToAll: 'bc'; upToEnd) = 'de'].
        self assert: [('abcde' asUnicodeString readStream upToAll: 'zzz') = 'abcde'].
        self assert: [('abcde' asUnicodeString readStream upToAll: 'zzz'; upToEnd) isEmpty].

     Arguments:
        aSequenceableCollection - <SequenceableCollection>
     Answers:
        <Object> instance of view collection class
upToAny:
  Answers a collection of all of the objects in the view up to, but not including, the next occurrence
     of the element that exists in @aSequenceableCollection.  If the element that exists in @aSequenceableCollection
     is not found and the end of the view is encountered, a collection of the objects read is returned.

     Note:
        If aSequenceableCollection is an EsString, then we attempt ot convert to a UnicodeString

     Example:
        self assert: [('abcde' asUnicodeString readStream upToAny: 'bd') = 'a'].
        self assert: [('abcde' asUnicodeString readStream upToAny: 'bd'; upToEnd) = 'cde'].
        self assert: [('abcde' asUnicodeString readStream upToAny: 'zzz') = 'abcde'].
        self assert: [('abcde' asUnicodeString readStream upToAny: 'zzz'; upToEnd) isEmpty].

     Arguments:
        aSequenceableCollection - <SequenceableCollection>
     Answers:
        <Object> view collection class
upToEnd
  Answer a collection containing UP TO the maximum number of elements read from the view.
     If there are no more elements available to be read, then an empty collection is answered.

     Example:
        self assert: ['abcde' asUnicodeString readStream upToEnd = 'abcde'].
        self assert: [('abcde' asUnicodeString readStream next: 2; upToEnd) = 'cde'].
        self assert: ['' asUnicodeString readStream upToEnd = '']

     Answers:
        <Object> instance of view collection class
Last modified date: 04/20/2022