|
Class: SplittingWriteStream
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)
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:]
WriteStream
instance creation
-
on: stream1 and: stream2
-
accessing
-
outStream1
-
return the value of the instance variable 'outStream1' (automatically generated)
-
outStream1: something
-
set the value of the instance variable 'outStream1' (automatically generated)
-
outStream2
-
return the value of the instance variable 'outStream2' (automatically generated)
-
outStream2: something
-
set the value of the instance variable 'outStream2' (automatically generated)
private access
-
setOutStream1: stream1 outStream2: stream2
-
redirect messages
-
doesNotUnderstand: aMessage
-
if my superclass implements the message, it can be forwarded to both streams.
writing
-
clear
-
-
close
-
-
contents
-
-
endEntry
-
-
flush
-
-
nextPut: something
-
-
nextPutAll: something
-
-
nextPutAll: aCollection startingAt: start to: stop
-
-
nextPutAllUnicode: aString
-
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8
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'))
|
|