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.8 date: 2017/09/21 10:44:18
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).



[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: something
set the value of the instance variable 'outStream1' (automatically generated)

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

o  outStream2: something
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

o  contents

o  endEntry

o  flush

o  nextPut: something

o  nextPutAll: something

o  nextPutAll: aCollection startingAt: start to: stop

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


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.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 19 May 2019 06:47:48 GMT