eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SplittingWriteStream':

Home

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

Class: SplittingWriteStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--SplittingWriteStream

Package:
stx:libbasic2
Category:
Streams-Misc
Version:
rev: 1.12 date: 2019/04/01 15:17:55
user: cg
file: SplittingWriteStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger (cg@exept)

Description:


A stream duplicator - everything written onto a splittingWriteStream
is written to two real streams.
Useful, if you have to send something to two files/destinations
simultaneously, and do not want to (or cannot) buffer it.

Especially useful, to generate a checksum, 
while sending something to a file 
(if one of the output streams is a checksummer).

Also, to duplicate some output to a Transcript.
The second stream can be closed and nilled, if no longer needed.



[instance variables:]
    outStream1      <Stream>       actual output streams
    outStream2      <Stream>

[class variables:]


Related information:

    WriteStream

Class protocol:

instance creation
o  on: stream1 and: stream2


Instance protocol:

accessing
o  outStream1
return the value of the instance variable 'outStream1' (automatically generated)

o  outStream1: aStream
set the value of the instance variable 'outStream1' (automatically generated)

o  outStream2
return the value of the instance variable 'outStream2' (automatically generated)

o  outStream2: aStreamOrNil
set the value of the instance variable 'outStream2' (automatically generated)

private access
o  setOutStream1: stream1 outStream2: stream2

redirect messages
o  doesNotUnderstand: aMessage
if my superclass implements the message, it can be forwarded to both streams.

writing
o  clear

o  close
(comment from inherited method)
close the stream - nothing done here.
Added for compatibility with external streams.

o  contents

o  cr
(comment from inherited method)
append a carriage-return to the stream.
This is only allowed, if the receiver supports writing.

o  endEntry
(comment from inherited method)
ignored here - for compatibility with Transcript

o  flush
(comment from inherited method)
write out all unbuffered data - ignored here, but added
to make internalStreams protocol compatible with externalStreams

o  nextPut: something
(comment from inherited method)
put the argument, anObject onto the receiver
- we do not know here how to do it, it must be redefined in subclass

o  nextPutAll: something
(comment from inherited method)
put all elements of the argument, aCollection onto the receiver.
This is only allowed, if the receiver supports writing.

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: aString
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8

o  show: something
(comment from inherited method)
append a printed representation of the argument to the stream.
This makes streams somewhat compatible to TextCollectors and
allows you to say:
Smalltalk at:#Transcript put:Stdout
or to use #show:/#showCR: with internal or external streams.


Examples:


writes to two files simultaneously:
  |s1 s2 splitter|

  s1 := '/tmp/foo1' asFilename writeStream.
  s2 := '/tmp/foo2' asFilename writeStream.
  splitter := SplittingWriteStream on:s1 and:s2.
  splitter nextPutAll:'hello world'.
  splitter close.
generates a hash on the fly:
  |s1 s2 splitter hash|

  s1 := '/tmp/foo1' asFilename writeStream.
  s2 := SHA1Stream new.
  splitter := SplittingWriteStream on:s1 and:s2.
  splitter nextPutAll:'hello world'.
  splitter close.
  hash := s2 hashValue. 
  self assert:(hash = (SHA1Stream hashValueOf:'hello world'))


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Mon, 01 Jun 2020 23:17:12 GMT