4275
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
3 |
All Rights Reserved
|
3532
|
4 |
|
4275
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
912
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
3470
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
833
|
16 |
Stream subclass:#SplittingWriteStream
|
|
17 |
instanceVariableNames:'outStream1 outStream2'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Streams-Misc'
|
|
21 |
!
|
|
22 |
|
|
23 |
!SplittingWriteStream class methodsFor:'documentation'!
|
|
24 |
|
4275
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
833
|
40 |
documentation
|
|
41 |
"
|
|
42 |
A stream duplicator - everything written onto a splittingWriteStream
|
|
43 |
is written to two real streams.
|
|
44 |
Useful, if you have to send something to two files/destinations
|
|
45 |
simultaneously, and do not want to (or cannot) buffer it.
|
|
46 |
Especially useful, to generate a checksum,
|
|
47 |
while sending something to a file
|
|
48 |
(if one of the output streams is a checksummer).
|
|
49 |
|
|
50 |
[author:]
|
|
51 |
Claus Gittinger (cg@exept)
|
|
52 |
|
|
53 |
[see also:]
|
|
54 |
WriteStream
|
|
55 |
|
|
56 |
[instance variables:]
|
|
57 |
outStream1 <Stream> actual output streams
|
|
58 |
outStream2 <Stream>
|
|
59 |
|
|
60 |
[class variables:]
|
|
61 |
"
|
|
62 |
!
|
|
63 |
|
|
64 |
examples
|
|
65 |
"
|
|
66 |
examples to be added.
|
|
67 |
[exBegin]
|
|
68 |
|s1 s2 splitter|
|
|
69 |
|
|
70 |
s1 := '/tmp/foo1' asFilename writeStream.
|
|
71 |
s2 := '/tmp/foo2' asFilename writeStream.
|
|
72 |
splitter := SplittingWriteStream on:s1 and:s2.
|
|
73 |
splitter nextPutAll:'hello world'.
|
|
74 |
splitter close.
|
|
75 |
[exEnd]
|
|
76 |
"
|
|
77 |
! !
|
|
78 |
|
|
79 |
!SplittingWriteStream class methodsFor:'instance creation'!
|
|
80 |
|
|
81 |
on:stream1 and:stream2
|
|
82 |
^ self basicNew setOutStream1:stream1 outStream2:stream2
|
|
83 |
! !
|
|
84 |
|
912
|
85 |
!SplittingWriteStream methodsFor:'accessing'!
|
|
86 |
|
|
87 |
outStream1
|
|
88 |
"return the value of the instance variable 'outStream1' (automatically generated)"
|
|
89 |
|
2993
|
90 |
^ outStream1
|
|
91 |
!
|
912
|
92 |
|
|
93 |
outStream1:something
|
|
94 |
"set the value of the instance variable 'outStream1' (automatically generated)"
|
|
95 |
|
2993
|
96 |
outStream1 := something.
|
|
97 |
!
|
912
|
98 |
|
|
99 |
outStream2
|
|
100 |
"return the value of the instance variable 'outStream2' (automatically generated)"
|
|
101 |
|
2993
|
102 |
^ outStream2
|
|
103 |
!
|
912
|
104 |
|
|
105 |
outStream2:something
|
|
106 |
"set the value of the instance variable 'outStream2' (automatically generated)"
|
|
107 |
|
2993
|
108 |
outStream2 := something.
|
|
109 |
! !
|
912
|
110 |
|
833
|
111 |
!SplittingWriteStream methodsFor:'private access'!
|
|
112 |
|
|
113 |
setOutStream1:stream1 outStream2:stream2
|
|
114 |
outStream1 := stream1.
|
|
115 |
outStream2 := stream2.
|
|
116 |
|
|
117 |
! !
|
|
118 |
|
3532
|
119 |
!SplittingWriteStream methodsFor:'redirect messages'!
|
|
120 |
|
|
121 |
doesNotUnderstand:aMessage
|
|
122 |
"if my superclass implements the message, it can be forwarded to both streams."
|
|
123 |
|
|
124 |
(outStream2 class canUnderstand:aMessage selector) ifTrue:[
|
|
125 |
aMessage sendTo:outStream1.
|
|
126 |
^ aMessage sendTo:outStream2.
|
|
127 |
].
|
|
128 |
^ super doesNotUnderstand:aMessage.
|
|
129 |
|
|
130 |
"
|
|
131 |
|sp s1 s2|
|
|
132 |
|
|
133 |
s1 := TextStream on:''.
|
|
134 |
s2 := TextStream on:''.
|
|
135 |
|
|
136 |
sp := SplittingWriteStream on:s1 and:s2.
|
|
137 |
|
|
138 |
sp nextPutAllText:('ABC' allBold); closeRun.
|
|
139 |
s2 contents inspect.
|
|
140 |
"
|
|
141 |
! !
|
|
142 |
|
833
|
143 |
!SplittingWriteStream methodsFor:'writing'!
|
|
144 |
|
2993
|
145 |
clear
|
|
146 |
outStream1 isStream ifFalse:[ outStream1 clear ].
|
|
147 |
outStream2 isStream ifFalse:[ outStream2 clear ].
|
|
148 |
!
|
|
149 |
|
833
|
150 |
close
|
|
151 |
outStream1 close.
|
|
152 |
outStream2 close.
|
|
153 |
|
|
154 |
!
|
|
155 |
|
2993
|
156 |
contents
|
|
157 |
^ outStream1 contents
|
|
158 |
!
|
|
159 |
|
833
|
160 |
endEntry
|
|
161 |
outStream1 endEntry.
|
|
162 |
outStream2 endEntry.
|
|
163 |
|
|
164 |
!
|
|
165 |
|
|
166 |
flush
|
|
167 |
outStream1 flush.
|
|
168 |
outStream2 flush.
|
|
169 |
|
|
170 |
!
|
|
171 |
|
|
172 |
nextPut:something
|
|
173 |
outStream1 nextPut:something.
|
|
174 |
outStream2 nextPut:something.
|
|
175 |
|
|
176 |
!
|
|
177 |
|
|
178 |
nextPutAll:something
|
|
179 |
outStream1 nextPutAll:something.
|
|
180 |
outStream2 nextPutAll:something.
|
|
181 |
|
3470
|
182 |
!
|
|
183 |
|
|
184 |
nextPutAll:aCollection startingAt:start to:stop
|
|
185 |
outStream1 nextPutAll:aCollection startingAt:start to:stop.
|
|
186 |
outStream2 nextPutAll:aCollection startingAt:start to:stop.
|
833
|
187 |
! !
|
|
188 |
|
|
189 |
!SplittingWriteStream class methodsFor:'documentation'!
|
|
190 |
|
|
191 |
version
|
4275
|
192 |
^ '$Header$'
|
833
|
193 |
! !
|
2993
|
194 |
|