eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CharacterWriteStream':

Home

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

Class: CharacterWriteStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--PositionableStream
            |
            +--WriteStream
               |
               +--CharacterWriteStream
                  |
                  +--TextStream

Package:
stx:libbasic
Category:
Streams
Version:
rev: 1.34 date: 2021/11/27 13:54:26
user: cg
file: CharacterWriteStream.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


This is a WriteStream, which automagically changes the underlying collection,
if a character does not fit into the current collection 
(i.e. String -> Unicode16String -> Unicode32String )

This means, that any character can be written to instances of me,
not just single-byte chars, as would be the case for a basic String-stream.
Strings readefine the writeStreamClass query, to return me,
so '' writeStream will automatically return the correct type of stream.


[instance variables:]

[class variables:]

copyright

COPYRIGHT (c) 2004 by eXept Software AG 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.

Class protocol:

instance creation
o  new
I know, that I operate on strings

o  new: count
I know, that I operate on strings


Instance protocol:

accessing
o  reset
reset the stream, to write again over the existing (or already written) contents.
See the comment in WriteStream>>contents

private
o  characterSizeChangedTo: newCharacterSize size: additionalSize
change aCollection to fit the size of newCharacterSize

private-accessing
o  on: aCollection
return a stream for writing into aCollection

o  on: aCollection from: start to: stop
return a stream for writing into part of aCollection.
This will position the stream to start writing at start-index,
and setup a writeLimit at stop-index.
Contents after stop-index will not be overwritten.

o  with: aCollection
return a stream for writing into aCollection.
This will position the stream to the end, and append written elements
after the initial contents.
I.e. the effect is similar to creating an empty stream first and then write
aCollection.

Usage example(s):

     |s|
     s := CharacterWriteStream with:'hello'.
     s nextPutAll:'1234567890'.
     s contents

writing
o  next: count put: aCharacter
append anObject count times to the receiver.
Redefined to avoid count grows of the underlying collection -
instead a single grow on the final size is performed.

o  nextPut: aCharacter
append the argument, aCharacter to the stream.
Answer aCharacter.
Specially tuned for appending to String, Unicode16String and Unicode32String streams.

o  nextPutAll: aCollection
append aCollection to the receiver.
Answer the receiver.
Redefined to convert to a string of the needed character size.

o  nextPutAll: aCollection startingAt: start to: stop
append the elements from first index to last index
of the argument, aCollection onto the receiver (i.e. both outstreams)

o  nextPutAllUnicode: aCollection
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8

o  nextPutUnicode: aCharacter
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8


Examples:


explicit:
  |stream|

  stream := CharacterWriteStream on:(String new:32).
  stream nextPutAll:'abc'.
  stream nextPut:(Character value:16r2c00).
  stream contents inspect
no need to know:
  |stream|

  stream := String writeStream.
  stream nextPutAll:'abc'.
  stream nextPut:(Character value:16r2c00).
  stream contents inspect
no need to know:
  (String streamContents:[:s |
      s nextPutAll:'abc'.
      s nextPut:(Character value:16r2c00).
  ]) inspect


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:36:55 GMT