|
Class: SplittingWriteStream
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)
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:]
WriteStream
instance creation
-
on: stream1 and: stream2
-
accessing
-
outStream1
-
return the value of the instance variable 'outStream1' (automatically generated)
-
outStream1: aStream
-
set the value of the instance variable 'outStream1' (automatically generated)
-
outStream2
-
return the value of the instance variable 'outStream2' (automatically generated)
-
outStream2: aStreamOrNil
-
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
-
(comment from inherited method)
close the stream - nothing done here.
Added for compatibility with external streams.
-
contents
-
-
cr
-
(comment from inherited method)
append a carriage-return to the stream.
This is only allowed, if the receiver supports writing.
-
endEntry
-
(comment from inherited method)
ignored here - for compatibility with Transcript
-
flush
-
(comment from inherited method)
write out all unbuffered data - ignored here, but added
to make internalStreams protocol compatible with externalStreams
-
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
-
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.
-
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)
-
nextPutAllUnicode: aString
-
(comment from inherited method)
normal streams can not handle multi-byte characters, so convert them to utf8
-
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.
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'))
|
|