author | Stefan Vogel <sv@exept.de> |
Thu, 16 May 2019 19:27:30 +0200 | |
changeset 24125 | 060e01919399 |
parent 24035 | ed67960ad29d |
child 24148 | 0a40f4bca78d |
permissions | -rw-r--r-- |
24035 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
216 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
15 |
|
17330 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Object subclass:#Stream |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
19 |
instanceVariableNames:'signalAtEnd' |
23935 | 20 |
classVariableNames:'ChunkSeparator EndOfStreamSignal LineTooLongErrorSignal |
21 |
PositionErrorSignal ReadErrorSignal StreamErrorSignal |
|
22 |
WriteErrorSignal' |
|
743 | 23 |
poolDictionaries:'' |
24 |
category:'Streams' |
|
1 | 25 |
! |
26 |
||
1949 | 27 |
!Stream class methodsFor:'documentation'! |
88 | 28 |
|
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
216 | 32 |
All Rights Reserved |
88 | 33 |
|
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
An abstract class defining common behavior for all stream-like objects. |
|
46 |
See concrete subclasses for more detail. |
|
345 | 47 |
|
1404 | 48 |
The protocol as implemented here is often only provided as a fallBack |
49 |
for very uncommon cases. Much of it is redefined for performance. |
|
50 |
(In streams which know more about their internal representation ...) |
|
51 |
||
52 |
||
345 | 53 |
Subclasses should (at least) implement: |
17555 | 54 |
#next (if readable) |
55 |
#nextPut: (if writable) |
|
56 |
#contents |
|
57 |
#atEnd |
|
58 |
#isReadable |
|
59 |
#isWritable |
|
1295 | 60 |
|
1404 | 61 |
Peekable & Positionable streams should (at least) implement: |
17555 | 62 |
#peek |
63 |
#position |
|
64 |
#position: |
|
1404 | 65 |
|
66 |
||
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
67 |
[instance variables:] |
17555 | 68 |
signalAtEnd <nil | Boolean> controls behavior when a read |
69 |
is attempted past the end-of-stream |
|
70 |
if true, the endOfStreamSignal is raised. |
|
71 |
if false, nil is returned. |
|
72 |
if nil (the default), the signal |
|
73 |
is raised, but if there is no handler, |
|
74 |
nil is returned. |
|
20198 | 75 |
|
8309 | 76 |
[Class variables / Exceptions:] |
17555 | 77 |
StreamError <Exception> parent of all stream errors |
78 |
||
79 |
PositionError <Exception> position attemted on a stream |
|
80 |
which does not support positioning, |
|
81 |
or if the position is invalid. |
|
82 |
||
83 |
ReadError <Exception> raised on read errors |
|
84 |
||
85 |
WriteError <Exception> raised on write errors |
|
86 |
||
87 |
EndOfStreamSignal <Signal> raised at end of stream if signalAtEnd |
|
88 |
is enabled. |
|
89 |
||
90 |
[caveat:] |
|
91 |
The Stream hierarchy has a few little quirks in it, which are a consequence of some early historic |
|
92 |
decisions. The biggest problem is the distinction between readable and writeable streams based on inheritance, |
|
17561 | 93 |
instead of by either using state (i.e. a flag) or delegation. |
17555 | 94 |
The problem is that there are streams which can be both, and maybe even dynamically change their opinion, |
20198 | 95 |
on whether being readable/writable. |
17555 | 96 |
(For example, a buffer may be write-only while filled, but become readonly, when given to a consumer.) |
97 |
||
98 |
The above decision to base this on inheritance lead to the ugly ReadStream - WriteStream - ReadWriteStream |
|
17561 | 99 |
hierarchy, with some subclasses undoing the blocking of their superclass. |
100 |
||
20198 | 101 |
Classes named 'ReadStream', 'WriteStream', 'ReadWriteStream', 'PeekableStream' and 'PositionableStream' should |
17561 | 102 |
all be eliminated in favour of a few flags in the 'Stream' superclass. |
17556 | 103 |
|
17555 | 104 |
It is really time for a new stream hierarchy (XStreams, for example). |
105 |
(On the other hand: there is so much code around, which depends on the current situation, that such a change |
|
106 |
must really be thought through - most got used to these issues and live with it more or less happily) |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
107 |
|
1295 | 108 |
[author:] |
17555 | 109 |
Claus Gittinger |
88 | 110 |
" |
111 |
! ! |
|
1 | 112 |
|
1949 | 113 |
!Stream class methodsFor:'initialization'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
114 |
|
5991 | 115 |
initSignals |
116 |
StreamErrorSignal := StreamError. |
|
117 |
StreamErrorSignal notifierString:'Stream error'. |
|
118 |
||
8071 | 119 |
PositionErrorSignal := PositionError. |
6314 | 120 |
PositionErrorSignal notifierString:'stream has no concept of a position'. |
5991 | 121 |
|
8071 | 122 |
ReadErrorSignal := ReadError. |
5991 | 123 |
ReadErrorSignal notifierString:'read error'. |
124 |
||
8071 | 125 |
WriteErrorSignal := WriteError. |
5991 | 126 |
WriteErrorSignal notifierString:'write error'. |
127 |
||
128 |
LineTooLongErrorSignal := QuerySignal new. |
|
8515 | 129 |
LineTooLongErrorSignal parent:StreamError. |
5991 | 130 |
LineTooLongErrorSignal nameClass:self message:#lineTooLongErrorSignal. |
131 |
LineTooLongErrorSignal notifierString:'line too long'. |
|
132 |
||
8515 | 133 |
EndOfStreamSignal := EndOfStreamNotification. |
5991 | 134 |
EndOfStreamSignal notifierString:'end of stream'. |
135 |
||
136 |
"Created: / 7.9.2001 / 14:15:13 / cg" |
|
137 |
"Modified: / 7.9.2001 / 14:15:27 / cg" |
|
138 |
! |
|
139 |
||
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
140 |
initialize |
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
141 |
ChunkSeparator := $!!. |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
142 |
|
8309 | 143 |
LineTooLongErrorSignal isNil ifTrue:[ |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
144 |
self initSignals |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
145 |
] |
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
146 |
|
3911 | 147 |
"Modified: / 1.11.1998 / 15:57:37 / stefan" |
5991 | 148 |
"Modified: / 7.9.2001 / 14:15:51 / cg" |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
149 |
! ! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
150 |
|
1949 | 151 |
!Stream class methodsFor:'instance creation'! |
611 | 152 |
|
153 |
new |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
154 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
155 |
|
611 | 156 |
"report an error - Streams are created using on:-messages" |
157 |
||
4530
793b116fef3e
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4467
diff
changeset
|
158 |
self error:'Streams cannot be created with new' |
611 | 159 |
! ! |
160 |
||
1949 | 161 |
!Stream class methodsFor:'Signal constants'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
162 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
163 |
endOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
164 |
"return the signal raised if read past end of stream is attemted" |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
165 |
|
8515 | 166 |
^ EndOfStreamNotification |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
167 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
168 |
|
6348 | 169 |
incompleteNextCountSignal |
170 |
"return the signal raised if not all requested elements are returned" |
|
171 |
||
172 |
^ IncompleteNextCountError |
|
173 |
! |
|
174 |
||
3877
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
175 |
lineTooLongErrorSignal |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
176 |
"return the signal raised if a line is read which is too long (>32k)" |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
177 |
|
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
178 |
^ LineTooLongErrorSignal |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
179 |
|
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
180 |
"Created: / 15.10.1998 / 12:11:14 / cg" |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
181 |
! |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
182 |
|
611 | 183 |
positionErrorSignal |
184 |
"return the signal raised if positioning is requested for |
|
185 |
a stream which does not support that kind of operation" |
|
186 |
||
8309 | 187 |
^ PositionError |
611 | 188 |
! |
189 |
||
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
190 |
readErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
191 |
"return the signal raised on read errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
192 |
|
8309 | 193 |
^ ReadError |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
194 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
195 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
196 |
streamErrorSignal |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
197 |
"return the parent of all stream errors; |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
198 |
handling this one also handles all other errors. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
199 |
Also, this one may be raised for errors not related to read/write |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
200 |
operations, such as failed ioctls in externalStream etc." |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
201 |
|
8309 | 202 |
^ StreamError |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
203 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
204 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
205 |
writeErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
206 |
"return the signal raised on write errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
207 |
|
8309 | 208 |
^ WriteError |
1 | 209 |
! ! |
210 |
||
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
211 |
!Stream class methodsFor:'constants'! |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
212 |
|
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
213 |
chunkSeparator |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
214 |
"return the chunk-separation character" |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
215 |
|
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
216 |
^ ChunkSeparator |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
217 |
! ! |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
218 |
|
21035 | 219 |
!Stream class methodsFor:'testing'! |
220 |
||
221 |
isAbstract |
|
222 |
^ self == Stream |
|
223 |
! ! |
|
224 |
||
24035 | 225 |
|
17549 | 226 |
!Stream methodsFor:'Compatibility-Dolphin'! |
227 |
||
228 |
display:someObject |
|
229 |
"dolphin compatibility" |
|
230 |
||
231 |
"/ someObject printOn:self. |
|
232 |
self nextPutAll: someObject asString. |
|
233 |
! ! |
|
234 |
||
24035 | 235 |
|
20305 | 236 |
!Stream methodsFor:'Compatibility-VW'! |
237 |
||
23935 | 238 |
commit |
239 |
"alias for flush -- ST80 compatibility" |
|
240 |
||
241 |
^ self flush |
|
242 |
||
243 |
"Modified: 7.5.1996 / 23:55:39 / stefan" |
|
244 |
! |
|
245 |
||
20305 | 246 |
nl |
247 |
"append a newline to the stream. |
|
248 |
This is only allowed, if the receiver supports writing." |
|
249 |
||
250 |
self nextPut:(Character nl) |
|
251 |
! ! |
|
252 |
||
23729 | 253 |
!Stream methodsFor:'JS syntactic sugar'! |
254 |
||
255 |
show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 |
|
256 |
"for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
257 |
||
258 |
self show:(aString bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7). |
|
259 |
||
260 |
"Created: / 13-02-2019 / 18:08:16 / Claus Gittinger" |
|
261 |
! |
|
262 |
||
263 |
show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 _:arg8 |
|
264 |
"for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
265 |
||
266 |
self show:(aString bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 with:arg8). |
|
267 |
||
268 |
"Created: / 13-02-2019 / 18:09:28 / Claus Gittinger" |
|
269 |
! |
|
270 |
||
271 |
showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 |
|
272 |
<javascript: 'log/8'> |
|
273 |
||
274 |
"for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
275 |
||
276 |
self showCR:(aString bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7). |
|
277 |
||
278 |
"Created: / 13-02-2019 / 18:08:43 / Claus Gittinger" |
|
279 |
! |
|
280 |
||
281 |
showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 _:arg8 |
|
282 |
<javascript: 'log/9'> |
|
283 |
||
284 |
"for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
285 |
||
286 |
self showCR:(aString bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 with:arg8). |
|
287 |
||
288 |
"Created: / 13-02-2019 / 18:09:17 / Claus Gittinger" |
|
289 |
! ! |
|
22252 | 290 |
|
1 | 291 |
!Stream methodsFor:'accessing'! |
292 |
||
293 |
contents |
|
11693 | 294 |
"return the entire contents of the stream. |
295 |
For a readStream, that is the rest (i.e. upToEnd), |
|
296 |
for a writeStream, that is the collected data. As we do not know here, |
|
297 |
what we are, this is the responsibility of a subclass..." |
|
298 |
||
299 |
^ self subclassResponsibility |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
300 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
301 |
|
23989 | 302 |
encoder |
303 |
"for compatibility with encoded stream" |
|
304 |
||
305 |
^ CharacterEncoder nullEncoderInstance |
|
306 |
! |
|
307 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
308 |
signalAtEnd |
20242 | 309 |
"return the signalAtEnd flag setting. |
310 |
If true, reading past the end will always raise an EndOfStream exception. |
|
3105 | 311 |
If false, no exception is raised and nil is returned from all reading messages. |
312 |
If nil (default), the exception is raised if there is a handler; otherwise, nil is returned. |
|
313 |
The default is nil (for ST80 compatibility) i.e. to only raise a signal if there is a handler." |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
314 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
315 |
^ signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
316 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
317 |
"Created: 5.2.1996 / 18:24:53 / stefan" |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
318 |
"Modified: 15.5.1996 / 17:35:55 / cg" |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
319 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
320 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
321 |
signalAtEnd:aBoolean |
20775 | 322 |
"set the signalAtEnd flag setting. |
323 |
If true, reading past the end will raise an EndOfStream exception. |
|
324 |
If false, no exception is raised and nil is returned from all reading messages. |
|
325 |
If nil (default), the exception is raised if there is a handler; otherwise, nil is returned. |
|
326 |
The default (nil) is both st80 backward compatible (i.e. returning nil) |
|
327 |
AND allows for modern code to provide a handler." |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
328 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
329 |
signalAtEnd := aBoolean. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
330 |
|
3591 | 331 |
"default behavior: return nil if unhandled ... |
332 |
|s| |
|
333 |
||
334 |
s := '12' readStream. |
|
335 |
Transcript showCR:s next. |
|
336 |
Transcript showCR:s next. |
|
337 |
Transcript showCR:s next. |
|
338 |
Transcript showCR:s next. |
|
339 |
" |
|
340 |
||
341 |
"... raise error if handled. |
|
342 |
|s| |
|
343 |
||
344 |
s := '12' readStream. |
|
345 |
Stream endOfStreamSignal handle:[:ex | |
|
16791 | 346 |
Transcript showCR:'end reached'. |
347 |
ex return |
|
3591 | 348 |
] do:[ |
16791 | 349 |
Transcript showCR:s next. |
350 |
Transcript showCR:s next. |
|
351 |
Transcript showCR:s next. |
|
352 |
Transcript showCR:s next. |
|
3591 | 353 |
] |
354 |
" |
|
355 |
||
356 |
"force raise (useful for debugging): |
|
357 |
|s| |
|
358 |
||
359 |
s := '12' readStream. |
|
360 |
s signalAtEnd:true. |
|
361 |
Transcript showCR:s next. |
|
362 |
Transcript showCR:s next. |
|
363 |
Transcript showCR:s next. |
|
364 |
Transcript showCR:s next. |
|
365 |
" |
|
366 |
||
367 |
||
368 |
"force no-raise (useful for compatibility with other systems): |
|
369 |
|s| |
|
370 |
||
371 |
s := '12' readStream. |
|
372 |
s signalAtEnd:false. |
|
373 |
Stream endOfStreamSignal handle:[:ex | |
|
16791 | 374 |
Transcript showCR:'end reached'. |
375 |
ex return |
|
3591 | 376 |
] do:[ |
16791 | 377 |
Transcript showCR:s next. |
378 |
Transcript showCR:s next. |
|
379 |
Transcript showCR:s next. |
|
380 |
Transcript showCR:s next. |
|
3591 | 381 |
] |
382 |
" |
|
383 |
||
384 |
"Modified: / 16.6.1998 / 16:04:41 / cg" |
|
1 | 385 |
! ! |
386 |
||
8630 | 387 |
!Stream methodsFor:'converting'! |
388 |
||
16086 | 389 |
asLineNumberReadStream |
18393 | 390 |
"returns a new stream, which keeps track of the line number. |
20242 | 391 |
It can be asked for the current linenumber, |
18393 | 392 |
which is useful eg. for error message generation" |
393 |
||
16086 | 394 |
^ LineNumberReadStream on:self |
395 |
! |
|
396 |
||
8630 | 397 |
asStream |
398 |
^ self |
|
399 |
! ! |
|
400 |
||
23912 | 401 |
!Stream methodsFor:'defaults'! |
402 |
||
403 |
bufferSizeForBulkCopy |
|
404 |
"return the size of buffer used when copying big files/bulk data |
|
405 |
from one stream to another." |
|
406 |
||
407 |
^ 128 * 1024 |
|
408 |
||
409 |
"Created: / 13-03-2019 / 16:50:04 / Stefan Vogel" |
|
410 |
"Modified (comment): / 13-03-2019 / 23:21:13 / Stefan Vogel" |
|
411 |
! ! |
|
412 |
||
1401 | 413 |
!Stream methodsFor:'emphasis'! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
414 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
415 |
bold |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
416 |
"set emphasis to #bold. |
21844 | 417 |
Normal streams will ignore this, |
418 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
419 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
420 |
self emphasis:#bold. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
421 |
|
21844 | 422 |
"Created: / 14-05-1996 / 17:37:37 / cg" |
423 |
"Modified: / 20-06-2017 / 08:41:50 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
424 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
425 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
426 |
boldItalic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
427 |
"set emphasis to #boldItalic |
21844 | 428 |
Normal streams will ignore this, |
429 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
430 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
431 |
self emphasis:#(bold italic). |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
432 |
|
21844 | 433 |
"Created: / 14-05-1996 / 17:37:47 / cg" |
434 |
"Modified: / 03-06-1996 / 17:15:22 / cg" |
|
435 |
"Modified (comment): / 20-06-2017 / 08:37:36 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
436 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
437 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
438 |
emphasis |
21844 | 439 |
"ignored here |
440 |
- allows Streams to be used interchangable with text streams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
441 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
442 |
^ nil |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
443 |
|
21844 | 444 |
"Created: / 14-05-1996 / 17:39:45 / cg" |
445 |
"Modified (comment): / 20-06-2017 / 08:37:15 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
446 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
447 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
448 |
emphasis:anEmphasis |
21844 | 449 |
"ignored here |
450 |
- allows Streams to be used interchangable with text streams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
451 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
452 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
453 |
|
21844 | 454 |
"Created: / 14-05-1996 / 17:38:07 / cg" |
455 |
"Modified (comment): / 20-06-2017 / 08:37:54 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
456 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
457 |
|
20242 | 458 |
italic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
459 |
"set emphasis to #italic. |
21844 | 460 |
Normal streams will ignore this, |
461 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
462 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
463 |
self emphasis:#italic. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
464 |
|
21844 | 465 |
"Created: / 14-05-1996 / 17:37:55 / cg" |
466 |
"Modified: / 20-06-2017 / 08:42:01 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
467 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
468 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
469 |
normal |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
470 |
"set emphasis to #normal. |
21844 | 471 |
Normal streams will ignore this, |
472 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
473 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
474 |
self emphasis:nil |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
475 |
|
21844 | 476 |
"Created: / 14-05-1996 / 17:37:59 / cg" |
477 |
"Modified: / 03-06-1996 / 17:15:35 / cg" |
|
478 |
"Modified (comment): / 20-06-2017 / 08:38:04 / cg" |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
479 |
! |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
480 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
481 |
strikeout |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
482 |
"set emphasis to #strikeout. |
21844 | 483 |
Normal streams will ignore this, |
484 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
485 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
486 |
self emphasis:#strikeout. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
487 |
|
21844 | 488 |
"Created: / 03-06-1996 / 17:15:45 / cg" |
489 |
"Modified (comment): / 20-06-2017 / 08:38:07 / cg" |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
490 |
! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
491 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
492 |
underline |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
493 |
"set emphasis to #underline. |
21844 | 494 |
Normal streams will ignore this, |
495 |
which allows arbitrary Streams to be used interchangeable with printStreams" |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
496 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
497 |
self emphasis:#underline. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
498 |
|
21844 | 499 |
"Created: / 03-06-1996 / 17:00:03 / cg" |
500 |
"Modified (comment): / 20-06-2017 / 08:38:11 / cg" |
|
14347 | 501 |
! |
502 |
||
503 |
withEmphasis:anEmphasis do:aBlock |
|
504 |
"evaluate aBlock while my emphasis has been changed to anEmphasis. |
|
505 |
Emphasis is ignored here, but implemented in some subclasses (PrinterStream, TextCollector etc.)." |
|
506 |
||
507 |
|oldEmphasis| |
|
508 |
||
509 |
oldEmphasis := self emphasis. |
|
510 |
[ |
|
511 |
self emphasis:anEmphasis. |
|
512 |
aBlock value |
|
513 |
] ensure:[ |
|
514 |
self emphasis:oldEmphasis. |
|
515 |
]. |
|
516 |
||
517 |
"Created: / 06-09-2012 / 16:12:55 / cg" |
|
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
518 |
! ! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
519 |
|
1401 | 520 |
!Stream methodsFor:'enumerating'! |
521 |
||
522 |
do:aBlock |
|
523 |
"evaluate the argument, aBlock for all remaining elements, |
|
524 |
up to the end of the stream" |
|
525 |
||
526 |
[self atEnd] whileFalse:[ |
|
527 |
aBlock value:(self next) |
|
528 |
] |
|
529 |
||
530 |
" |
|
531 |
|s| |
|
532 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
533 |
s next. |
|
534 |
s next. |
|
1422 | 535 |
s do:[:element | Transcript showCR:element] |
1401 | 536 |
" |
6384 | 537 |
! |
538 |
||
539 |
linesDo:aBlock |
|
540 |
"evaluate the argument, aBlock for all lines, |
|
541 |
up to the end of the stream" |
|
542 |
||
543 |
[self atEnd] whileFalse:[ |
|
544 |
aBlock value:(self nextLine) |
|
545 |
] |
|
546 |
||
547 |
" |
|
548 |
|s| |
|
549 |
s := '/etc/hosts' asFilename readStream. |
|
550 |
s linesDo:[:line | Transcript showCR:line]. |
|
551 |
s close |
|
552 |
" |
|
553 |
||
554 |
" |
|
20242 | 555 |
Filename readingFile:'/etc/hosts' |
6384 | 556 |
do:[:s | |
557 |
s linesDo:[:line | Transcript showCR:line]. |
|
558 |
]. |
|
559 |
" |
|
1401 | 560 |
! ! |
561 |
||
562 |
!Stream methodsFor:'error handling'! |
|
563 |
||
7104
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
564 |
checkNilFileStream |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
565 |
"Do nothing if this is a valid FileStream |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
566 |
(i.e. the previous open operation was successful). |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
567 |
Also implemented in UndefinedObject, to raise an Error there. |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
568 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
569 |
This is an aid for converting from the old error reporting (returning nil) |
8309 | 570 |
to the new error reporting (with real Exceptions). |
7104
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
571 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
572 |
It will vanish as soon as the conversion has been done" |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
573 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
574 |
^ self |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
575 |
! |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
576 |
|
20065 | 577 |
errorNotOpen |
578 |
"{ Pragma: +optSpace }" |
|
579 |
||
22191 | 580 |
"report an error, that the stream has not been opened or has been closed" |
20065 | 581 |
|
582 |
^ StreamNotOpenError raiseRequestWith:self "/ in:thisContext sender |
|
583 |
||
584 |
"Modified: / 8.5.1999 / 20:12:33 / cg" |
|
585 |
! |
|
586 |
||
1401 | 587 |
pastEnd |
588 |
"someone tried to read after the end of the stream. |
|
19648 | 589 |
If signalAtEnd == true, raise a signal. If it's false, return nil. |
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
590 |
Otherwise raise the signal, but only if handled; otherwise return nil." |
1401 | 591 |
|
8622 | 592 |
<resource: #obsolete> |
593 |
||
9061 | 594 |
self obsoleteMethodWarning:'use #pastEndRead'. |
10181 | 595 |
^ self pastEndRead |
596 |
||
597 |
"Modified: / 18-11-2006 / 15:36:44 / cg" |
|
8614 | 598 |
! |
599 |
||
600 |
pastEndRead |
|
601 |
"someone tried to read after the end of the stream. |
|
20242 | 602 |
If signalAtEnd == true, raise a signal. |
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
603 |
If it is false, return nil. |
20242 | 604 |
Otherwise raise a notification, which is ignored if not handled; |
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
605 |
otherwise return nil." |
8614 | 606 |
|
13380 | 607 |
|shouldSignalAtEnd| |
608 |
||
609 |
shouldSignalAtEnd := self signalAtEnd. |
|
610 |
||
611 |
shouldSignalAtEnd == true ifTrue:[ |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
612 |
"raise - a hard error..." |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
613 |
^ EndOfStreamError raiseRequestFrom:self |
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
614 |
]. |
13380 | 615 |
shouldSignalAtEnd == false ifTrue:[ |
8515 | 616 |
"never raise ..." |
617 |
^ nil |
|
1401 | 618 |
]. |
619 |
||
20775 | 620 |
"EndOfStreamNotification is a notification; |
621 |
i.e. it is ignored, if there is no handler. |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
622 |
In this case, nil is returned" |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
623 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
624 |
^ EndOfStreamNotification raiseRequestFrom:self |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
625 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
626 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
627 |
" ... no handler, no raise |
3591 | 628 |
|s| |
629 |
||
630 |
s := '12' readStream. |
|
631 |
Transcript showCR:s next. |
|
632 |
Transcript showCR:s next. |
|
633 |
Transcript showCR:s next. |
|
634 |
Transcript showCR:s next. |
|
635 |
" |
|
636 |
||
637 |
"... raise error if handled. |
|
638 |
|s| |
|
639 |
||
640 |
s := '12' readStream. |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
641 |
EndOfStreamNotification handle:[:ex | |
8515 | 642 |
Transcript showCR:'end reached'. |
643 |
ex return |
|
3591 | 644 |
] do:[ |
8515 | 645 |
Transcript showCR:s next. |
646 |
Transcript showCR:s next. |
|
647 |
Transcript showCR:s next. |
|
648 |
Transcript showCR:s next. |
|
3591 | 649 |
] |
650 |
" |
|
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
651 |
|
3591 | 652 |
"force raise (useful for debugging): |
653 |
|s| |
|
654 |
||
655 |
s := '12' readStream. |
|
656 |
s signalAtEnd:true. |
|
657 |
Transcript showCR:s next. |
|
658 |
Transcript showCR:s next. |
|
659 |
Transcript showCR:s next. |
|
660 |
Transcript showCR:s next. |
|
661 |
" |
|
662 |
||
663 |
||
664 |
"force no-raise (useful for compatibility with other systems): |
|
665 |
|s| |
|
666 |
||
667 |
s := '12' readStream. |
|
668 |
s signalAtEnd:false. |
|
669 |
Stream endOfStreamSignal handle:[:ex | |
|
8515 | 670 |
Transcript showCR:'end reached'. |
671 |
ex return |
|
3591 | 672 |
] do:[ |
8515 | 673 |
Transcript showCR:s next. |
674 |
Transcript showCR:s next. |
|
675 |
Transcript showCR:s next. |
|
676 |
Transcript showCR:s next. |
|
3591 | 677 |
] |
678 |
" |
|
679 |
||
680 |
"Modified: / 16.6.1998 / 16:04:13 / cg" |
|
1401 | 681 |
! ! |
682 |
||
23902 | 683 |
!Stream methodsFor:'externalStream compatibility'! |
611 | 684 |
|
685 |
binary |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
686 |
"switch to binary mode. In binary mode, reading of text streams |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
687 |
returns byte-valued integers instead of characters; writing expects |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
688 |
byte-valued integers respectively. |
20242 | 689 |
Ignored here, but added to make internalStreams protocol compatible |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
690 |
with externalStreams." |
611 | 691 |
|
23902 | 692 |
^ self. |
693 |
||
694 |
"Modified: / 15-05-1996 / 17:38:36 / cg" |
|
695 |
"Modified: / 13-03-2019 / 19:40:03 / Stefan Vogel" |
|
696 |
! |
|
697 |
||
698 |
binary:beBinaryBool |
|
699 |
"if beBinaryBool is true, switch to binary mode, if false, switch to text mode. |
|
700 |
Answer the prevous mode - true for binary mode, false for text mode. |
|
701 |
In binary mode, reading of text streams |
|
702 |
returns byte-valued integers instead of characters; writing expects |
|
703 |
byte-valued integers respectively. |
|
704 |
Ignored here, but added to make internalStreams protocol compatible |
|
705 |
with externalStreams." |
|
706 |
||
707 |
^ false "/ I am not in binary mode!! |
|
708 |
||
709 |
"Created: / 13-03-2019 / 19:11:06 / Stefan Vogel" |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
710 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
711 |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
712 |
blocking:aBoolean |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
713 |
"set non-blocking mode. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
714 |
Ignored, since internal streams never block" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
715 |
|
7498
9637184b10fe
ExternalStream>>blocking: returns previous blocking status
Stefan Vogel <sv@exept.de>
parents:
7497
diff
changeset
|
716 |
^ false. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
717 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
718 |
|
23902 | 719 |
buffered:aBoolean |
720 |
"ExternalStream compatibility: change buffered mode. |
|
721 |
Ignored, since internal streams are never buffered." |
|
722 |
||
723 |
^ false. |
|
724 |
||
725 |
"Created: / 13-03-2019 / 19:38:15 / Stefan Vogel" |
|
726 |
! |
|
727 |
||
16775 | 728 |
eolMode |
20242 | 729 |
"Dummy here, but added to make internalStreams protocol compatible |
16775 | 730 |
with externalStreams." |
731 |
||
732 |
^ nil "/ transparent |
|
733 |
! |
|
734 |
||
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
735 |
eolMode:aSymbol |
20242 | 736 |
"Ignored here, but added to make internalStreams protocol compatible |
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
737 |
with externalStreams." |
23902 | 738 |
|
739 |
^ self. |
|
740 |
||
741 |
"Modified: / 13-03-2019 / 19:38:52 / Stefan Vogel" |
|
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
742 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
743 |
|
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
744 |
lineEndCRLF |
20242 | 745 |
"Ignored here, but added to make internalStreams protocol compatible |
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
746 |
with externalStreams." |
23902 | 747 |
|
748 |
^ self |
|
749 |
||
750 |
"Modified: / 13-03-2019 / 19:39:00 / Stefan Vogel" |
|
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
751 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
752 |
|
20502 | 753 |
lineEndConvention |
754 |
^ self eolMode |
|
755 |
! |
|
756 |
||
757 |
lineEndConvention:aSymbol |
|
758 |
^ self eolMode:aSymbol |
|
759 |
! |
|
760 |
||
17673 | 761 |
lineEndLF |
20242 | 762 |
"Ignored here, but added to make internalStreams protocol compatible |
17673 | 763 |
with externalStreams." |
23902 | 764 |
|
765 |
^ self. |
|
766 |
||
767 |
"Modified: / 13-03-2019 / 19:39:11 / Stefan Vogel" |
|
17673 | 768 |
! |
769 |
||
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
770 |
lineEndTransparent |
20242 | 771 |
"Ignored here, but added to make internalStreams protocol compatible |
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
772 |
with externalStreams." |
23902 | 773 |
|
774 |
^ self. |
|
775 |
||
776 |
"Modified: / 13-03-2019 / 19:39:21 / Stefan Vogel" |
|
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
777 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
778 |
|
14434 | 779 |
stream |
780 |
"for compatibility with encodedStream" |
|
781 |
||
782 |
^ self |
|
783 |
! |
|
784 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
785 |
text |
20242 | 786 |
"switch to text mode. |
787 |
Ignored here, but added to make internalStreams protocol compatible |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
788 |
with externalStreams." |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
789 |
|
23902 | 790 |
^ self. |
791 |
||
792 |
"Modified: / 15-05-1996 / 17:38:36 / cg" |
|
793 |
"Created: / 13-09-1996 / 18:33:26 / cg" |
|
794 |
"Modified: / 13-03-2019 / 19:39:53 / Stefan Vogel" |
|
611 | 795 |
! ! |
796 |
||
797 |
!Stream methodsFor:'non homogenous reading'! |
|
798 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
799 |
nextAvailableBytes:numBytes into:aCollection startingAt:initialIndex |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
800 |
"for compatibility with ExternalStream" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
801 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
802 |
^ self nextBytes:numBytes into:aCollection startingAt:initialIndex |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
803 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
804 |
|
8988
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
805 |
nextByte |
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
806 |
"return the next byte of the stream |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
807 |
- we do not know here how to do it, it should be redefined in subclass" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
808 |
|
15839 | 809 |
^ self next asInteger |
8988
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
810 |
! |
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
811 |
|
2714 | 812 |
nextBytes:count |
11249 | 813 |
"read the next count bytes and return it as a byteArray. |
814 |
If EOF is encountered while reading, a truncated byteArray is returned. |
|
815 |
If EOF is already reached before the first byte can be read, |
|
15839 | 816 |
an error is raised." |
2714 | 817 |
|
818 |
|data n| |
|
819 |
||
7187 | 820 |
data := ByteArray uninitializedNew:count. |
2714 | 821 |
n := self nextBytes:count into:data startingAt:1. |
822 |
n ~~ count ifTrue:[ |
|
7187 | 823 |
n == 0 ifTrue:[ |
15839 | 824 |
^ self pastEndRead. |
7187 | 825 |
]. |
826 |
data := data copyTo:n |
|
2714 | 827 |
]. |
828 |
^ data |
|
829 |
||
3346 | 830 |
"Created: / 21.6.1997 / 11:18:57 / cg" |
831 |
"Modified: / 30.3.1998 / 18:04:58 / cg" |
|
2714 | 832 |
! |
833 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
834 |
nextBytes:count into:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
835 |
"read the next count bytes into an object and return the number of |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
836 |
bytes read. On EOF, 0 is returned. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
837 |
If the receiver is some socket/pipe-like stream, an exception |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
838 |
is raised if the connection is broken. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
839 |
|
20242 | 840 |
The object must have non-pointer indexed instvars (i.e. it must be |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
841 |
a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
842 |
If anObject is a string or byteArray and reused, this provides the |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
843 |
fastest possible physical I/O (since no new objects are allocated). |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
844 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
845 |
Use with care - non object oriented i/o. |
20242 | 846 |
Warning: in general, you cannot use this method to pass data from other |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
847 |
architectures since it does not care for byte order or float representation." |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
848 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
849 |
^ self nextBytes:count into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
850 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
851 |
"Modified: 22.4.1997 / 10:41:39 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
852 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
853 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
854 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
855 |
"return the next numBytes from the stream. If the end is |
22515 | 856 |
reached before, only that many bytes are copied into the |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
857 |
collection. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
858 |
Returns the number of bytes that have been actually read. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
859 |
The receiver must support reading of binary bytes. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
860 |
|
9001 | 861 |
Notice: this method is provided here for protocol completeness |
7506 | 862 |
with externalStreams - it is normally not used with other |
863 |
streams." |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
864 |
|
17610 | 865 |
|n "{Class: SmallInteger }"| |
866 |
||
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
867 |
n := 0. |
7506 | 868 |
|
17610 | 869 |
[n ~= numBytes and:[self atEnd not]] whileTrue:[ |
870 |
aCollection byteAt:initialIndex+n put:self nextByte. |
|
15839 | 871 |
n := n + 1. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
872 |
]. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
873 |
^ n |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
874 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
875 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
876 |
|s n buffer| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
877 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
878 |
buffer := ByteArray new:10. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
879 |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
880 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
881 |
s next:3. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
882 |
n := s nextBytes:9 into:buffer startingAt:1. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
883 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
884 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
885 |
|
17610 | 886 |
" |
887 |
|s n buffer| |
|
888 |
||
889 |
buffer := String new:10. |
|
890 |
||
891 |
s := ReadStream on:'Hello World'. |
|
892 |
s next:6. |
|
893 |
n := s nextBytes:5 into:buffer startingAt:1. |
|
894 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
895 |
" |
|
896 |
||
22515 | 897 |
"Modified: / 22-04-1997 / 10:43:08 / cg" |
898 |
"Modified (comment): / 29-01-2018 / 14:43:09 / mawalch" |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
899 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
900 |
|
2587 | 901 |
nextBytes:numBytes into:aCollection startingAt:initialIndex blockSize:blockSize |
902 |
"like nextBytes:into:startingAt:, but read in blocks of the given size. |
|
22209 | 903 |
This leads to better behavior when reading large chunks from a slow device, |
2587 | 904 |
such as a cdrom drive (since a single unix-read is not interruptable)." |
905 |
||
906 |
|nR oR n| |
|
907 |
||
908 |
nR := numBytes. |
|
909 |
oR := initialIndex. |
|
910 |
[nR > 0] whileTrue:[ |
|
22209 | 911 |
n := nR. |
912 |
n > blockSize ifTrue:[n := blockSize]. |
|
913 |
n := self nextBytes:n into:aCollection startingAt:oR. |
|
914 |
n == 0 ifTrue:[ |
|
915 |
^ numBytes - nR |
|
916 |
]. |
|
917 |
oR := oR + n. |
|
918 |
nR := nR - n |
|
2587 | 919 |
]. |
920 |
^ numBytes |
|
921 |
||
22209 | 922 |
"Created: / 24-04-1997 / 21:09:34 / cg" |
923 |
"Modified (comment): / 25-08-2017 / 00:17:09 / cg" |
|
2587 | 924 |
! |
925 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
926 |
nextBytesInto:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
927 |
"read bytes into an object, regardless of binary/text mode. |
19565 | 928 |
The number of bytes to read is defined by the object's size. |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
929 |
Return the number of bytes read. On EOF, 0 is returned. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
930 |
If the receiver is some socket/pipe-like stream, an exception |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
931 |
is raised if the connection is broken. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
932 |
|
20242 | 933 |
The object to read into must have non-pointer indexed instvars |
934 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
935 |
If anObject is a string or byteArray and reused, this provides the |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
936 |
fastest possible physical I/O (since no new objects are allocated). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
937 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
938 |
Use with care - non object oriented i/o. |
20242 | 939 |
Warning: in general, you cannot use this method to pass data from other |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
940 |
architectures since it does not care for byte order or float representation." |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
941 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
942 |
^ self nextBytes:(anObject byteSize) into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
943 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
944 |
" to read 100 bytes from a stream: |
20242 | 945 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
946 |
|b aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
947 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
948 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
949 |
b := ByteArray new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
950 |
aStream nextBytesInto:b. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
951 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
952 |
b inspect |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
953 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
954 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
955 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
956 |
|s aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
957 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
958 |
s := String new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
959 |
aStream nextBytesInto:s. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
960 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
961 |
s inspect |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
962 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
963 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
964 |
"Modified: 22.4.1997 / 10:42:02 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
965 |
"Created: 22.4.1997 / 10:42:26 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
966 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
967 |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
968 |
nextIEEEDouble |
19618 | 969 |
"read an 8-byte IEEE double precision float number in native byte order" |
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
970 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
971 |
^ Float readBinaryIEEEDoubleFrom:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
972 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
973 |
|
17628 | 974 |
nextIEEEDoubleMSB:msbFirst |
975 |
"read an 8-byte IEEE double precision float number" |
|
976 |
||
977 |
^ Float readBinaryIEEEDoubleFrom:self MSB:msbFirst |
|
978 |
! |
|
979 |
||
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
980 |
nextIEEESingle |
19618 | 981 |
"read a 4-byte IEEE single precision float number in native byte order" |
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
982 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
983 |
^ ShortFloat readBinaryIEEESingleFrom:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
984 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
985 |
|
17628 | 986 |
nextIEEESingleMSB:msbFirst |
987 |
"read a 4-byte IEEE single precision float number" |
|
988 |
||
989 |
^ ShortFloat readBinaryIEEESingleFrom:self MSB:msbFirst |
|
990 |
! |
|
991 |
||
19211 | 992 |
nextInt16MSB:msbFlag |
993 |
"return a signed short (2 bytes) from the stream. |
|
994 |
The receiver must support reading of binary bytes. |
|
995 |
||
996 |
The msbFlag argument controls if the integer is to be read with |
|
997 |
most-significant-byte-first (true) or least-first (false). |
|
998 |
This interface is provided to allow talking to external programs, |
|
999 |
where it's known that the byte order is some definite one. |
|
1000 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1001 |
order, please use the corresponding xxxNet methods, which use a standard |
|
1002 |
network byte order." |
|
1003 |
||
1004 |
|b1 b2 uval "{ Class: SmallInteger }"| |
|
1005 |
||
1006 |
b1 := self nextByte. |
|
1007 |
b2 := self nextByte. |
|
1008 |
||
1009 |
msbFlag ifTrue:[ |
|
1010 |
"most significant first" |
|
1011 |
uval := b1 bitShift:8. |
|
1012 |
uval := uval bitOr:b2. |
|
1013 |
] ifFalse:[ |
|
1014 |
"least significant first" |
|
1015 |
uval := b2 bitShift:8. |
|
1016 |
uval := uval bitOr:b1. |
|
1017 |
]. |
|
1018 |
"change from unsigned 0..FFFF to signed -8000..7FFF" |
|
1019 |
uval >= 16r8000 ifTrue:[ |
|
20242 | 1020 |
^ uval - 16r10000 |
19211 | 1021 |
]. |
1022 |
^ uval |
|
1023 |
||
1024 |
"Modified: 11.7.1996 / 10:07:04 / cg" |
|
1025 |
! |
|
1026 |
||
19393 | 1027 |
nextInt24MSB:msbFlag |
1028 |
"return a signed 3 byte integer from the stream. |
|
1029 |
The receiver must support reading of binary bytes. |
|
1030 |
||
1031 |
The msbFlag argument controls if the integer is to be read with |
|
1032 |
most-significant-byte-first (true) or least-first (false). |
|
1033 |
This interface is provided to allow talking to external programs, |
|
1034 |
where it's known that the byte order is some definite one. |
|
1035 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1036 |
order, please use the corresponding xxxNet methods, which use a standard |
|
1037 |
network byte order." |
|
1038 |
||
1039 |
|uval "{ Class: SmallInteger }"| |
|
1040 |
||
1041 |
uval := self nextUnsignedInt24MSB:msbFlag. |
|
1042 |
"change from unsigned 0..FFFFFF to signed -800000..7FFFFF" |
|
1043 |
uval >= 16r800000 ifTrue:[ |
|
20242 | 1044 |
^ uval - 16r1000000 |
19393 | 1045 |
]. |
1046 |
^ uval |
|
1047 |
||
1048 |
" |
|
1049 |
((ReadStream on:#[16r10 16r20 16rFF]) nextInt24MSB:true) hexPrintString |
|
1050 |
((ReadStream on:#[16rFF 16r20 16r30]) nextInt24MSB:false) hexPrintString |
|
1051 |
||
1052 |
((ReadStream on:#[16rFF 16r20 16r30]) nextInt24MSB:true) hexPrintString |
|
1053 |
((ReadStream on:#[16r10 16r20 16rFF]) nextInt24MSB:false) hexPrintString |
|
1054 |
" |
|
1055 |
! |
|
1056 |
||
19211 | 1057 |
nextInt32MSB:msbFlag |
611 | 1058 |
"return a signed long (4 bytes) from the stream. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1059 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1060 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1061 |
The msbFlag argument controls if the integer is to be read with |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1062 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1063 |
This interface is provided to allow talking to external programs, |
19648 | 1064 |
where it's known that the byte order is some definite one. |
20824 | 1065 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1066 |
order, please use the corresponding xxxNet methods, which use a standard |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1067 |
network byte order." |
611 | 1068 |
|
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1069 |
|b1 b2 b3 b4 uval "{ Class: SmallInteger }" val| |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1070 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1071 |
b1 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1072 |
b2 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1073 |
b3 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1074 |
b4 := self nextByte. |
611 | 1075 |
|
1076 |
msbFlag ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1077 |
"most significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1078 |
uval := (b1 bitShift:8) bitOr:b2. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1079 |
uval := (uval bitShift:8) bitOr:b3. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1080 |
val := (uval bitShift:8) bitOr:b4. |
611 | 1081 |
] ifFalse:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1082 |
"least significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1083 |
uval := (b4 bitShift:8) bitOr:b3. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1084 |
uval := (uval bitShift:8) bitOr:b2. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1085 |
val := (uval bitShift:8) bitOr:b1. |
611 | 1086 |
]. |
1087 |
"change from unsigned 0..FFFFFFFF to signed -80000000..7FFFFFFF" |
|
1088 |
||
3176 | 1089 |
val >= 16r80000000 ifTrue:[ |
20242 | 1090 |
^ val - 16r100000000 |
3176 | 1091 |
]. |
1092 |
^ val |
|
1093 |
||
1094 |
" |
|
1095 |
|bytes s| |
|
1096 |
||
1097 |
bytes := #[16rFF 16rFF 16rFF 16rFF]. |
|
1098 |
s := bytes readStream. |
|
19211 | 1099 |
Transcript showCR:(s nextInt32MSB:true). |
3176 | 1100 |
s reset. |
19211 | 1101 |
Transcript showCR:(s nextInt32MSB:false). |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1102 |
|
3176 | 1103 |
bytes := #[16r12 16r34 16r56 16r78]. |
1104 |
s := bytes readStream. |
|
19211 | 1105 |
Transcript showCR:(s nextInt32MSB:true). |
3176 | 1106 |
s reset. |
19211 | 1107 |
Transcript showCR:(s nextInt32MSB:false). |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1108 |
|
3176 | 1109 |
bytes := #[16r89 16rab 16rcd 16ref]. |
1110 |
s := bytes readStream. |
|
19211 | 1111 |
Transcript showCR:(s nextInt32MSB:true). |
3176 | 1112 |
s reset. |
19211 | 1113 |
Transcript showCR:(s nextInt32MSB:false). |
3176 | 1114 |
" |
1115 |
||
1116 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
611 | 1117 |
! |
1118 |
||
19211 | 1119 |
nextInt64MSB:msbFlag |
19604 | 1120 |
"return a signed longlong (also called hyper) (8 bytes) from the stream. |
19211 | 1121 |
The receiver must support reading of binary bytes. |
1122 |
||
1123 |
The msbFlag argument controls if the integer is to be read with |
|
1124 |
most-significant-byte-first (true) or least-first (false). |
|
1125 |
This interface is provided to allow talking to external programs, |
|
19648 | 1126 |
where it's known that the byte order is some definite one. |
20824 | 1127 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
19211 | 1128 |
order, please use the corresponding xxxNet methods, which use a standard |
1129 |
network byte order." |
|
1130 |
||
1131 |
|uval| |
|
1132 |
||
1133 |
uval := self nextUnsignedInt64MSB:msbFlag. |
|
1134 |
"change from unsigned 0..FF..FF to signed -80..00..7FF..FF" |
|
1135 |
||
1136 |
uval >= 16r8000000000000000 ifTrue:[ |
|
20242 | 1137 |
^ uval - 16r10000000000000000 |
19211 | 1138 |
]. |
1139 |
^ uval |
|
1140 |
||
1141 |
" |
|
1142 |
|bytes s| |
|
1143 |
||
1144 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
|
1145 |
s := bytes readStream. |
|
1146 |
Transcript showCR:(s nextInt64MSB:true) hexPrintString. |
|
1147 |
s reset. |
|
1148 |
Transcript showCR:(s nextInt64MSB:false) hexPrintString. |
|
1149 |
||
1150 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
|
1151 |
s := bytes readStream. |
|
1152 |
Transcript showCR:(s nextInt64MSB:true) hexPrintString. |
|
1153 |
s reset. |
|
1154 |
Transcript showCR:(s nextInt64MSB:false) hexPrintString. |
|
1155 |
||
1156 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
|
1157 |
s := bytes readStream. |
|
1158 |
Transcript showCR:(s nextInt64MSB:true) hexPrintString. |
|
1159 |
s reset. |
|
1160 |
Transcript showCR:(s nextInt64MSB:false) hexPrintString. |
|
1161 |
||
1162 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
|
1163 |
s := bytes readStream. |
|
1164 |
Transcript showCR:(s nextInt64MSB:true) hexPrintString. |
|
1165 |
s reset. |
|
1166 |
Transcript showCR:(s nextInt64MSB:false) hexPrintString. |
|
1167 |
" |
|
1168 |
||
1169 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
1170 |
! |
|
1171 |
||
4588 | 1172 |
nextSignedByte |
1173 |
"return a signed byte (-128..127) from the stream. |
|
1174 |
The receiver must support reading of binary bytes." |
|
1175 |
||
1176 |
|uval "{ Class: SmallInteger }"| |
|
1177 |
||
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1178 |
uval := self nextByte. |
4588 | 1179 |
"change from unsigned 0..FF to signed -80..7F" |
1180 |
uval >= 16r80 ifTrue:[ |
|
20242 | 1181 |
^ uval - 16r100 |
4588 | 1182 |
]. |
1183 |
^ uval |
|
1184 |
||
1185 |
" |
|
1186 |
#[16rFF 16r80 16r7F 16r01] readStream nextSignedByte |
|
1187 |
" |
|
1188 |
! |
|
1189 |
||
19562 | 1190 |
nextString:count |
1191 |
"read the next count bytes and return it as a string. |
|
20242 | 1192 |
If EOF is encountered while reading, a truncated string is returned. |
19562 | 1193 |
If EOF is already reached before the first byte can be read, |
1194 |
an error is raised." |
|
1195 |
||
1196 |
|data n| |
|
1197 |
||
1198 |
data := String uninitializedNew:count. |
|
1199 |
n := self nextBytes:count into:data startingAt:1. |
|
1200 |
n ~~ count ifTrue:[ |
|
1201 |
n == 0 ifTrue:[ |
|
1202 |
^ self pastEndRead. |
|
1203 |
]. |
|
1204 |
data := data copyTo:n |
|
1205 |
]. |
|
1206 |
^ data |
|
1207 |
! |
|
1208 |
||
12129 | 1209 |
nextUnsigned:numBytes MSB:msbFlag |
1210 |
"return a numBytes-sized unsigned (numBytes bytes) from the stream as an Integer. |
|
1211 |
The receiver must support reading of binary bytes. |
|
1212 |
||
1213 |
The msbFlag argument controls if the integer is to be read with |
|
1214 |
most-significant-byte-first (true) or least-first (false). |
|
1215 |
This interface is provided to allow talking to external programs, |
|
19648 | 1216 |
where it's known that the byte order is some definite one. |
1217 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
12129 | 1218 |
order, please use the corresponding xxxNet methods, which use a standard |
1219 |
network byte order." |
|
1220 |
||
19607 | 1221 |
|val shift bytes| |
12129 | 1222 |
|
1223 |
"claus: this method is central in binaryStorage - |
|
1224 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
1225 |
||
1226 |
numBytes == 1 ifTrue:[ |
|
1227 |
^ self nextByte |
|
1228 |
]. |
|
1229 |
numBytes == 2 ifTrue:[ |
|
19214 | 1230 |
^ self nextUnsignedInt16MSB:msbFlag |
12129 | 1231 |
]. |
1232 |
numBytes == 3 ifTrue:[ |
|
19395 | 1233 |
^ self nextUnsignedInt24MSB:msbFlag. |
12129 | 1234 |
]. |
1235 |
numBytes == 4 ifTrue:[ |
|
19214 | 1236 |
^ self nextUnsignedInt32MSB:msbFlag |
12129 | 1237 |
]. |
19393 | 1238 |
numBytes == 8 ifTrue:[ |
1239 |
^ self nextUnsignedInt64MSB:msbFlag |
|
1240 |
]. |
|
19607 | 1241 |
"/ bytes |
1242 |
bytes := self nextBytes:numBytes. |
|
1243 |
^ (LargeInteger digitBytes:bytes MSB:msbFlag) compressed |
|
20242 | 1244 |
|
19607 | 1245 |
"/ val := 0. |
1246 |
"/ msbFlag ifTrue:[ |
|
1247 |
"/ numBytes timesRepeat:[ |
|
1248 |
"/ val := (val bitShift:8) + self nextByte |
|
1249 |
"/ ]. |
|
1250 |
"/ ] ifFalse:[ |
|
1251 |
"/ shift := 0. |
|
1252 |
"/ numBytes timesRepeat:[ |
|
1253 |
"/ val := val + (self nextByte bitShift:shift). |
|
1254 |
"/ shift := shift + 8. |
|
1255 |
"/ ]. |
|
1256 |
"/ ]. |
|
1257 |
"/ ^ val |
|
12129 | 1258 |
|
1259 |
" |
|
1260 |
|s| |
|
1261 |
||
1262 |
s := #[ 16r01 16r02 16r03 16r04 16r05 ] readStream. |
|
20242 | 1263 |
(s nextUnsigned:3 MSB:true) hexPrintString. |
19607 | 1264 |
s := #[ 16r01 16r02 16r03 16r04 16r05 16r06 16r07 16r08 16r09 ] readStream. |
20242 | 1265 |
(s nextUnsigned:9 MSB:true) hexPrintString. |
12129 | 1266 |
|
1267 |
s := #[ 16r01 16r02 16r03 16r04 16r05 ] readStream. |
|
20242 | 1268 |
(s nextUnsigned:3 MSB:false) hexPrintString. |
19607 | 1269 |
s := #[ 16r01 16r02 16r03 16r04 16r05 16r06 16r07 16r08 16r09 ] readStream. |
20242 | 1270 |
(s nextUnsigned:9 MSB:false) hexPrintString. |
12129 | 1271 |
" |
1272 |
! |
|
1273 |
||
19211 | 1274 |
nextUnsignedInt16MSB:msbFlag |
1275 |
"return an unsigned short (2 bytes) from the stream. |
|
1276 |
The receiver must support reading of binary bytes. |
|
1277 |
||
1278 |
The msbFlag argument controls if the integer is to be read with |
|
1279 |
most-significant-byte-first (true) or least-first (false). |
|
1280 |
This interface is provided to allow talking to external programs, |
|
19648 | 1281 |
where it's known that the byte order is some definite one. |
1282 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
19211 | 1283 |
order, please use the corresponding xxxNet methods, which use a standard |
1284 |
network byte order." |
|
1285 |
||
20097 | 1286 |
|b1 b2 uval "{ Class: SmallInteger }"| |
19211 | 1287 |
|
1288 |
b1 := self nextByte. |
|
1289 |
b2 := self nextByte. |
|
1290 |
||
1291 |
msbFlag ifTrue:[ |
|
20097 | 1292 |
"most significant first" |
1293 |
uval := b1 bitShift:8. |
|
1294 |
uval := uval bitOr:b2. |
|
19393 | 1295 |
] ifFalse:[ |
20097 | 1296 |
"least significant first" |
1297 |
uval := b2 bitShift:8. |
|
1298 |
uval := uval bitOr:b1. |
|
1299 |
]. |
|
1300 |
||
1301 |
^ uval |
|
19211 | 1302 |
|
19396 | 1303 |
" |
1304 |
((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt16MSB:true) hexPrintString |
|
1305 |
((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt16MSB:false) hexPrintString |
|
1306 |
" |
|
1307 |
||
19211 | 1308 |
"Modified: 11.7.1996 / 10:07:20 / cg" |
1309 |
! |
|
1310 |
||
19393 | 1311 |
nextUnsignedInt24MSB:msbFlag |
1312 |
"return an unsigned 3 byte integer from the stream. |
|
1313 |
The receiver must support reading of binary bytes. |
|
1314 |
||
1315 |
The msbFlag argument controls if the integer is to be read with |
|
1316 |
most-significant-byte-first (true) or least-first (false). |
|
1317 |
This interface is provided to allow talking to external programs, |
|
19648 | 1318 |
where it's known that the byte order is some definite one. |
1319 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
19393 | 1320 |
order, please use the corresponding xxxNet methods, which use a standard |
1321 |
network byte order." |
|
1322 |
||
1323 |
|b1 b2 b3 bL bM bH| |
|
1324 |
||
1325 |
b1 := self nextByte. |
|
1326 |
b2 := self nextByte. |
|
1327 |
b3 := self nextByte. |
|
1328 |
||
1329 |
msbFlag ifTrue:[ |
|
1330 |
bH := b1. |
|
1331 |
bM := b2. |
|
1332 |
bL := b3. |
|
1333 |
] ifFalse:[ |
|
1334 |
bH := b3. |
|
1335 |
bM := b2. |
|
1336 |
bL := b1. |
|
20242 | 1337 |
]. |
19393 | 1338 |
^ (((bH bitShift:8) bitOr:bM) bitShift:8) bitOr:bL |
1339 |
||
1340 |
" |
|
1341 |
((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt24MSB:true) hexPrintString |
|
1342 |
((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt24MSB:false) hexPrintString |
|
1343 |
" |
|
1344 |
! |
|
1345 |
||
19211 | 1346 |
nextUnsignedInt32MSB:msbFlag |
1347 |
"return an unsigned long (4 bytes) from the stream. |
|
1348 |
The receiver must support reading of binary bytes. |
|
1349 |
||
1350 |
The msbFlag argument controls if the integer is to be read with |
|
1351 |
most-significant-byte-first (true) or least-first (false). |
|
1352 |
This interface is provided to allow talking to external programs, |
|
19648 | 1353 |
where it's known that the byte order is some definite one. |
1354 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
19211 | 1355 |
order, please use the corresponding xxxNet methods, which use a standard |
1356 |
network byte order." |
|
1357 |
||
20097 | 1358 |
|b1 b2 b3 b4 uval "{ Class: SmallInteger }" val| |
19211 | 1359 |
|
1360 |
b1 := self nextByte. |
|
1361 |
b2 := self nextByte. |
|
1362 |
b3 := self nextByte. |
|
1363 |
b4 := self nextByte. |
|
1364 |
||
1365 |
msbFlag ifTrue:[ |
|
20097 | 1366 |
"most significant first" |
1367 |
uval := (b1 bitShift:8) bitOr:b2. |
|
1368 |
uval := (uval bitShift:8) bitOr:b3. |
|
1369 |
val := (uval bitShift:8) bitOr:b4. |
|
1370 |
] ifFalse:[ |
|
1371 |
"least significant first" |
|
1372 |
uval := (b4 bitShift:8) bitOr:b3. |
|
1373 |
uval := (uval bitShift:8) bitOr:b2. |
|
1374 |
val := (uval bitShift:8) bitOr:b1. |
|
19211 | 1375 |
]. |
20097 | 1376 |
|
19211 | 1377 |
^ val |
19604 | 1378 |
! |
1379 |
||
19211 | 1380 |
nextUnsignedInt64MSB:msbFlag |
19604 | 1381 |
"return an unsigned longlong (also called hyper) (8 bytes) from the stream. |
19211 | 1382 |
The receiver must support reading of binary bytes. |
1383 |
||
1384 |
The msbFlag argument controls if the integer is to be read with |
|
1385 |
most-significant-byte-first (true) or least-first (false). |
|
1386 |
This interface is provided to allow talking to external programs, |
|
19648 | 1387 |
where it's known that the byte order is some definite one. |
1388 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
19211 | 1389 |
order, please use the corresponding xxxNet methods, which use a standard |
1390 |
network byte order." |
|
1391 |
||
1392 |
|bytes uval t| |
|
1393 |
||
1394 |
bytes := self nextBytes:8. |
|
1395 |
uval := 0. |
|
1396 |
||
1397 |
msbFlag ifTrue:[ |
|
1398 |
"most significant first" |
|
1399 |
1 to:8 do:[:i | |
|
1400 |
t := (uval bitShift:8). |
|
1401 |
uval := t bitOr:(bytes at:i). |
|
1402 |
]. |
|
1403 |
] ifFalse:[ |
|
1404 |
"least significant first" |
|
1405 |
8 to:1 by:-1 do:[:i | |
|
1406 |
t := (uval bitShift:8). |
|
1407 |
uval := t bitOr:(bytes at:i). |
|
1408 |
]. |
|
1409 |
]. |
|
1410 |
^ uval |
|
1411 |
||
1412 |
" |
|
1413 |
|bytes s| |
|
1414 |
||
1415 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
|
1416 |
s := bytes readStream. |
|
1417 |
Transcript showCR:(s nextUnsignedInt64MSB:true) hexPrintString. |
|
1418 |
s reset. |
|
1419 |
Transcript showCR:(s nextUnsignedInt64MSB:false) hexPrintString. |
|
1420 |
||
1421 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
|
1422 |
s := bytes readStream. |
|
1423 |
Transcript showCR:(s nextUnsignedInt64MSB:true) hexPrintString. |
|
1424 |
s reset. |
|
1425 |
Transcript showCR:(s nextUnsignedInt64MSB:false) hexPrintString. |
|
1426 |
||
1427 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
|
1428 |
s := bytes readStream. |
|
1429 |
Transcript showCR:(s nextUnsignedInt64MSB:true) hexPrintString. |
|
1430 |
s reset. |
|
1431 |
Transcript showCR:(s nextUnsignedInt64MSB:false) hexPrintString. |
|
1432 |
||
1433 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
|
1434 |
s := bytes readStream. |
|
1435 |
Transcript showCR:(s nextUnsignedInt64MSB:true) hexPrintString. |
|
1436 |
s reset. |
|
1437 |
Transcript showCR:(s nextUnsignedInt64MSB:false) hexPrintString. |
|
1438 |
" |
|
1439 |
||
1440 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
20097 | 1441 |
! ! |
1442 |
||
1443 |
!Stream methodsFor:'non homogenous reading - aliases'! |
|
1444 |
||
1445 |
nextInt16LSB |
|
1446 |
"return a signed short (2 bytes) in LSB-first order from the stream. |
|
1447 |
The receiver must support reading of binary bytes." |
|
1448 |
||
1449 |
^ self nextInt16MSB:false |
|
1450 |
! |
|
1451 |
||
1452 |
nextInt16MSB |
|
1453 |
"return a signed short (2 bytes) in MSB-first order from the stream. |
|
1454 |
The receiver must support reading of binary bytes." |
|
1455 |
||
1456 |
^ self nextInt16MSB:true |
|
1457 |
! |
|
1458 |
||
1459 |
nextInt16Net |
|
1460 |
"return a signed short (2 bytes) in network byte order from the stream. |
|
1461 |
The receiver must support reading of binary bytes. |
|
1462 |
Network byte order is MSB-first per definition" |
|
1463 |
||
1464 |
^ self nextInt16MSB:true |
|
1465 |
||
1466 |
"Created: 10.1.1996 / 19:49:41 / cg" |
|
1467 |
! |
|
1468 |
||
1469 |
nextInt32LSB |
|
1470 |
"return a signed long (4 bytes) in LSB-first order from the stream. |
|
1471 |
The receiver must support reading of binary bytes." |
|
1472 |
||
1473 |
^ self nextInt32MSB:false |
|
1474 |
! |
|
1475 |
||
1476 |
nextInt32MSB |
|
1477 |
"return a signed long (4 bytes) in MSB-first order from the stream. |
|
1478 |
The receiver must support reading of binary bytes." |
|
1479 |
||
1480 |
^ self nextInt32MSB:true |
|
1481 |
! |
|
1482 |
||
1483 |
nextInt32Net |
|
1484 |
"return a signed long (4 bytes) in network byte order from the stream. |
|
1485 |
The receiver must support reading of binary bytes. |
|
1486 |
Network byte order is MSB-first per definition" |
|
1487 |
||
1488 |
^ self nextInt32MSB:true |
|
1489 |
||
1490 |
"Created: 10.1.1996 / 19:49:28 / cg" |
|
1491 |
! |
|
1492 |
||
1493 |
nextInt64LSB |
|
1494 |
"return a signed longlong (also called hyper) (8 bytes) in LSB-first order from the stream. |
|
1495 |
The receiver must support reading of binary bytes." |
|
1496 |
||
1497 |
^ self nextInt64MSB:false |
|
1498 |
! |
|
1499 |
||
1500 |
nextInt64MSB |
|
1501 |
"return a signed longlong (also called hyper) (8 bytes) in MSB-first order from the stream. |
|
1502 |
The receiver must support reading of binary bytes." |
|
1503 |
||
1504 |
^ self nextInt64MSB:true |
|
1505 |
! |
|
1506 |
||
1507 |
nextInt64Net |
|
1508 |
"return a signed longlong (also called hyper) (8 bytes) in network byte order from the stream. |
|
1509 |
The receiver must support reading of binary bytes. |
|
1510 |
Network byte order is MSB-first per definition" |
|
1511 |
||
1512 |
^ self nextInt64MSB:true |
|
1513 |
! |
|
1514 |
||
20242 | 1515 |
nextNumber:numBytes |
1516 |
"Return the next n bytes as a positive Integer; |
|
20097 | 1517 |
bytes are taken msb-first." |
1518 |
||
1519 |
^ self nextUnsigned:numBytes MSB:true |
|
1520 |
! |
|
1521 |
||
1522 |
nextUnsignedInt16LSB |
|
1523 |
"return an unsigned short (2 bytes) in LSB-first order from the stream. |
|
1524 |
The receiver must support reading of binary bytes." |
|
1525 |
||
1526 |
^ self nextUnsignedInt16MSB:false |
|
1527 |
! |
|
1528 |
||
1529 |
nextUnsignedInt16MSB |
|
1530 |
"return an unsigned short (2 bytes) in MSB-first order from the stream. |
|
1531 |
The receiver must support reading of binary bytes." |
|
1532 |
||
1533 |
^ self nextUnsignedInt16MSB:true |
|
1534 |
! |
|
1535 |
||
1536 |
nextUnsignedInt16Net |
|
1537 |
"return an unsigned short (2 bytes) in network byte order from the stream. |
|
1538 |
The receiver must support reading of binary bytes. |
|
1539 |
Network byte order is MSB-first per definition" |
|
1540 |
||
1541 |
^ self nextUnsignedInt16MSB:true |
|
1542 |
||
1543 |
"Created: 10.1.1996 / 19:50:02 / cg" |
|
1544 |
! |
|
1545 |
||
1546 |
nextUnsignedInt32LSB |
|
1547 |
"return an unsigned long (4 bytes) in LSB-first order from the stream. |
|
1548 |
The receiver must support reading of binary bytes." |
|
1549 |
||
1550 |
^ self nextUnsignedInt32MSB:false |
|
1551 |
! |
|
1552 |
||
1553 |
nextUnsignedInt32MSB |
|
1554 |
"return an unsigned long (4 bytes) in MSB-first order from the stream. |
|
1555 |
The receiver must support reading of binary bytes." |
|
1556 |
||
1557 |
^ self nextUnsignedInt32MSB:true |
|
1558 |
! |
|
1559 |
||
1560 |
nextUnsignedInt32Net |
|
1561 |
"return an unsigned long (4 bytes) in network byte order from the stream. |
|
1562 |
The receiver must support reading of binary bytes. |
|
1563 |
Network byte order is MSB-first per definition" |
|
1564 |
||
1565 |
^ self nextUnsignedInt32MSB:true |
|
1566 |
||
1567 |
"Created: 10.1.1996 / 19:49:02 / cg" |
|
1568 |
"Modified: 10.1.1996 / 19:49:50 / cg" |
|
1569 |
! |
|
1570 |
||
1571 |
nextUnsignedInt64LSB |
|
1572 |
"return an unsigned longlong (also called hyper) (8 bytes) in LSB-first order from the stream. |
|
1573 |
The receiver must support reading of binary bytes." |
|
1574 |
||
1575 |
^ self nextUnsignedInt64MSB:false |
|
1576 |
! |
|
1577 |
||
1578 |
nextUnsignedInt64MSB |
|
1579 |
"return an unsigned longlong (also called hyper) (8 bytes) in MSB-first order from the stream. |
|
1580 |
The receiver must support reading of binary bytes." |
|
1581 |
||
1582 |
^ self nextUnsignedInt64MSB:true |
|
19211 | 1583 |
! |
1584 |
||
1585 |
nextUnsignedInt64Net |
|
19604 | 1586 |
"return an unsigned longlong (also called hyper) (8 bytes) in network byte order from the stream. |
1587 |
The receiver must support reading of binary bytes. |
|
1588 |
Network byte order is MSB-first per definition" |
|
19211 | 1589 |
|
1590 |
^ self nextUnsignedInt64MSB:true |
|
1591 |
! ! |
|
1592 |
||
1593 |
!Stream methodsFor:'non homogenous reading - obsolete'! |
|
1594 |
||
1595 |
nextHyperMSB:msbFlag |
|
19569 | 1596 |
<resource: #obsolete> |
19211 | 1597 |
"return a signed hyper (8 bytes) from the stream. |
1598 |
The receiver must support reading of binary bytes. |
|
1599 |
||
1600 |
The msbFlag argument controls if the integer is to be read with |
|
1601 |
most-significant-byte-first (true) or least-first (false). |
|
1602 |
This interface is provided to allow talking to external programs, |
|
19648 | 1603 |
where it's known that the byte order is some definite one. |
20824 | 1604 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
19211 | 1605 |
order, please use the corresponding xxxNet methods, which use a standard |
1606 |
network byte order." |
|
1607 |
||
1608 |
^ self nextInt64MSB:msbFlag |
|
1609 |
||
1610 |
" |
|
1611 |
|bytes s| |
|
1612 |
||
1613 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
|
1614 |
s := bytes readStream. |
|
1615 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
|
1616 |
s reset. |
|
1617 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
|
1618 |
||
1619 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
|
1620 |
s := bytes readStream. |
|
1621 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
|
1622 |
s reset. |
|
1623 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
|
1624 |
||
1625 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
|
1626 |
s := bytes readStream. |
|
1627 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
|
1628 |
s reset. |
|
1629 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
|
1630 |
||
1631 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
|
1632 |
s := bytes readStream. |
|
1633 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
|
1634 |
s reset. |
|
1635 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
|
1636 |
" |
|
1637 |
||
1638 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
1639 |
! |
|
1640 |
||
19212 | 1641 |
nextLong |
19569 | 1642 |
<resource: #obsolete> |
19212 | 1643 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
1644 |
The returned value may be a LargeInteger. |
|
1645 |
(msb-first for compatibility with other smalltalks)" |
|
1646 |
||
1647 |
^ self nextInt32MSB:true |
|
1648 |
! |
|
1649 |
||
19211 | 1650 |
nextLongMSB:msbFlag |
19569 | 1651 |
<resource: #obsolete> |
19211 | 1652 |
"return a signed long (4 bytes) from the stream. |
1653 |
The receiver must support reading of binary bytes. |
|
1654 |
||
1655 |
The msbFlag argument controls if the integer is to be read with |
|
1656 |
most-significant-byte-first (true) or least-first (false). |
|
1657 |
This interface is provided to allow talking to external programs, |
|
19648 | 1658 |
where it's known that the byte order is some definite one. |
20824 | 1659 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
19211 | 1660 |
order, please use the corresponding xxxNet methods, which use a standard |
1661 |
network byte order." |
|
1662 |
||
1663 |
^ self nextInt32MSB:msbFlag |
|
1664 |
||
1665 |
" |
|
1666 |
|bytes s| |
|
1667 |
||
1668 |
bytes := #[16rFF 16rFF 16rFF 16rFF]. |
|
1669 |
s := bytes readStream. |
|
1670 |
Transcript showCR:(s nextLongMSB:true). |
|
1671 |
s reset. |
|
1672 |
Transcript showCR:(s nextLongMSB:false). |
|
1673 |
||
1674 |
bytes := #[16r12 16r34 16r56 16r78]. |
|
1675 |
s := bytes readStream. |
|
1676 |
Transcript showCR:(s nextLongMSB:true). |
|
1677 |
s reset. |
|
1678 |
Transcript showCR:(s nextLongMSB:false). |
|
1679 |
||
1680 |
bytes := #[16r89 16rab 16rcd 16ref]. |
|
1681 |
s := bytes readStream. |
|
1682 |
Transcript showCR:(s nextLongMSB:true). |
|
1683 |
s reset. |
|
1684 |
Transcript showCR:(s nextLongMSB:false). |
|
1685 |
" |
|
1686 |
||
1687 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
1688 |
! |
|
1689 |
||
1690 |
nextLongNet |
|
19569 | 1691 |
<resource: #obsolete> |
19211 | 1692 |
"return a signed long (4 bytes) in network byte order from the stream. |
1693 |
The receiver must support reading of binary bytes." |
|
1694 |
||
1695 |
^ self nextInt32MSB:true |
|
1696 |
||
1697 |
"Created: 10.1.1996 / 19:49:28 / cg" |
|
1698 |
! |
|
1699 |
||
1700 |
nextShortMSB:msbFlag |
|
19569 | 1701 |
<resource: #obsolete> |
19211 | 1702 |
"return a signed short (2 bytes) from the stream. |
1703 |
The receiver must support reading of binary bytes. |
|
1704 |
||
1705 |
The msbFlag argument controls if the integer is to be read with |
|
1706 |
most-significant-byte-first (true) or least-first (false). |
|
1707 |
This interface is provided to allow talking to external programs, |
|
1708 |
where it's known that the byte order is some definite one. |
|
1709 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1710 |
order, please use the corresponding xxxNet methods, which use a standard |
|
1711 |
network byte order." |
|
1712 |
||
1713 |
^ self nextInt16MSB:msbFlag |
|
1714 |
||
1715 |
"Modified: 11.7.1996 / 10:07:04 / cg" |
|
1716 |
! |
|
1717 |
||
1718 |
nextShortNet |
|
19569 | 1719 |
<resource: #obsolete> |
19211 | 1720 |
"return a signed short (2 bytes) in network byte order from the stream. |
1721 |
The receiver must support reading of binary bytes. |
|
1722 |
Network byte order is MSB per definition" |
|
1723 |
||
1724 |
^ self nextInt16MSB:true |
|
1725 |
||
1726 |
"Created: 10.1.1996 / 19:49:41 / cg" |
|
1727 |
! |
|
1728 |
||
20097 | 1729 |
nextUnsignedHyperMSB:msbFlag |
1730 |
<resource: #obsolete> |
|
1731 |
"return an unsigned hyper (8 bytes) from the stream. |
|
1732 |
The receiver must support reading of binary bytes. |
|
1733 |
||
1734 |
The msbFlag argument controls if the integer is to be read with |
|
1735 |
most-significant-byte-first (true) or least-first (false). |
|
1736 |
This interface is provided to allow talking to external programs, |
|
1737 |
where it's known that the byte order is some definite one. |
|
1738 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1739 |
order, please use the corresponding xxxNet methods, which use a standard |
|
1740 |
network byte order." |
|
1741 |
||
1742 |
^ self nextUnsignedInt64MSB:msbFlag |
|
1743 |
||
1744 |
" |
|
1745 |
|bytes s| |
|
1746 |
||
1747 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
|
1748 |
s := bytes readStream. |
|
1749 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
|
1750 |
s reset. |
|
1751 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
|
1752 |
||
1753 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
|
1754 |
s := bytes readStream. |
|
1755 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
|
1756 |
s reset. |
|
1757 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
|
1758 |
||
1759 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
|
1760 |
s := bytes readStream. |
|
1761 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
|
1762 |
s reset. |
|
1763 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
|
1764 |
||
1765 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
|
1766 |
s := bytes readStream. |
|
1767 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
|
1768 |
s reset. |
|
1769 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
|
1770 |
" |
|
1771 |
||
1772 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
1773 |
! |
|
1774 |
||
611 | 1775 |
nextUnsignedLongMSB:msbFlag |
19569 | 1776 |
<resource: #obsolete> |
611 | 1777 |
"return an unsigned long (4 bytes) from the stream. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1778 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1779 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1780 |
The msbFlag argument controls if the integer is to be read with |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1781 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1782 |
This interface is provided to allow talking to external programs, |
19648 | 1783 |
where it's known that the byte order is some definite one. |
1784 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1785 |
order, please use the corresponding xxxNet methods, which use a standard |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1786 |
network byte order." |
611 | 1787 |
|
19212 | 1788 |
^ self nextUnsignedInt32MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1789 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1790 |
"Modified: 11.7.1996 / 10:07:13 / cg" |
611 | 1791 |
! |
1792 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1793 |
nextUnsignedLongNet |
19569 | 1794 |
<resource: #obsolete> |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1795 |
"return an unsigned long (4 bytes) in network byte order from the stream. |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1796 |
The receiver must support reading of binary bytes." |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1797 |
|
19212 | 1798 |
^ self nextUnsignedInt32MSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1799 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1800 |
"Created: 10.1.1996 / 19:49:02 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1801 |
"Modified: 10.1.1996 / 19:49:50 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1802 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1803 |
|
611 | 1804 |
nextUnsignedShortMSB:msbFlag |
19569 | 1805 |
<resource: #obsolete> |
611 | 1806 |
"return an unsigned short (2 bytes) from the stream. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1807 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1808 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1809 |
The msbFlag argument controls if the integer is to be read with |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1810 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1811 |
This interface is provided to allow talking to external programs, |
19648 | 1812 |
where it's known that the byte order is some definite one. |
1813 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1814 |
order, please use the corresponding xxxNet methods, which use a standard |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1815 |
network byte order." |
611 | 1816 |
|
19212 | 1817 |
^ self nextUnsignedInt16MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1818 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1819 |
"Modified: 11.7.1996 / 10:07:20 / cg" |
611 | 1820 |
! |
1821 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1822 |
nextUnsignedShortNet |
19569 | 1823 |
<resource: #obsolete> |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1824 |
"return an unsigned short (2 bytes) in network byte order from the stream. |
8894
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1825 |
The receiver must support reading of binary bytes. |
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1826 |
Network byte order is MSB per definition" |
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1827 |
|
19212 | 1828 |
^ self nextUnsignedInt16MSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1829 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1830 |
"Created: 10.1.1996 / 19:50:02 / cg" |
611 | 1831 |
! ! |
1832 |
||
1833 |
!Stream methodsFor:'non homogenous writing'! |
|
1834 |
||
19571 | 1835 |
next:count putByte:aByteValue |
1836 |
"write a byte n times" |
|
1837 |
||
1838 |
|n "{ Class: SmallInteger }"| |
|
1839 |
||
1840 |
n := count. |
|
1841 |
n timesRepeat:[self nextPutByte:aByteValue]. |
|
1842 |
||
1843 |
" |
|
1844 |
|s| |
|
1845 |
s := ByteArray new writeStream. |
|
1846 |
s nextPutByte:1. |
|
1847 |
s next:10 putByte:99. |
|
1848 |
s nextPutByte:2. |
|
1849 |
s contents |
|
1850 |
" |
|
1851 |
! |
|
1852 |
||
20242 | 1853 |
nextNumber:n put:v |
611 | 1854 |
"Append to the receiver the argument, v, which is a positive Integer, |
20242 | 1855 |
as the next n bytes. Bytes are written msb first. |
611 | 1856 |
Possibly pad with leading zeros. |
1857 |
The receiver must support writing of binary bytes." |
|
1858 |
||
19564 | 1859 |
self nextNumber:n put:v MSB:true |
1860 |
! |
|
1861 |
||
1862 |
nextNumber:n put:v MSB:msb |
|
1863 |
"Append to the receiver the argument, v, which is a positive Integer, |
|
20242 | 1864 |
as the next n bytes. |
1865 |
Bytes are written in the specified byte order. |
|
19564 | 1866 |
Possibly pad with leading zeros (trailing zeros, if lsb). |
1867 |
The receiver must support writing of binary bytes." |
|
1868 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1869 |
|vlen "{ Class: SmallInteger }" |
19564 | 1870 |
i "{ Class: SmallInteger }" |
1871 |
bl bm bh bml bmh| |
|
611 | 1872 |
|
1873 |
"claus: this method is central in binaryStorage - |
|
1874 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
1875 |
||
1876 |
v class == SmallInteger ifTrue:[ "- this is a hint to stc" |
|
9407 | 1877 |
n == 1 ifTrue:[ |
1878 |
(v between:0 and:16rFF) ifTrue:[ |
|
1879 |
self nextPutByte:v. |
|
1880 |
^ self |
|
1881 |
]. |
|
1882 |
]. |
|
1883 |
n == 2 ifTrue:[ |
|
1884 |
(v between:0 and:16rFFFF) ifTrue:[ |
|
19564 | 1885 |
bl := (v bitAnd:16rFF). |
1886 |
bh := (v bitShift:-8) bitAnd:16rFF. |
|
1887 |
msb ifTrue:[ |
|
1888 |
self nextPutByte:bh; nextPutByte:bl. |
|
20242 | 1889 |
] ifFalse:[ |
19564 | 1890 |
self nextPutByte:bl; nextPutByte:bh. |
20242 | 1891 |
]. |
9407 | 1892 |
^ self |
1893 |
]. |
|
1894 |
]. |
|
1895 |
n == 3 ifTrue:[ |
|
1896 |
(v between:0 and:16rFFFFFF) ifTrue:[ |
|
19564 | 1897 |
bl := (v bitAnd:16rFF). |
1898 |
bm := (v bitShift:-8) bitAnd:16rFF. |
|
1899 |
bh := (v bitShift:-16) bitAnd:16rFF. |
|
1900 |
msb ifTrue:[ |
|
1901 |
self nextPutByte:bh. |
|
1902 |
self nextPutByte:bm. |
|
1903 |
self nextPutByte:bl. |
|
1904 |
] ifFalse:[ |
|
1905 |
self nextPutByte:bl. |
|
1906 |
self nextPutByte:bm. |
|
1907 |
self nextPutByte:bh. |
|
20242 | 1908 |
]. |
9407 | 1909 |
^ self |
1910 |
]. |
|
1911 |
]. |
|
1912 |
n == 4 ifTrue:[ |
|
19564 | 1913 |
(v between:0 and:16rFFFFFFFF) ifTrue:[ |
1914 |
bl := (v bitAnd:16rFF). |
|
1915 |
bml := (v bitShift:-8) bitAnd:16rFF. |
|
1916 |
bmh := (v bitShift:-16) bitAnd:16rFF. |
|
1917 |
bh := (v bitShift:-24) bitAnd:16rFF. |
|
1918 |
msb ifTrue:[ |
|
1919 |
self nextPutByte:bh. |
|
1920 |
self nextPutByte:bmh. |
|
1921 |
self nextPutByte:bml. |
|
1922 |
self nextPutByte:bl. |
|
1923 |
] ifFalse:[ |
|
1924 |
self nextPutByte:bl. |
|
1925 |
self nextPutByte:bml. |
|
1926 |
self nextPutByte:bmh. |
|
1927 |
self nextPutByte:bh. |
|
1928 |
]. |
|
9407 | 1929 |
^ self |
1930 |
]. |
|
1931 |
]. |
|
611 | 1932 |
]. |
1933 |
||
1934 |
" |
|
1935 |
arbitrary long |
|
1936 |
" |
|
1937 |
n < (vlen := v digitLength) ifTrue: [ |
|
9407 | 1938 |
" |
1939 |
the number is too big to be repesented in n bytes |
|
1940 |
" |
|
1941 |
self error:'number too big' |
|
611 | 1942 |
]. |
1943 |
||
19564 | 1944 |
msb ifTrue:[ |
1945 |
"pad with leading zeros" |
|
1946 |
i := n. |
|
1947 |
[i > vlen] whileTrue:[ |
|
20242 | 1948 |
self nextPutByte:0. |
19564 | 1949 |
i := i - 1 |
1950 |
]. |
|
1951 |
||
1952 |
i == 1 ifTrue:[ |
|
1953 |
^ self nextPutByte:v |
|
1954 |
]. |
|
1955 |
||
1956 |
[i > 0] whileTrue:[ |
|
20242 | 1957 |
self nextPutByte:(v digitAt:i). |
19564 | 1958 |
i := i - 1 |
1959 |
] |
|
1960 |
] ifFalse:[ |
|
20366 | 1961 |
1 to:vlen do:[:idx | |
1962 |
self nextPutByte:(v digitAt:idx). |
|
20242 | 1963 |
]. |
19564 | 1964 |
"pad with trailing zeros" |
20366 | 1965 |
vlen+1 to:n do:[:idx | |
20242 | 1966 |
self nextPutByte:0. |
19564 | 1967 |
]. |
20242 | 1968 |
]. |
9407 | 1969 |
|
1970 |
"Modified: / 22-06-2006 / 11:31:13 / fm" |
|
611 | 1971 |
! |
1972 |
||
15654 | 1973 |
nextPutAllUtf16:aString |
21467 | 1974 |
"write a string as UTF-16BE characters." |
1975 |
||
1976 |
self nextPutAllUtf16Bytes:aString MSB:true |
|
1977 |
||
1978 |
"Modified (comment): / 16-02-2017 / 17:04:37 / stefan" |
|
15654 | 1979 |
! |
1980 |
||
19623 | 1981 |
nextPutAllUtf16Bytes:aString MSB:msb |
1982 |
"write a string as UTF-16 bytes - no 0-word is written. |
|
1983 |
The underlying stream must support writing of bytes" |
|
1984 |
||
1985 |
|sz "{Class: SmallInteger}"| |
|
1986 |
||
1987 |
sz := aString size. |
|
1988 |
1 to:sz do:[:idx| |
|
20097 | 1989 |
self nextPutUtf16Bytes:(aString at:idx) MSB:msb. |
19623 | 1990 |
]. |
20097 | 1991 |
|
1992 |
" |
|
1993 |
(#[] writeStream |
|
24035 | 1994 |
nextPutAllUtf16Bytes:'BÄxxx' MSB:true; |
20097 | 1995 |
nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true; |
1996 |
contents) |
|
1997 |
" |
|
19623 | 1998 |
! |
1999 |
||
11322 | 2000 |
nextPutAllUtf8:aString |
21467 | 2001 |
"write the UTF-8 representation of aString to myself." |
2002 |
||
2003 |
|string |
|
2004 |
stringSize "{ Class: SmallInteger }"| |
|
2005 |
||
2006 |
string := aString string. |
|
2007 |
||
2008 |
"/ avoid creation of new strings if possible |
|
2009 |
string containsNon7BitAscii ifFalse:[ |
|
2010 |
self nextPutAll:string asSingleByteString. |
|
2011 |
^ self. |
|
2012 |
]. |
|
2013 |
||
2014 |
stringSize := string size. |
|
2015 |
1 to:stringSize do:[:idx | |
|
2016 |
self nextPutUtf8:(string at:idx). |
|
11322 | 2017 |
]. |
21467 | 2018 |
|
2019 |
" |
|
24035 | 2020 |
String streamContents:[:s| |
2021 |
s nextPutAllUtf8:'hallo' |
|
2022 |
]. |
|
2023 |
||
2024 |
ByteArray streamContents:[:s| |
|
2025 |
s nextPutAllUtf8:'hallo' |
|
2026 |
]. |
|
2027 |
||
2028 |
String streamContents:[:s| |
|
2029 |
s nextPutAllUtf8:'abcdeäöüß' asUnicode32String |
|
2030 |
]. |
|
2031 |
||
2032 |
ByteArray streamContents:[:s| |
|
2033 |
s nextPutAllUtf8:'abcdeäöüß' asUnicode32String |
|
2034 |
]. |
|
2035 |
||
2036 |
'/tmp/bytes' asFilename writingFileDo:[:s| |
|
2037 |
s nextPutAllUtf8:'abcdeäöüß' |
|
2038 |
]. |
|
21467 | 2039 |
" |
2040 |
||
2041 |
"Modified (format): / 16-02-2017 / 20:28:52 / stefan" |
|
24035 | 2042 |
"Modified (comment): / 02-04-2019 / 11:10:25 / Claus Gittinger" |
11322 | 2043 |
! |
2044 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2045 |
nextPutByte:aByteValue |
20242 | 2046 |
"write a byte. |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2047 |
Same as nextPut: here; for protocol compatibility with externalStream." |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2048 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2049 |
self nextPut:aByteValue |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2050 |
|
9407 | 2051 |
"Created: / 22-04-1997 / 10:43:55 / cg" |
2052 |
"Modified: / 23-06-2006 / 12:19:47 / fm" |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2053 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2054 |
|
12093 | 2055 |
nextPutBytes:anObject |
2056 |
"write bytes from an object; the number of bytes is defined by |
|
19565 | 2057 |
the object's size. |
12093 | 2058 |
Return the number of bytes written or nil on error. |
20242 | 2059 |
The object must have non-pointer indexed instvars |
2060 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
12093 | 2061 |
Use with care - non object oriented i/o. |
20242 | 2062 |
Warning: in general, you cannot use this method to pass non-byte data to other |
12093 | 2063 |
architectures since it does not care for byte order or float representation." |
2064 |
||
2065 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
|
2066 |
||
2067 |
"Created: 22.4.1997 / 10:44:18 / cg" |
|
2068 |
! |
|
2069 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2070 |
nextPutBytes:count from:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2071 |
"write count bytes from an object. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2072 |
Return the number of bytes written or nil on error. |
20242 | 2073 |
The object must have non-pointer indexed instvars |
2074 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2075 |
Use with care - non object oriented i/o. |
20242 | 2076 |
Warning: in general, you cannot use this method to pass non-byte data to other |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2077 |
architectures since it does not care for byte order or float representation." |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2078 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2079 |
^ self nextPutBytes:count from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2080 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2081 |
"Created: 22.4.1997 / 10:43:59 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2082 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2083 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2084 |
nextPutBytes:count from:anObject startingAt:start |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2085 |
"write count bytes from an object starting at index start. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2086 |
Return the number of bytes written. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2087 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2088 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2089 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2090 |
This is provided for compatibility with externalStream; |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2091 |
to support binary storage" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2092 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2093 |
|idx| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2094 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2095 |
idx := start. |
7506 | 2096 |
self isBinary ifTrue:[ |
2097 |
1 to:count do:[:i | |
|
2098 |
self nextPutByte:(anObject byteAt:idx). |
|
2099 |
idx := idx + 1 |
|
2100 |
]. |
|
2101 |
] ifFalse:[ |
|
2102 |
1 to:count do:[:i | |
|
2103 |
self nextPut:(anObject at:idx). |
|
2104 |
idx := idx + 1 |
|
2105 |
]. |
|
2106 |
]. |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2107 |
^ count |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2108 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2109 |
"Created: 22.4.1997 / 10:44:09 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2110 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2111 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2112 |
nextPutBytesFrom:anObject |
19565 | 2113 |
"write bytes from an object; the number of bytes is defined by the object's size. |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2114 |
Return the number of bytes written or nil on error. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2115 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2116 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2117 |
Use with care - non object oriented i/o. |
12093 | 2118 |
Warning: in general, you cannot use this method to pass non-byte data to other |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2119 |
architectures since it does not care for byte order or float representation." |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2120 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2121 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2122 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2123 |
"Created: 22.4.1997 / 10:44:18 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2124 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
2125 |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2126 |
nextPutIEEEDouble:aFloat |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2127 |
"write an 8-byte IEEE double precision float number" |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2128 |
|
17628 | 2129 |
Float storeBinaryIEEEDouble:aFloat on:self MSB:(UninterpretedBytes isBigEndian) |
2130 |
! |
|
2131 |
||
17629 | 2132 |
nextPutIEEEDouble:aFloat MSB:msb |
17628 | 2133 |
"write an 8-byte IEEE double precision float number" |
2134 |
||
2135 |
Float storeBinaryIEEEDouble:aFloat on:self MSB:msb |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2136 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2137 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2138 |
nextPutIEEESingle:aFloat |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2139 |
"write a 4-byte IEEE single precision float number" |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2140 |
|
17628 | 2141 |
ShortFloat storeBinaryIEEESingle:aFloat on:self MSB:(UninterpretedBytes isBigEndian). |
2142 |
! |
|
2143 |
||
17629 | 2144 |
nextPutIEEESingle:aFloat MSB:msb |
17628 | 2145 |
"write a 4-byte IEEE single precision float number" |
2146 |
||
2147 |
ShortFloat storeBinaryIEEESingle:aFloat on:self MSB:msb. |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2148 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
2149 |
|
19211 | 2150 |
nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
20242 | 2151 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
2152 |
If msbFlag is true, data is written most-significant byte first; |
|
2153 |
otherwise least first. |
|
23935 | 2154 |
Returns the receiver. |
19211 | 2155 |
The receiver must support writing of binary bytes. |
2156 |
||
2157 |
This interface is provided to allow talking to external programs, |
|
19648 | 2158 |
where it's known that the byte order is some definite one. |
19211 | 2159 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
2160 |
order, please use the corresponding xxxNet methods, which use a standard |
|
2161 |
network byte order." |
|
2162 |
||
2163 |
|iNum "{ Class: SmallInteger }" hi lo b1 b2| |
|
2164 |
||
2165 |
iNum := anIntegerOrCharacter asInteger. |
|
2166 |
lo := iNum digitByteAt:1. |
|
2167 |
hi := iNum digitByteAt:2. |
|
2168 |
msbFlag ifTrue:[ |
|
2169 |
"high word first" |
|
2170 |
b1 := hi. |
|
2171 |
b2 := lo. |
|
2172 |
] ifFalse:[ |
|
2173 |
"low word first" |
|
2174 |
b1 := lo. |
|
2175 |
b2 := hi. |
|
2176 |
]. |
|
2177 |
self nextPutByte:b1. |
|
2178 |
self nextPutByte:b2. |
|
2179 |
||
2180 |
" |
|
2181 |
|s| |
|
2182 |
||
2183 |
s := #[] writeStream. |
|
2184 |
s nextPutInt16:16r1234 MSB:false. |
|
20242 | 2185 |
s contents. |
19211 | 2186 |
" |
2187 |
" |
|
2188 |
|s| |
|
2189 |
||
2190 |
s := #[] writeStream. |
|
2191 |
s nextPutInt16:16r1234 MSB:true. |
|
2192 |
s contents. |
|
2193 |
" |
|
2194 |
||
2195 |
"Modified: / 22-06-2006 / 11:30:26 / fm" |
|
23935 | 2196 |
"Modified (comment): / 17-03-2019 / 14:58:20 / Claus Gittinger" |
19211 | 2197 |
! |
2198 |
||
19604 | 2199 |
nextPutInt16LSB:aNumber |
2200 |
"Write the argument, aNumber as a short (two bytes) in LSB-first order. |
|
2201 |
Returns the receiver on ok, nil on error. |
|
2202 |
The receiver must support writing of binary bytes." |
|
2203 |
||
23935 | 2204 |
self nextPutInt16:aNumber MSB:false. |
2205 |
||
2206 |
"Modified: / 17-03-2019 / 14:55:37 / Claus Gittinger" |
|
19604 | 2207 |
! |
2208 |
||
2209 |
nextPutInt16MSB:aNumber |
|
2210 |
"Write the argument, aNumber as a short (two bytes) in MSB-first order. |
|
23935 | 2211 |
Returns the receiver. |
19604 | 2212 |
The receiver must support writing of binary bytes." |
2213 |
||
23935 | 2214 |
self nextPutInt16:aNumber MSB:true. |
2215 |
||
2216 |
"Modified (comment): / 17-03-2019 / 14:58:37 / Claus Gittinger" |
|
19604 | 2217 |
! |
2218 |
||
19211 | 2219 |
nextPutInt16Net:aNumber |
2220 |
"Write the argument, aNumber as a short (two bytes) in the network byte order. |
|
23935 | 2221 |
Returns the receiver. |
19211 | 2222 |
The receiver must support writing of binary bytes. |
19604 | 2223 |
Network byte order is MSB-first per definition" |
19211 | 2224 |
|
23935 | 2225 |
self nextPutInt16:aNumber MSB:true. |
2226 |
||
2227 |
"Created: / 10-01-1996 / 19:50:33 / cg" |
|
2228 |
"Modified: / 17-03-2019 / 14:58:50 / Claus Gittinger" |
|
19211 | 2229 |
! |
2230 |
||
2231 |
nextPutInt32:aNumber MSB:msbFlag |
|
20242 | 2232 |
"Write the argument, aNumber as a long (four bytes). |
2233 |
If msbFlag is true, data is written most-significant byte first; |
|
2234 |
otherwise least first. |
|
23935 | 2235 |
Returns the receiver. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2236 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2237 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2238 |
This interface is provided to allow talking to external programs, |
19648 | 2239 |
where it's known that the byte order is some definite one. |
20824 | 2240 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2241 |
order, please use the corresponding xxxNet methods, which use a standard |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2242 |
network byte order." |
611 | 2243 |
|
5960 | 2244 |
|hh hl lh ll b1 b2 b3 b4| |
2245 |
||
2246 |
ll := aNumber digitByteAt:1. |
|
2247 |
lh := aNumber digitByteAt:2. |
|
2248 |
hl := aNumber digitByteAt:3. |
|
2249 |
hh := aNumber digitByteAt:4. |
|
611 | 2250 |
msbFlag ifTrue:[ |
9407 | 2251 |
"high byte first" |
2252 |
b1 := hh. |
|
2253 |
b2 := hl. |
|
2254 |
b3 := lh. |
|
2255 |
b4 := ll. |
|
2332 | 2256 |
] ifFalse:[ |
9407 | 2257 |
"low word first" |
2258 |
b1 := ll. |
|
2259 |
b2 := lh. |
|
2260 |
b3 := hl. |
|
2261 |
b4 := hh. |
|
611 | 2262 |
]. |
9407 | 2263 |
self nextPutByte:b1. |
2264 |
self nextPutByte:b2. |
|
2265 |
self nextPutByte:b3. |
|
2266 |
self nextPutByte:b4. |
|
5960 | 2267 |
|
2268 |
" |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2269 |
|s bytes| |
5960 | 2270 |
|
2271 |
s := #[] writeStream. |
|
19211 | 2272 |
s nextPutInt32:16r12345678 MSB:false. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2273 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2274 |
s := bytes readStream. |
20242 | 2275 |
(s nextInt32MSB:false) hexPrintString. |
5960 | 2276 |
" |
2277 |
" |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2278 |
|s bytes| |
5960 | 2279 |
|
2280 |
s := #[] writeStream. |
|
19211 | 2281 |
s nextPutInt32:16r12345678 MSB:true. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2282 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2283 |
s := bytes readStream. |
20242 | 2284 |
(s nextInt32MSB:true) hexPrintString. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2285 |
. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2286 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2287 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2288 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2289 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2290 |
s := #[] writeStream. |
19211 | 2291 |
s nextPutInt32:16r-80000000 MSB:true. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2292 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2293 |
s := bytes readStream. |
20242 | 2294 |
(s nextInt32MSB:true) hexPrintString. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2295 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2296 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2297 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2298 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2299 |
s := #[] writeStream. |
19211 | 2300 |
s nextPutInt32:16r-80000000 MSB:false. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2301 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
2302 |
s := bytes readStream. |
20242 | 2303 |
(s nextInt32MSB:false) hexPrintString. |
5960 | 2304 |
" |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2305 |
|
9407 | 2306 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
2307 |
"Modified: / 22-06-2006 / 11:31:43 / fm" |
|
23935 | 2308 |
"Modified (comment): / 17-03-2019 / 14:59:00 / Claus Gittinger" |
611 | 2309 |
! |
2310 |
||
19604 | 2311 |
nextPutInt32LSB:aNumber |
2312 |
"Write the argument, aNumber as a long (4 bytes) in LSB-first order. |
|
23935 | 2313 |
Returns the receiver. |
19604 | 2314 |
The receiver must support writing of binary bytes." |
2315 |
||
23935 | 2316 |
self nextPutInt32:aNumber MSB:false. |
2317 |
||
2318 |
"Modified: / 17-03-2019 / 14:59:07 / Claus Gittinger" |
|
19604 | 2319 |
! |
2320 |
||
2321 |
nextPutInt32MSB:aNumber |
|
2322 |
"Write the argument, aNumber as a long (4 bytes) in MSB-first order. |
|
23935 | 2323 |
Returns the receiver. |
19604 | 2324 |
The receiver must support writing of binary bytes." |
2325 |
||
23935 | 2326 |
self nextPutInt32:aNumber MSB:true. |
2327 |
||
2328 |
"Modified: / 17-03-2019 / 14:59:14 / Claus Gittinger" |
|
19604 | 2329 |
! |
2330 |
||
19211 | 2331 |
nextPutInt32Net:aNumber |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
2332 |
"Write the argument, aNumber as a long (four bytes) in the network byte order. |
23935 | 2333 |
Returns the receiver. |
19604 | 2334 |
The receiver must support writing of binary bytes. |
2335 |
Network byte order is MSB-first per definition" |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
2336 |
|
23935 | 2337 |
self nextPutInt32:aNumber MSB:true |
2338 |
||
2339 |
"Modified: / 17-03-2019 / 14:59:22 / Claus Gittinger" |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
2340 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
2341 |
|
19211 | 2342 |
nextPutInt64:aNumber MSB:msbFlag |
20242 | 2343 |
"Write the argument, aNumber as a longlong (8 bytes). |
2344 |
If msbFlag is true, data is written most-significant byte first; |
|
2345 |
otherwise least first. |
|
23935 | 2346 |
Returns the receiver. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2347 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2348 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2349 |
This interface is provided to allow talking to external programs, |
19648 | 2350 |
where it's known that the byte order is some definite one. |
15654 | 2351 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2352 |
order, please use the corresponding xxxNet methods, which use a standard |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2353 |
network byte order." |
611 | 2354 |
|
2355 |
msbFlag ifTrue:[ |
|
19211 | 2356 |
1 to:8 do:[:i | |
2357 |
self nextPutByte:(aNumber digitByteAt:8+1-i) |
|
2358 |
]. |
|
2332 | 2359 |
] ifFalse:[ |
19211 | 2360 |
1 to:8 do:[:i | |
2361 |
self nextPutByte:(aNumber digitByteAt:i) |
|
2362 |
]. |
|
611 | 2363 |
]. |
5960 | 2364 |
|
2365 |
" |
|
19211 | 2366 |
|s bytes| |
2367 |
||
2368 |
s := #[] writeStream. |
|
19235 | 2369 |
s nextPutInt64:16r123456789abcdef0 MSB:false. |
19211 | 2370 |
bytes := s contents. |
2371 |
s := bytes readStream. |
|
20242 | 2372 |
(s nextUInt64MSB:false) hexPrintString. |
19211 | 2373 |
" |
2374 |
" |
|
2375 |
|s bytes| |
|
2376 |
||
2377 |
s := #[] writeStream. |
|
19235 | 2378 |
s nextPutInt64:16r123456789abcdef0 MSB:true. |
19211 | 2379 |
bytes := s contents. |
2380 |
s := bytes readStream. |
|
20242 | 2381 |
(s nextUInt64MSB:true) hexPrintString. |
19211 | 2382 |
" |
2383 |
" |
|
2384 |
|s bytes| |
|
2385 |
||
2386 |
s := #[] writeStream. |
|
19235 | 2387 |
s nextPutInt64:16r-8000000000000000 MSB:true. |
19211 | 2388 |
bytes := s contents. |
2389 |
s := bytes readStream. |
|
20242 | 2390 |
(s nextUInt64MSB:true) hexPrintString. |
19211 | 2391 |
" |
2392 |
" |
|
2393 |
|s bytes| |
|
5960 | 2394 |
|
2395 |
s := #[] writeStream. |
|
19235 | 2396 |
s nextPutInt64:16r-8000000000000000 MSB:false. |
19211 | 2397 |
bytes := s contents. |
2398 |
s := bytes readStream. |
|
20242 | 2399 |
(s nextUInt64MSB:false) hexPrintString. |
5960 | 2400 |
" |
19211 | 2401 |
|
2402 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
|
2403 |
"Modified: / 22-06-2006 / 11:31:37 / fm" |
|
23935 | 2404 |
"Modified (comment): / 17-03-2019 / 14:59:33 / Claus Gittinger" |
19211 | 2405 |
! |
2406 |
||
19604 | 2407 |
nextPutInt64LSB:aNumber |
2408 |
"Write the argument, aNumber as a longlong (8 bytes) in LSB-first order. |
|
23935 | 2409 |
Returns the receiver. |
19604 | 2410 |
The receiver must support writing of binary bytes." |
2411 |
||
23935 | 2412 |
self nextPutInt64:aNumber MSB:false. |
2413 |
||
2414 |
"Modified: / 17-03-2019 / 14:59:42 / Claus Gittinger" |
|
19604 | 2415 |
! |
2416 |
||
2417 |
nextPutInt64MSB:aNumber |
|
2418 |
"Write the argument, aNumber as a longlong (8 bytes) in MSB-first order. |
|
23935 | 2419 |
Returns the receiver. |
19604 | 2420 |
The receiver must support writing of binary bytes." |
2421 |
||
23935 | 2422 |
self nextPutInt64:aNumber MSB:true. |
2423 |
||
2424 |
"Modified: / 17-03-2019 / 14:59:49 / Claus Gittinger" |
|
19604 | 2425 |
! |
2426 |
||
19211 | 2427 |
nextPutInt64Net:aNumber |
2428 |
"Write the argument, aNumber as a longlong (8 bytes) in the network byte order. |
|
23935 | 2429 |
Returns the receiver. |
19604 | 2430 |
The receiver must support writing of binary bytes. |
2431 |
Network byte order is MSB-first per definition" |
|
19211 | 2432 |
|
23935 | 2433 |
self nextPutInt64:aNumber MSB:true |
2434 |
||
2435 |
"Modified: / 17-03-2019 / 14:59:56 / Claus Gittinger" |
|
19211 | 2436 |
! |
2437 |
||
15652 | 2438 |
nextPutUtf16:aCharacter |
2439 |
"append my UTF-16 representation to the argument, aStream. |
|
19623 | 2440 |
Notice: this writes characters - not bytes. |
2441 |
The underlying stream must be a stream which can deal with characters, |
|
2442 |
eg. OrderedCollectionStream, TwoByteCharacterStream, etc. |
|
20097 | 2443 |
Also notice, that characters above 16rFFFF are escaped according UTF16 specifications." |
15654 | 2444 |
|
17620 | 2445 |
|codePoint "{Class: SmallInteger}"| |
15654 | 2446 |
|
2447 |
codePoint := aCharacter codePoint. |
|
20711 | 2448 |
(codePoint <= 16rD7FF or:[codePoint between:16rE000 and:16rFFFF]) |
2449 |
ifTrue:[ |
|
2450 |
self nextPut:aCharacter. |
|
2451 |
] |
|
2452 |
ifFalse:[ |
|
2453 |
codePoint <= 16r10FFFF ifTrue:[ |
|
2454 |
|highBits lowBits| |
|
2455 |
||
2456 |
codePoint := codePoint - 16r100000. |
|
2457 |
highBits := codePoint bitShift:-10. |
|
2458 |
lowBits := codePoint bitAnd:16r3FF. |
|
2459 |
self nextPut:(Character codePoint:highBits+16rD800). |
|
2460 |
self nextPut:(Character codePoint:lowBits+16rDC00). |
|
2461 |
] ifFalse:[ |
|
2462 |
EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'. |
|
2463 |
] |
|
2464 |
]. |
|
15654 | 2465 |
|
2466 |
" |
|
2467 |
((WriteStream on:Unicode16String new) |
|
2468 |
nextPutUtf16:$B; |
|
24035 | 2469 |
nextPutUtf16:$Ä; |
15654 | 2470 |
nextPutUtf16:(Character codePoint:16r10CCCC) |
2471 |
yourself) contents |
|
2472 |
" |
|
15652 | 2473 |
! |
2474 |
||
20242 | 2475 |
nextPutUtf16Bytes:aCharacter MSB:msb |
20097 | 2476 |
"append my UTF-16 representation to the argument, aStream. |
2477 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF. |
|
2478 |
The underlying stream must support writing of bytes." |
|
20242 | 2479 |
|
20711 | 2480 |
|codePoint "{ Class: SmallInteger }"| |
20097 | 2481 |
|
2482 |
codePoint := aCharacter codePoint. |
|
22433 | 2483 |
(codePoint <= 16rD7FF or:[codePoint between:16rE000 and:16rFFFF]) ifTrue:[ |
2484 |
self nextPutInt16:codePoint MSB:msb. |
|
2485 |
] ifFalse:[ |
|
2486 |
codePoint <= 16r10FFFF ifTrue:[ |
|
2487 |
|highBits lowBits| |
|
2488 |
||
2489 |
codePoint := codePoint - 16r100000. |
|
2490 |
highBits := codePoint bitShift:-10. |
|
2491 |
lowBits := codePoint bitAnd:16r3FF. |
|
2492 |
self nextPutInt16:(highBits + 16rD800) MSB:msb. |
|
2493 |
self nextPutInt16:(lowBits + 16rDC00) MSB:msb. |
|
2494 |
] ifFalse:[ |
|
2495 |
EncodingError |
|
2496 |
raiseWith:aCharacter |
|
2497 |
errorString:'Character cannot be encoded as UTF-16'. |
|
20711 | 2498 |
] |
22433 | 2499 |
]. |
20097 | 2500 |
|
2501 |
" |
|
2502 |
(#[] writeStream |
|
21467 | 2503 |
nextPutUtf16Bytes:$B MSB:true; |
24035 | 2504 |
nextPutUtf16Bytes:$Ä MSB:true; |
21467 | 2505 |
nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true; |
2506 |
contents) |
|
2507 |
||
2508 |
('' writeStream |
|
2509 |
nextPutUtf16Bytes:$B MSB:true; |
|
24035 | 2510 |
nextPutUtf16Bytes:$Ä MSB:true; |
21467 | 2511 |
nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true; |
20097 | 2512 |
contents) |
2513 |
||
2514 |
(FileStream newTemporary |
|
21467 | 2515 |
nextPutUtf16Bytes:$B MSB:false; |
24035 | 2516 |
nextPutUtf16Bytes:$Ä MSB:false; |
21467 | 2517 |
nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:false; |
20097 | 2518 |
reset; |
2519 |
binary; |
|
21467 | 2520 |
contents) |
2521 |
" |
|
2522 |
||
22433 | 2523 |
"Modified (format): / 16-01-2018 / 19:41:27 / stefan" |
20097 | 2524 |
! |
2525 |
||
11322 | 2526 |
nextPutUtf8:aCharacter |
2527 |
"append my UTF-8 representation to the argument, aStream. |
|
19623 | 2528 |
The underlying stream must be a stream which can deal with characters. |
11322 | 2529 |
Up to 31 bits can be encoded in up to 6 bytes. |
14593 | 2530 |
However, currently, characters are limited to 31 bits." |
11322 | 2531 |
|
21467 | 2532 |
|codePoint "{Class: SmallInteger}"| |
11322 | 2533 |
|
2534 |
codePoint := aCharacter codePoint. |
|
2535 |
||
2536 |
codePoint <= 16r7F ifTrue:[ |
|
21321 | 2537 |
"/ 7 bits - 1 byte |
21467 | 2538 |
self nextPutByte:codePoint. |
11322 | 2539 |
^ self. |
2540 |
]. |
|
21321 | 2541 |
codePoint <= 16r7FF ifTrue:[ |
2542 |
"/ 11 bits - 2 byte sequence 5+6 |
|
2543 |
self |
|
21467 | 2544 |
nextPutByte:(((codePoint bitShift:-6) bitAnd:16r1F) bitOr:16rC0); |
2545 |
nextPutByte:((codePoint bitAnd:16r3F) bitOr:16r80). |
|
21321 | 2546 |
^ self. |
2547 |
]. |
|
2548 |
codePoint <= 16rFFFF ifTrue:[ |
|
2549 |
"/ 16 bits - 3 byte sequence 4+6+6 |
|
2550 |
self |
|
21467 | 2551 |
nextPutByte:(((codePoint bitShift:-12) bitAnd:16r0F) bitOr:16rE0); |
2552 |
nextPutByte:(((codePoint bitShift:-6) bitAnd:16r3F) bitOr:16r80); |
|
2553 |
nextPutByte:((codePoint bitAnd:16r3F) bitOr:16r80). |
|
11322 | 2554 |
^ self. |
2555 |
]. |
|
21321 | 2556 |
codePoint <= 16r1FFFFF ifTrue:[ |
2557 |
"/ 21 bits - 4 byte sequence 3+6+6+6 |
|
2558 |
self |
|
21467 | 2559 |
nextPutByte:(((codePoint bitShift:-18) bitAnd:16r07) bitOr:16rF0); |
2560 |
nextPutByte:(((codePoint bitShift:-12) bitAnd:16r3F) bitOr:16r80); |
|
2561 |
nextPutByte:(((codePoint bitShift:-6) bitAnd:16r3F) bitOr:16r80); |
|
2562 |
nextPutByte:((codePoint bitAnd:16r3F) bitOr:16r80). |
|
21321 | 2563 |
^ self. |
2564 |
]. |
|
22252 | 2565 |
codePoint <= 16r3FFFFFF ifTrue:[ |
21321 | 2566 |
"/ 26 bits - 5 byte sequence 2+6+6+6+6 |
2567 |
self |
|
21467 | 2568 |
nextPutByte:(((codePoint bitShift:-24) bitAnd:16r03) bitOr:16rF8); |
2569 |
nextPutByte:(((codePoint bitShift:-18) bitAnd:16r3F) bitOr:16r80); |
|
2570 |
nextPutByte:(((codePoint bitShift:-12) bitAnd:16r3F) bitOr:16r80); |
|
2571 |
nextPutByte:(((codePoint bitShift:-6) bitAnd:16r3F) bitOr:16r80); |
|
2572 |
nextPutByte:((codePoint bitAnd:16r3F) bitOr:16r80). |
|
11322 | 2573 |
^ self. |
2574 |
]. |
|
22252 | 2575 |
codePoint <= 16r7FFFFFFF ifTrue:[ |
21321 | 2576 |
"/ 31 bits - 6 byte sequence 1+6+6+6+6+6 |
2577 |
self |
|
21467 | 2578 |
nextPutByte:(((codePoint bitShift:-30) bitAnd:16r01) bitOr:16rFC); |
2579 |
nextPutByte:(((codePoint bitShift:-24) bitAnd:16r3F) bitOr:16r80); |
|
2580 |
nextPutByte:(((codePoint bitShift:-18) bitAnd:16r3F) bitOr:16r80); |
|
2581 |
nextPutByte:(((codePoint bitShift:-12) bitAnd:16r3F) bitOr:16r80); |
|
2582 |
nextPutByte:(((codePoint bitShift:-6) bitAnd:16r3F) bitOr:16r80); |
|
2583 |
nextPutByte:((codePoint bitAnd:16r3F) bitOr:16r80). |
|
11322 | 2584 |
^ self. |
2585 |
]. |
|
21321 | 2586 |
|
2587 |
"/ b1 := Character codePoint:((codePoint bitAnd:16r3F) bitOr:2r10000000). |
|
2588 |
"/ v := codePoint bitShift:-6. |
|
2589 |
"/ v <= 16r1F ifTrue:[ |
|
2590 |
"/ self nextPut:(Character value:(v bitOr:2r11000000)). |
|
2591 |
"/ self nextPut:b1. |
|
2592 |
"/ ^ self. |
|
2593 |
"/ ]. |
|
2594 |
"/ b2 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
2595 |
"/ v := v bitShift:-6. |
|
2596 |
"/ v <= 16r0F ifTrue:[ |
|
2597 |
"/ self nextPut:(Character value:(v bitOr:2r11100000)). |
|
2598 |
"/ self nextPut:b2; nextPut:b1. |
|
2599 |
"/ ^ self. |
|
2600 |
"/ ]. |
|
2601 |
"/ b3 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
2602 |
"/ v := v bitShift:-6. |
|
2603 |
"/ v <= 16r07 ifTrue:[ |
|
2604 |
"/ self nextPut:(Character value:(v bitOr:2r11110000)). |
|
2605 |
"/ self nextPut:b3; nextPut:b2; nextPut:b1. |
|
2606 |
"/ ^ self. |
|
2607 |
"/ ]. |
|
2608 |
"/ b4 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
2609 |
"/ v := v bitShift:-6. |
|
2610 |
"/ v <= 16r03 ifTrue:[ |
|
2611 |
"/ self nextPut:(Character value:(v bitOr:2r11111000)). |
|
2612 |
"/ self nextPut:b4; nextPut:b3; nextPut:b2; nextPut:b1. |
|
2613 |
"/ ^ self. |
|
2614 |
"/ ]. |
|
2615 |
"/ b5 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
2616 |
"/ v := v bitShift:-6. |
|
2617 |
"/ v <= 16r01 ifTrue:[ |
|
2618 |
"/ self nextPut:(Character value:(v bitOr:2r11111100)). |
|
2619 |
"/ self nextPut:b5; nextPut:b4; nextPut:b3; nextPut:b2; nextPut:b1. |
|
2620 |
"/ ^ self. |
|
2621 |
"/ ]. |
|
11322 | 2622 |
|
17620 | 2623 |
EncodingError raiseWith:aCharacter errorString:'codePoint > 31bit in #nextPutUtf8:'. |
11322 | 2624 |
|
2625 |
" |
|
20242 | 2626 |
(String streamContents:[:s| |
11322 | 2627 |
s nextPutUtf8:$a. |
24035 | 2628 |
s nextPutUtf8:$ü. |
11322 | 2629 |
s nextPutUtf8: (Character value:16r1fff). |
2630 |
s nextPutUtf8: (Character value:16rffff). |
|
14593 | 2631 |
s nextPutUtf8: (Character value:16r1ffffff). |
11322 | 2632 |
s nextPutUtf8: (Character value:16r800). |
2633 |
]) |
|
2634 |
asByteArray |
|
20242 | 2635 |
|
11322 | 2636 |
" |
21467 | 2637 |
|
2638 |
"Modified: / 16-02-2017 / 17:25:48 / stefan" |
|
19211 | 2639 |
! ! |
2640 |
||
2641 |
!Stream methodsFor:'non homogenous writing - obsolete'! |
|
2642 |
||
2643 |
nextPutHyper:aNumber MSB:msbFlag |
|
19569 | 2644 |
<resource: #obsolete> |
20242 | 2645 |
"Write the argument, aNumber as a hyper (8 bytes). |
2646 |
If msbFlag is true, data is written most-significant byte first; |
|
2647 |
otherwise least first. |
|
23935 | 2648 |
Returns the receiver. |
611 | 2649 |
The receiver must support writing of binary bytes. |
19211 | 2650 |
|
2651 |
This interface is provided to allow talking to external programs, |
|
19648 | 2652 |
where it's known that the byte order is some definite one. |
20824 | 2653 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
19211 | 2654 |
order, please use the corresponding xxxNet methods, which use a standard |
2655 |
network byte order." |
|
2656 |
||
23935 | 2657 |
self nextPutInt64:aNumber MSB:msbFlag |
19211 | 2658 |
|
2659 |
" |
|
2660 |
|s bytes| |
|
2661 |
||
2662 |
s := #[] writeStream. |
|
2663 |
s nextPutHyper:16r123456789abcdef0 MSB:false. |
|
2664 |
bytes := s contents. |
|
2665 |
s := bytes readStream. |
|
20242 | 2666 |
(s nextHyperMSB:false) hexPrintString. |
19211 | 2667 |
" |
2668 |
" |
|
2669 |
|s bytes| |
|
2670 |
||
2671 |
s := #[] writeStream. |
|
2672 |
s nextPutHyper:16r123456789abcdef0 MSB:true. |
|
2673 |
bytes := s contents. |
|
2674 |
s := bytes readStream. |
|
20242 | 2675 |
(s nextHyperMSB:true) hexPrintString. |
19211 | 2676 |
. |
2677 |
" |
|
2678 |
" |
|
2679 |
|s bytes| |
|
2680 |
||
2681 |
s := #[] writeStream. |
|
2682 |
s nextPutHyper:16r-8000000000000000 MSB:true. |
|
2683 |
bytes := s contents. |
|
2684 |
s := bytes readStream. |
|
20242 | 2685 |
(s nextHyperMSB:true) hexPrintString. |
19211 | 2686 |
" |
2687 |
" |
|
2688 |
|s bytes| |
|
2689 |
||
2690 |
s := #[] writeStream. |
|
2691 |
s nextPutHyper:16r-8000000000000000 MSB:false. |
|
2692 |
bytes := s contents. |
|
2693 |
s := bytes readStream. |
|
20242 | 2694 |
(s nextHyperMSB:false) hexPrintString. |
19211 | 2695 |
" |
2696 |
||
2697 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
|
2698 |
"Modified: / 22-06-2006 / 11:31:37 / fm" |
|
23935 | 2699 |
"Modified: / 17-03-2019 / 15:01:27 / Claus Gittinger" |
611 | 2700 |
! |
2701 |
||
19211 | 2702 |
nextPutLong:aNumber MSB:msbFlag |
19569 | 2703 |
<resource: #obsolete> |
20242 | 2704 |
"Write the argument, aNumber as a long (four bytes). |
2705 |
If msbFlag is true, data is written most-significant byte first; |
|
2706 |
otherwise least first. |
|
23935 | 2707 |
Returns the receiver. |
19211 | 2708 |
The receiver must support writing of binary bytes. |
2709 |
||
2710 |
This interface is provided to allow talking to external programs, |
|
19648 | 2711 |
where it's known that the byte order is some definite one. |
20824 | 2712 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
19211 | 2713 |
order, please use the corresponding xxxNet methods, which use a standard |
2714 |
network byte order." |
|
2715 |
||
23935 | 2716 |
self nextPutInt32:aNumber MSB:msbFlag |
19211 | 2717 |
|
2718 |
" |
|
2719 |
|s bytes| |
|
2720 |
||
2721 |
s := #[] writeStream. |
|
2722 |
s nextPutLong:16r12345678 MSB:false. |
|
2723 |
bytes := s contents. |
|
2724 |
s := bytes readStream. |
|
20242 | 2725 |
(s nextLongMSB:false) hexPrintString. |
19211 | 2726 |
" |
2727 |
" |
|
2728 |
|s bytes| |
|
2729 |
||
2730 |
s := #[] writeStream. |
|
2731 |
s nextPutLong:16r12345678 MSB:true. |
|
2732 |
bytes := s contents. |
|
2733 |
s := bytes readStream. |
|
20242 | 2734 |
(s nextLongMSB:true) hexPrintString. |
19211 | 2735 |
. |
2736 |
" |
|
2737 |
" |
|
2738 |
|s bytes| |
|
2739 |
||
2740 |
s := #[] writeStream. |
|
2741 |
s nextPutLong:16r-80000000 MSB:true. |
|
2742 |
bytes := s contents. |
|
2743 |
s := bytes readStream. |
|
20242 | 2744 |
(s nextLongMSB:true) hexPrintString. |
19211 | 2745 |
" |
2746 |
" |
|
2747 |
|s bytes| |
|
2748 |
||
2749 |
s := #[] writeStream. |
|
2750 |
s nextPutLong:16r-80000000 MSB:false. |
|
2751 |
bytes := s contents. |
|
2752 |
s := bytes readStream. |
|
20242 | 2753 |
(s nextLongMSB:false) hexPrintString. |
19211 | 2754 |
" |
2755 |
||
2756 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
|
2757 |
"Modified: / 22-06-2006 / 11:31:43 / fm" |
|
23935 | 2758 |
"Modified: / 17-03-2019 / 15:01:38 / Claus Gittinger" |
9407 | 2759 |
! |
2760 |
||
19211 | 2761 |
nextPutLongNet:aNumber |
19569 | 2762 |
<resource: #obsolete> |
19211 | 2763 |
"Write the argument, aNumber as a long (four bytes) in the network byte order. |
23935 | 2764 |
Returns the receiver. |
19211 | 2765 |
The receiver must support writing of binary bytes." |
2766 |
||
23935 | 2767 |
self nextPutInt32:aNumber MSB:true |
2768 |
||
2769 |
"Created: / 10-01-1996 / 19:50:23 / cg" |
|
2770 |
"Modified: / 17-03-2019 / 15:01:44 / Claus Gittinger" |
|
19211 | 2771 |
! |
2772 |
||
2773 |
nextPutShort:anIntegerOrCharacter MSB:msbFlag |
|
19569 | 2774 |
<resource: #obsolete> |
20242 | 2775 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
2776 |
If msbFlag is true, data is written most-significant byte first; |
|
2777 |
otherwise least first. |
|
23935 | 2778 |
Returns the receiver. |
19211 | 2779 |
The receiver must support writing of binary bytes. |
2780 |
||
2781 |
This interface is provided to allow talking to external programs, |
|
19648 | 2782 |
where it's known that the byte order is some definite one. |
19211 | 2783 |
If you don't care (i.e. talk to other smalltalks) or you can control the |
2784 |
order, please use the corresponding xxxNet methods, which use a standard |
|
2785 |
network byte order." |
|
2786 |
||
23935 | 2787 |
self nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
19211 | 2788 |
|
2789 |
" |
|
2790 |
|s| |
|
2791 |
||
2792 |
s := #[] writeStream. |
|
2793 |
s nextPutShort:16r1234 MSB:false. |
|
20242 | 2794 |
s contents. |
19211 | 2795 |
" |
2796 |
" |
|
2797 |
|s| |
|
2798 |
||
2799 |
s := #[] writeStream. |
|
2800 |
s nextPutShort:16r1234 MSB:true. |
|
2801 |
s contents. |
|
2802 |
" |
|
2803 |
||
2804 |
"Modified: / 22-06-2006 / 11:30:26 / fm" |
|
23935 | 2805 |
"Modified: / 17-03-2019 / 15:01:53 / Claus Gittinger" |
19211 | 2806 |
! |
2807 |
||
2808 |
nextPutShortNet:aNumber |
|
19569 | 2809 |
<resource: #obsolete> |
19211 | 2810 |
"Write the argument, aNumber as a short (two bytes) in the network byte order. |
23935 | 2811 |
Returns the receiver. |
19211 | 2812 |
The receiver must support writing of binary bytes. |
2813 |
Network byte order is MSB per definition" |
|
2814 |
||
23935 | 2815 |
self nextPutInt16:aNumber MSB:true. |
2816 |
||
2817 |
"Created: / 10-01-1996 / 19:50:33 / cg" |
|
2818 |
"Modified: / 17-03-2019 / 15:02:00 / Claus Gittinger" |
|
611 | 2819 |
! ! |
2820 |
||
20189 | 2821 |
!Stream methodsFor:'open & close'! |
16454 | 2822 |
|
2823 |
close |
|
2824 |
"close the stream - nothing done here. |
|
2825 |
Added for compatibility with external streams." |
|
2826 |
||
2827 |
^ self |
|
2828 |
! ! |
|
2829 |
||
611 | 2830 |
!Stream methodsFor:'queries'! |
2831 |
||
16472 | 2832 |
canReadWithoutBlocking |
18394 | 2833 |
"return true, if the stream can be read without blocking the program (actually: suspending the thread). |
2834 |
This is redefined in external streams, which read from a communication line |
|
2835 |
(sockets and devices). |
|
2836 |
Always true here, because all internal streams never block" |
|
2837 |
||
16472 | 2838 |
^ true |
2839 |
! |
|
2840 |
||
2841 |
canWriteWithoutBlocking |
|
18394 | 2842 |
"return true, if the stream can be written without blocking the program (actually: suspending the thread). |
2843 |
This is redefined in external streams, which write to a communication line |
|
2844 |
(sockets and devices). |
|
2845 |
Always true here, because all internal streams never block" |
|
2846 |
||
16472 | 2847 |
^ true |
2848 |
! |
|
2849 |
||
22417 | 2850 |
contentsSpecies |
2851 |
"this should return the class of which an instance is |
|
2852 |
returned by the #contents method. Here, Array is returned, |
|
2853 |
since the abstract Stream-class has no idea of the underlying |
|
2854 |
collection class. |
|
2855 |
It is redefined in some subclasses - for example, to return String." |
|
2856 |
||
2857 |
^ Array |
|
2858 |
||
2859 |
"Modified: 15.5.1996 / 17:53:31 / cg" |
|
2860 |
! |
|
2861 |
||
15719 | 2862 |
current |
2863 |
"for compatibility with Transcript - allow Transcript current, |
|
2864 |
even if redirected to the standardError" |
|
2865 |
||
2866 |
self == Transcript ifTrue:[ |
|
2867 |
^ self |
|
2868 |
]. |
|
2869 |
"/ this will raise an DNU error, usually. |
|
2870 |
^ super current |
|
2871 |
||
2872 |
"Modified (comment): / 29-08-2013 / 11:09:21 / cg" |
|
2873 |
! |
|
2874 |
||
15590 | 2875 |
inputStream |
2876 |
"return the receiver. |
|
2877 |
for compatibility with filtering streams" |
|
2878 |
||
2879 |
self isReadable ifFalse:[ ^ nil ]. |
|
2880 |
^ self |
|
2881 |
! |
|
2882 |
||
611 | 2883 |
isBinary |
1403 | 2884 |
"return true, if in binary mode. Always returns false here, |
2885 |
to make internalStreams protocol compatible with externalStreams." |
|
611 | 2886 |
|
7503 | 2887 |
^ self contentsSpecies == ByteArray |
1403 | 2888 |
|
2889 |
"Modified: 15.5.1996 / 17:53:51 / cg" |
|
611 | 2890 |
! |
2891 |
||
11948 | 2892 |
isOpen |
2893 |
"for compatibility with externalStream: |
|
2894 |
return true, if this stream is open." |
|
2895 |
||
2896 |
^ true |
|
2897 |
! |
|
2898 |
||
611 | 2899 |
isReadable |
19438 | 2900 |
"return true, if reading is supported by the receiver. |
1403 | 2901 |
This has to be redefined in concrete subclasses." |
611 | 2902 |
|
2903 |
^ self subclassResponsibility |
|
1403 | 2904 |
|
2905 |
"Modified: 15.5.1996 / 17:54:31 / cg" |
|
611 | 2906 |
! |
2907 |
||
2908 |
isWritable |
|
19438 | 2909 |
"return true, if writing is supported by the receiver. |
1403 | 2910 |
This has to be redefined in concrete subclasses." |
611 | 2911 |
|
2912 |
^ self subclassResponsibility |
|
1403 | 2913 |
|
2914 |
"Modified: 15.5.1996 / 17:54:54 / cg" |
|
611 | 2915 |
! |
2916 |
||
2917 |
lineLength |
|
1403 | 2918 |
"return the lineLength which `looks good' when pretty printed |
2919 |
text is sent to this stream. |
|
2920 |
This has NO meaning whatsoever to regular streams; |
|
2921 |
however, it may be used as a layout hint for prettyprinting functions |
|
2922 |
- for compatibility with TextCollectors, which returns its views actual |
|
2923 |
line length, and allows the prettyprinter to wrap at that position." |
|
611 | 2924 |
|
2925 |
^ 80 |
|
1403 | 2926 |
|
2927 |
"Modified: 15.5.1996 / 17:57:01 / cg" |
|
3493
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2928 |
! |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2929 |
|
5395 | 2930 |
lineNumber |
15591 | 2931 |
"return the current lineNumber if known |
2932 |
(for compatibility with LineNumberReadStream)" |
|
5395 | 2933 |
|
2934 |
^ nil |
|
2935 |
! |
|
2936 |
||
20102 | 2937 |
numAvailableForRead |
20242 | 2938 |
"answer the number of bytes available for reading" |
2939 |
||
20102 | 2940 |
^ self size |
2941 |
! |
|
2942 |
||
8645 | 2943 |
numberOfTerminalCols |
2944 |
^ self lineLength |
|
2945 |
! |
|
2946 |
||
2947 |
numberOfTerminalLines |
|
2948 |
^ 24 |
|
2949 |
! |
|
2950 |
||
15590 | 2951 |
outputStream |
2952 |
"return the receiver. |
|
2953 |
for compatibility with filtering streams" |
|
2954 |
||
2955 |
self isWritable ifFalse:[ ^ nil ]. |
|
2956 |
^ self |
|
2957 |
! |
|
2958 |
||
3493
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2959 |
pageFormat |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2960 |
"return the pageFormat - nil here. |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2961 |
This has NO meaning whatsoever to regular streams; |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2962 |
however, it has been added for protocol compatibility with printerStreams" |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2963 |
|
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2964 |
^ nil |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2965 |
|
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2966 |
"Modified: / 15.5.1996 / 17:57:01 / cg" |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
2967 |
"Created: / 29.5.1998 / 16:57:48 / cg" |
8645 | 2968 |
! |
2969 |
||
14303 | 2970 |
size |
2971 |
"return the number of elements in the streamed collection." |
|
2972 |
||
2973 |
self subclassResponsibility |
|
2974 |
||
2975 |
"Created: / 05-08-2012 / 18:38:12 / cg" |
|
2976 |
! |
|
2977 |
||
8645 | 2978 |
terminalType |
2979 |
^ 'dump' |
|
611 | 2980 |
! ! |
2981 |
||
62 | 2982 |
!Stream methodsFor:'reading'! |
1 | 2983 |
|
2984 |
next |
|
2985 |
"return the next element of the stream |
|
2986 |
- we do not know here how to do it, it must be redefined in subclass" |
|
2987 |
||
2988 |
^ self subclassResponsibility |
|
2989 |
! |
|
2990 |
||
2991 |
next:count |
|
1403 | 2992 |
"return the next count elements of the stream as aCollection, |
2993 |
which depends on the streams type - (see #contentsSpecies)." |
|
1 | 2994 |
|
20242 | 2995 |
|answerStream |
285 | 2996 |
cnt "{ Class: SmallInteger }" | |
1 | 2997 |
|
285 | 2998 |
cnt := count. |
22417 | 2999 |
answerStream := self contentsSpecies writeStream:cnt. |
12426 | 3000 |
1 to:cnt do:[:index | |next| |
3001 |
next := self next. |
|
3002 |
next isNil ifTrue:[ |
|
3003 |
"if next did not raise EndOfStreamError, we have to do it" |
|
3004 |
EndOfStreamError raiseRequestFrom:self. |
|
12623 | 3005 |
"if you proceed, you get what we have already collected" |
3006 |
^ answerStream contents |
|
12426 | 3007 |
]. |
3008 |
answerStream nextPut:next. |
|
1 | 3009 |
]. |
329 | 3010 |
^ answerStream contents |
1 | 3011 |
|
275 | 3012 |
" |
3013 |
(ReadStream on:#(1 2 3 4 5)) next:3 |
|
3014 |
(ReadStream on:'hello') next:3 |
|
3015 |
" |
|
1403 | 3016 |
|
22417 | 3017 |
"Modified: / 15-05-1996 / 17:57:58 / cg" |
3018 |
"Modified: / 10-01-2018 / 21:41:41 / stefan" |
|
1 | 3019 |
! |
3020 |
||
7467 | 3021 |
next:count into:aWriteStream |
3022 |
"put the next count elements of the stream into aWriteStream" |
|
3023 |
||
3024 |
|cnt "{ Class: SmallInteger }" | |
|
3025 |
||
3026 |
cnt := count. |
|
12426 | 3027 |
1 to:cnt do:[:index | |next| |
3028 |
next := self next. |
|
3029 |
next isNil ifTrue:[ |
|
3030 |
"if next did not raise EndOfStreamError, we have to do it" |
|
3031 |
EndOfStreamError raiseRequestFrom:self. |
|
3032 |
]. |
|
3033 |
aWriteStream nextPut:next. |
|
7467 | 3034 |
]. |
3035 |
||
3036 |
" |
|
3037 |
|writeStream| |
|
3038 |
writeStream := #() writeStream. |
|
3039 |
#(1 2 3 4 5) readStream next:3 into:writeStream. |
|
3040 |
writeStream contents. |
|
3041 |
||
3042 |
|writeStream| |
|
3043 |
writeStream := '' writeStream. |
|
3044 |
'hello' readStream next:3 into:writeStream. |
|
3045 |
writeStream contents. |
|
3046 |
" |
|
3047 |
||
3048 |
"Modified: 15.5.1996 / 17:57:58 / cg" |
|
3049 |
! |
|
3050 |
||
17610 | 3051 |
next:numObjects into:aCollection startingAt:initialIndex |
3052 |
"return the next numObjects from the stream." |
|
3053 |
||
3054 |
|n "{Class: SmallInteger }"| |
|
3055 |
||
3056 |
n := 0. |
|
3057 |
||
3058 |
[n ~~ numObjects] whileTrue:[ |
|
3059 |
self atEnd ifTrue:[ |
|
3060 |
^ aCollection copyFrom:1 to:initialIndex+n-1. |
|
3061 |
]. |
|
3062 |
aCollection at:(initialIndex + n) put:self next. |
|
3063 |
n := n + 1. |
|
3064 |
]. |
|
3065 |
^ aCollection. |
|
3066 |
||
3067 |
" |
|
3068 |
|s n buffer| |
|
3069 |
||
3070 |
buffer := Array new:10. |
|
3071 |
||
3072 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
3073 |
s next:3. |
|
3074 |
n := s next:9 into:buffer startingAt:2. |
|
3075 |
Transcript showCR:('n = %1; buffer = %2' bindWith:n with:buffer) |
|
3076 |
" |
|
3077 |
||
3078 |
"Modified: 22.4.1997 / 10:43:08 / cg" |
|
3079 |
! |
|
3080 |
||
285 | 3081 |
nextAvailable:count |
1403 | 3082 |
"return the next count elements of the stream as aCollection. |
285 | 3083 |
If the stream reaches the end before count elements have been read, |
1403 | 3084 |
return what is available. (i.e. a shorter collection). |
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
3085 |
The type of collection is specified in #contentsSpecies." |
285 | 3086 |
|
345 | 3087 |
|answerStream |
285 | 3088 |
cnt "{ Class: SmallInteger }"| |
3089 |
||
3090 |
cnt := count. |
|
22417 | 3091 |
answerStream := self contentsSpecies writeStream:cnt. |
285 | 3092 |
1 to:cnt do:[:index | |
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3093 |
self atEnd ifTrue:[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3094 |
^ answerStream contents |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3095 |
]. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3096 |
answerStream nextPut:(self next) |
285 | 3097 |
]. |
329 | 3098 |
^ answerStream contents |
285 | 3099 |
|
3100 |
" |
|
20242 | 3101 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
3102 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
285 | 3103 |
(ReadStream on:'hello') nextAvailable:3 |
20242 | 3104 |
(ReadStream on:'hello') nextAvailable:10 |
285 | 3105 |
" |
1403 | 3106 |
|
22417 | 3107 |
"Modified: / 16-06-1998 / 15:52:41 / cg" |
3108 |
"Modified: / 10-01-2018 / 18:34:55 / stefan" |
|
285 | 3109 |
! |
3110 |
||
17610 | 3111 |
nextAvailable:numObjects into:aCollection startingAt:initialIndex |
3112 |
"return the next numObjects from the stream." |
|
3113 |
||
3114 |
|n "{Class: SmallInteger }"| |
|
3115 |
||
3116 |
n := 0. |
|
3117 |
||
3118 |
[n ~= numObjects and:[self atEnd not]] whileTrue:[ |
|
3119 |
aCollection at:(initialIndex + n) put:self next. |
|
3120 |
n := n + 1. |
|
3121 |
]. |
|
3122 |
^ n. |
|
3123 |
! |
|
3124 |
||
1 | 3125 |
nextMatchFor:anObject |
62 | 3126 |
"read an element from the receiver, return true if it was equal to |
1403 | 3127 |
the argument, anObject; false otherwise." |
62 | 3128 |
|
3129 |
^ (self next = anObject) |
|
3130 |
||
3131 |
" |
|
3132 |
|s| |
|
3133 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
3134 |
s nextMatchFor:2 |
|
3135 |
" |
|
3136 |
" |
|
3137 |
|s| |
|
3138 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
3139 |
s nextMatchFor:2. |
|
3140 |
s nextMatchFor:2 |
|
3141 |
" |
|
1403 | 3142 |
|
3143 |
"Modified: 15.5.1996 / 17:58:57 / cg" |
|
62 | 3144 |
! |
3145 |
||
6862 | 3146 |
nextOrNil |
3147 |
"like #next, this returns the next element, if available. |
|
7118 | 3148 |
If nothing is available, this does never raise a read-beyond end signal. |
6862 | 3149 |
Instead, nil is returned immediately." |
3150 |
||
3151 |
self atEnd ifTrue:[^ nil]. |
|
3152 |
^ self next |
|
3153 |
! |
|
3154 |
||
20242 | 3155 |
skip:numberToSkip |
7242 | 3156 |
"skip numberToSkip objects, return the receiver" |
345 | 3157 |
|
16208 | 3158 |
"don't know how to unread ..." |
7242 | 3159 |
numberToSkip < 0 ifTrue:[ |
8309 | 3160 |
PositionError raiseRequest. |
7242 | 3161 |
^ self |
62 | 3162 |
]. |
16208 | 3163 |
numberToSkip timesRepeat:[self next] |
62 | 3164 |
|
3165 |
" |
|
3166 |
|s| |
|
3167 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
3168 |
s skip:4. |
|
3169 |
s next |
|
3170 |
" |
|
4467 | 3171 |
|
3172 |
"Modified: / 30.7.1999 / 12:12:10 / cg" |
|
62 | 3173 |
! |
3174 |
||
3175 |
skipFor:anObject |
|
20242 | 3176 |
"skip all objects up-to and including anObject; |
15639 | 3177 |
read and return the element after anObject." |
62 | 3178 |
|
3179 |
(self skipThrough:anObject) notNil ifTrue:[ |
|
15639 | 3180 |
^ self next |
62 | 3181 |
]. |
3182 |
^ nil |
|
3183 |
||
3184 |
" |
|
15639 | 3185 |
|s next rest| |
62 | 3186 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
20242 | 3187 |
next := s skipFor:4. |
3188 |
rest := s upToEnd. |
|
6010 | 3189 |
" |
3190 |
" |
|
15639 | 3191 |
|s next rest| |
6010 | 3192 |
s := ReadStream on:'12345678'. |
15639 | 3193 |
next := s skipFor:$4. |
3194 |
rest := s upToEnd. |
|
62 | 3195 |
" |
1403 | 3196 |
|
3197 |
"Modified: 15.5.1996 / 17:59:23 / cg" |
|
62 | 3198 |
! |
3199 |
||
10360
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3200 |
skipLine |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3201 |
"read the next line (characters up to newline) skip only; |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3202 |
return nil if EOF reached, self otherwise. |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3203 |
Not allowed in binary mode." |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3204 |
|
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3205 |
^ self skipThrough:Character cr |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3206 |
! |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
3207 |
|
62 | 3208 |
skipThrough:anObject |
20242 | 3209 |
"skip all objects up-to and including anObject. |
3210 |
Return the receiver if skip was successful, |
|
6010 | 3211 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
62 | 3212 |
The next read operation will return the element after anObject." |
1 | 3213 |
|
3214 |
|nextElement| |
|
3215 |
||
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3216 |
[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3217 |
nextElement := self nextOrNil. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3218 |
(nextElement isNil and:[self atEnd]) ifTrue:[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3219 |
^ nil. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3220 |
]. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3221 |
nextElement = anObject |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3222 |
] whileFalse. |
2 | 3223 |
|
62 | 3224 |
" |
3225 |
|s| |
|
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
3226 |
s := ReadStream on:#(1 nil 2 3 4 5 6 7 8). |
62 | 3227 |
s skipThrough:4. |
3228 |
s next |
|
3229 |
" |
|
6010 | 3230 |
" |
3231 |
|s| |
|
3232 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
3233 |
s skipThrough:4. |
|
3234 |
s skipThrough:4. |
|
20242 | 3235 |
s next |
6010 | 3236 |
" |
3237 |
" |
|
3238 |
|s| |
|
3239 |
s := ReadStream on:'12345678'. |
|
3240 |
s skipThrough:$4. |
|
20242 | 3241 |
s next |
6010 | 3242 |
" |
3243 |
" |
|
3244 |
|s| |
|
3245 |
s := ReadStream on:'12345678'. |
|
3246 |
s skipThrough:$4. |
|
3247 |
s skipThrough:$4. |
|
20242 | 3248 |
s next |
6010 | 3249 |
" |
3250 |
" |
|
3251 |
|s| |
|
3252 |
s := ReadStream on:'12345678'. |
|
3253 |
s skipThrough:$4. |
|
3254 |
s skipThrough:$4. |
|
20242 | 3255 |
s atEnd |
6010 | 3256 |
" |
77 | 3257 |
! |
3258 |
||
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3259 |
skipThroughAll:aCollection |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3260 |
"skip for and through the sequence given by the argument, aCollection; |
20242 | 3261 |
return nil if not found, the receiver otherwise. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3262 |
On a successful match, the next read will return elements after aCollection; |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3263 |
if no match was found, the receiver will be positioned at the end." |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3264 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3265 |
|buffer l first idx| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3266 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3267 |
l := aCollection size. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3268 |
first := aCollection at:1. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3269 |
[self atEnd] whileFalse:[ |
20242 | 3270 |
buffer isNil ifTrue:[ |
3271 |
buffer := self nextAvailable:l. |
|
3272 |
]. |
|
3273 |
buffer = aCollection ifTrue:[ |
|
3274 |
^ self |
|
3275 |
]. |
|
3276 |
idx := buffer indexOf:first startingAt:2. |
|
3277 |
idx == 0 ifTrue:[ |
|
3278 |
buffer := nil |
|
3279 |
] ifFalse:[ |
|
3280 |
buffer := (buffer copyFrom:idx) , (self nextAvailable:(idx - 1)) |
|
3281 |
] |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3282 |
]. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3283 |
^ nil |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3284 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3285 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3286 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3287 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3288 |
s skipThroughAll:'901'. |
20242 | 3289 |
s upToEnd |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3290 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3291 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3292 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3293 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3294 |
s skipThroughAll:'1234'. |
20242 | 3295 |
s upToEnd |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3296 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3297 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3298 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3299 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3300 |
s skipThroughAll:'999'. |
20242 | 3301 |
s atEnd |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3302 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3303 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3304 |
"Created: 11.1.1997 / 18:55:13 / cg" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3305 |
"Modified: 11.1.1997 / 19:09:06 / cg" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3306 |
! |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
3307 |
|
611 | 3308 |
through:anObject |
3309 |
"read a collection of all objects up-to anObject and return these |
|
20242 | 3310 |
elements, including anObject. |
611 | 3311 |
The next read operation will return the element after anObject. |
1409 | 3312 |
If anObject is not encountered, all elements up to the end are read |
3313 |
and returned. |
|
611 | 3314 |
Compare this with #upTo: which also reads up to some object |
3315 |
and also positions behind it, but does not include it in the returned |
|
3316 |
value." |
|
3317 |
||
3318 |
|answerStream element| |
|
3319 |
||
22417 | 3320 |
answerStream := self contentsSpecies writeStream. |
611 | 3321 |
[self atEnd] whileFalse:[ |
20242 | 3322 |
element := self next. |
3323 |
answerStream nextPut:element. |
|
3324 |
(element = anObject) ifTrue: [ |
|
3325 |
^ answerStream contents |
|
3326 |
] |
|
611 | 3327 |
]. |
3328 |
^ answerStream contents |
|
3329 |
||
3330 |
" |
|
3331 |
|s| |
|
3332 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
20242 | 3333 |
Transcript showCR:(s through:4). |
1422 | 3334 |
Transcript showCR:s next |
1409 | 3335 |
|
3336 |
|s| |
|
3337 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
20242 | 3338 |
Transcript showCR:(s through:9). |
1422 | 3339 |
Transcript showCR:s next |
1409 | 3340 |
|
611 | 3341 |
|s| |
3342 |
s := ReadStream on:'hello world'. |
|
1422 | 3343 |
Transcript showCR:(s through:Character space). |
3344 |
Transcript showCR:(s upToEnd) |
|
611 | 3345 |
" |
1409 | 3346 |
|
22417 | 3347 |
"Modified: / 17-05-1996 / 08:51:40 / cg" |
3348 |
"Modified: / 10-01-2018 / 18:30:17 / stefan" |
|
611 | 3349 |
! |
3350 |
||
1548 | 3351 |
throughAll:aCollection |
20242 | 3352 |
"read & return a collection of all objects up-to and including |
1548 | 3353 |
a subcollection given by aCollection. |
3354 |
(i.e. read until a ``substring'' is encountered.) |
|
3355 |
The next read operation will return the element after aCollection. |
|
3356 |
If aCollection is not encountered, all elements up to the end are read |
|
3357 |
and returned." |
|
3358 |
||
21137 | 3359 |
|answerStream element last| |
1548 | 3360 |
|
3361 |
last := aCollection last. |
|
22417 | 3362 |
answerStream := self contentsSpecies writeStream. |
21137 | 3363 |
[(element := self nextOrNil) isNil and:[self atEnd]] whileFalse:[ |
20242 | 3364 |
answerStream nextPut:element. |
22417 | 3365 |
element = last ifTrue:[ |
21137 | 3366 |
(answerStream endsWith:aCollection) ifTrue:[ |
3367 |
^ answerStream contents |
|
20242 | 3368 |
] |
3369 |
]. |
|
1548 | 3370 |
]. |
3371 |
^ answerStream contents |
|
3372 |
||
3373 |
" |
|
3374 |
|s| |
|
3375 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
20242 | 3376 |
Transcript showCR:(s throughAll:#(4 4 4)). |
1548 | 3377 |
Transcript showCR:s next |
3378 |
||
3379 |
|s| |
|
3380 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
20242 | 3381 |
Transcript showCR:(s throughAll:#(4 5 6)). |
1548 | 3382 |
Transcript showCR:s next |
3383 |
||
3384 |
|s| |
|
3385 |
s := ReadStream on:'hello world, this is some text'. |
|
20242 | 3386 |
Transcript showCR:(s throughAll:'world'). |
3387 |
Transcript showCR:(s throughAll:'some'). |
|
1548 | 3388 |
Transcript showCR:s upToEnd. |
3389 |
" |
|
3390 |
||
22417 | 3391 |
"Modified: / 15-07-1996 / 09:08:07 / cg" |
3392 |
"Modified: / 10-01-2018 / 23:46:08 / stefan" |
|
1548 | 3393 |
! |
3394 |
||
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3395 |
throughAny:aCollection |
20242 | 3396 |
"read & return a collection of all objects up-to and including |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3397 |
an element contained in aCollection. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3398 |
(i.e. read until any from aCollection is encountered.) |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3399 |
If no such character is encountered, all elements up to the end are read |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3400 |
and returned." |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3401 |
|
9070 | 3402 |
|answerStream element| |
3403 |
||
22417 | 3404 |
answerStream := self contentsSpecies writeStream. |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3405 |
[self atEnd] whileFalse:[ |
9070 | 3406 |
element := self next. |
3407 |
answerStream nextPut:element. |
|
3408 |
(aCollection includes:element) ifTrue:[ |
|
3409 |
^ answerStream contents |
|
3410 |
]. |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3411 |
]. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3412 |
^ answerStream contents |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3413 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3414 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3415 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3416 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
20242 | 3417 |
Transcript showCR:(s throughAny:#(3 4 5)). |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3418 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3419 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3420 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3421 |
s := ReadStream on:'hello world, this is some text'. |
20242 | 3422 |
Transcript showCR:(s throughAny:'wt'). |
3423 |
Transcript showCR:(s throughAny:'wt'). |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3424 |
Transcript showCR:s upToEnd. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3425 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3426 |
|
22417 | 3427 |
"Modified: / 11-01-1998 / 15:28:04 / cg" |
3428 |
"Modified: / 10-01-2018 / 18:30:25 / stefan" |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3429 |
! |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3430 |
|
15639 | 3431 |
throughElementForWhich:aBlock |
20198 | 3432 |
"read elements until aBlock returns true for an element. |
15639 | 3433 |
Return the collected elements including that element. |
20198 | 3434 |
Leave the stream positioned for the next read to return the element after that one." |
15639 | 3435 |
|
3436 |
|answerStream element| |
|
3437 |
||
22417 | 3438 |
answerStream := self contentsSpecies writeStream. |
15639 | 3439 |
|
3440 |
[self atEnd] whileFalse:[ |
|
3441 |
element := self next. |
|
3442 |
answerStream nextPut:element. |
|
3443 |
(aBlock value:element) ifTrue: [ |
|
3444 |
^ answerStream contents |
|
3445 |
] |
|
3446 |
]. |
|
3447 |
^ answerStream contents |
|
3448 |
||
3449 |
" |
|
3450 |
#(1 2 3 4 5 6 7 8 9 10) readStream |
|
3451 |
throughElementForWhich:[:el | el > 5]; |
|
3452 |
" |
|
22417 | 3453 |
|
3454 |
"Modified: / 10-01-2018 / 18:30:30 / stefan" |
|
15639 | 3455 |
! |
3456 |
||
427 | 3457 |
upTo:anObject |
3458 |
"read a collection of all objects up-to anObject and return these |
|
20242 | 3459 |
elements, but excluding anObject. |
427 | 3460 |
The next read operation will return the element after anObject. |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3461 |
(i.e. anObject is considered a separator, which is skipped) |
3172
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
3462 |
Similar to #through:, but the matching object is not included in the |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3463 |
returned collection. |
1409 | 3464 |
If anObject is not encountered, all elements up to the end are read |
3465 |
and returned. |
|
427 | 3466 |
Compare this with #through: which also reads up to some object |
3467 |
and also positions behind it, but DOES include it in the returned |
|
3468 |
value." |
|
3469 |
||
11659 | 3470 |
|answerStream| |
427 | 3471 |
|
22417 | 3472 |
answerStream := self contentsSpecies writeStream. |
11659 | 3473 |
self upTo:anObject into:answerStream. |
427 | 3474 |
^ answerStream contents |
3475 |
||
3476 |
" |
|
3477 |
|s| |
|
3478 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
20242 | 3479 |
Transcript showCR:(s upTo:4). |
1422 | 3480 |
Transcript showCR:s next |
427 | 3481 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3482 |
compare the above to: |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3483 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3484 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
20242 | 3485 |
Transcript showCR:(s through:4). |
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3486 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
3487 |
|
427 | 3488 |
|s| |
1409 | 3489 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
20242 | 3490 |
Transcript showCR:(s upTo:9). |
1422 | 3491 |
Transcript showCR:s next |
1409 | 3492 |
|
3493 |
|s| |
|
427 | 3494 |
s := ReadStream on:'hello world'. |
1422 | 3495 |
Transcript showCR:(s upTo:Character space). |
3496 |
Transcript showCR:(s upToEnd) |
|
427 | 3497 |
|
20242 | 3498 |
(ReadStream on:'12345678905') upTo:$5; next |
3499 |
||
3500 |
(ReadStream on:'12345678905') upTo:$5; upTo:$5 |
|
3501 |
||
3502 |
(ReadStream on:'123456') upTo:$7 |
|
3503 |
||
3504 |
(ReadStream on:#(1 2 3 4 5 6)) upTo:4 |
|
427 | 3505 |
|
3506 |
(ReadStream on:'line 1 |
|
20242 | 3507 |
line 2') upTo:Character cr |
3508 |
||
3509 |
'Makefile' asFilename readStream upTo:Character cr;upTo:Character cr |
|
427 | 3510 |
" |
1409 | 3511 |
|
22417 | 3512 |
"Modified: / 12-01-1998 / 21:58:38 / cg" |
3513 |
"Modified: / 10-01-2018 / 18:30:36 / stefan" |
|
3172
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
3514 |
! |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
3515 |
|
11659 | 3516 |
upTo:anObject into:aStream |
3517 |
"read a collection of all objects up-to anObject and append these |
|
3518 |
elements to aStream, but excluding anObject. |
|
3519 |
The next read operation will return the element after anObject. |
|
3520 |
(i.e. anObject is considered a separator, which is skipped) |
|
3521 |
Similar to #through:, but the matching object is not included in the returned collection. |
|
3522 |
If anObject is not encountered, all elements up to the end are read and returned. |
|
3523 |
Compare this with #through: which also reads up to some object |
|
3524 |
and also positions behind it, but DOES include it in the returned value." |
|
3525 |
||
3526 |
|element| |
|
3527 |
||
3528 |
[ |
|
3529 |
element := self nextOrNil. |
|
3530 |
((element isNil and:[self atEnd]) or:[element = anObject]) ifTrue:[ |
|
19384 | 3531 |
^ self |
11659 | 3532 |
]. |
19384 | 3533 |
aStream nextPut:element. |
3534 |
] loop. |
|
11659 | 3535 |
! |
3536 |
||
3586 | 3537 |
upToAllExcluding:aCollection |
3538 |
"read a collection of all objects up-to a element which is contained in |
|
3539 |
aCollection and return these elements, but excluding the matching one. |
|
3540 |
The next read operation will return the element after aCollection. |
|
3541 |
If no such element is encountered, all elements up to the end are read |
|
3542 |
and returned. |
|
6494 | 3543 |
See also #throughAll: which also reads up to some object |
3586 | 3544 |
and also positions behind it, but DOES include it in the returned |
6494 | 3545 |
value. |
3546 |
See also #upToAll:, which returns the same, but leaves the |
|
3547 |
read pointer before the matched subcollection." |
|
3586 | 3548 |
|
16197 | 3549 |
|answerStream element last| |
3586 | 3550 |
|
3551 |
last := aCollection last. |
|
16197 | 3552 |
answerStream := ReadWriteStream on:(self contentsSpecies new). |
21137 | 3553 |
[(element := self nextOrNil) isNil and:[self atEnd]] whileFalse:[ |
6494 | 3554 |
answerStream nextPut:element. |
22417 | 3555 |
element = last ifTrue:[ |
21137 | 3556 |
(answerStream endsWith:aCollection) ifTrue:[ |
16197 | 3557 |
|pos| |
3558 |
pos := answerStream position. |
|
19884 | 3559 |
answerStream reset. |
16197 | 3560 |
^ answerStream next:pos-aCollection size. |
6494 | 3561 |
] |
3562 |
]. |
|
3586 | 3563 |
]. |
3564 |
^ answerStream contents |
|
3565 |
||
3566 |
" |
|
3567 |
|s| |
|
3568 |
s := ReadStream on:'hello world world'. |
|
3569 |
Transcript show:'<'; show:(s upToAllExcluding:'wo'); showCR:'>'. |
|
3570 |
Transcript show:'<'; show:(s upToAllExcluding:'wo'); showCR:'>'. |
|
3571 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
3572 |
" |
|
3573 |
||
22417 | 3574 |
"Created: / 15-06-1998 / 19:11:31 / cg" |
3575 |
"Modified: / 10-01-2018 / 23:48:49 / stefan" |
|
3586 | 3576 |
! |
3577 |
||
77 | 3578 |
upToEnd |
3579 |
"return a collection of the elements up-to the end. |
|
1403 | 3580 |
Return an empty collection, if the stream-end is already at the end." |
77 | 3581 |
|
3582 |
|answerStream| |
|
3583 |
||
22417 | 3584 |
answerStream := self contentsSpecies writeStream. |
77 | 3585 |
[self atEnd] whileFalse:[ |
22417 | 3586 |
answerStream nextPut:self next. |
77 | 3587 |
]. |
3588 |
^ answerStream contents |
|
3589 |
||
275 | 3590 |
" |
3591 |
(ReadStream on:'1234567890') upToEnd |
|
3592 |
('123456' readStream) next; next; upToEnd |
|
20242 | 3593 |
('1 23456' readStream) upTo:Character space; upToEnd |
3594 |
('12' readStream) next; next; upToEnd |
|
275 | 3595 |
" |
1403 | 3596 |
|
22417 | 3597 |
"Modified: / 15-05-1996 / 18:00:39 / cg" |
3598 |
"Modified (format): / 10-01-2018 / 18:30:53 / stefan" |
|
611 | 3599 |
! ! |
77 | 3600 |
|
18720 | 3601 |
!Stream methodsFor:'reading-numbers'! |
3602 |
||
3603 |
nextDecimalInteger |
|
3604 |
"read and return the next integer from the receiver stream. |
|
3605 |
Leaves the stream positioned after the digits" |
|
3606 |
||
3607 |
^ Integer readFrom:self |
|
3608 |
||
3609 |
" |
|
3610 |
|s| |
|
3611 |
s := '1234a' readStream. |
|
3612 |
Transcript showCR:(s nextDecimalInteger). |
|
3613 |
s peek -> $a |
|
3614 |
" |
|
3615 |
" |
|
3616 |
|s| |
|
3617 |
s := '1234.0a' readStream. |
|
3618 |
Transcript showCR:(s nextDecimalInteger). |
|
3619 |
s peek -> $. |
|
3620 |
" |
|
3621 |
" |
|
3622 |
|s| |
|
3623 |
s := '1234.0a' readStream. |
|
3624 |
Transcript showCR:(s nextDecimalNumber). |
|
3625 |
s peek -> $a |
|
3626 |
" |
|
3627 |
! |
|
3628 |
||
3629 |
nextDecimalInteger:numChars |
|
3630 |
"read and return the next integer of numChars size from the receiver stream. |
|
3631 |
Does NOT skip separators. |
|
19396 | 3632 |
Leaves the stream positioned after the digits. |
3633 |
Raises an error, if the characters cannot be converted to an integer" |
|
18720 | 3634 |
|
3635 |
|chars| |
|
3636 |
||
3637 |
chars := self next:numChars. |
|
3638 |
^ Integer readFrom:chars |
|
3639 |
||
3640 |
" |
|
3641 |
|s| |
|
3642 |
s := '1234a' readStream. |
|
3643 |
Transcript showCR:(s nextDecimalInteger:2). |
|
3644 |
Transcript showCR:(s nextDecimalInteger). |
|
3645 |
s peek -> $a |
|
3646 |
" |
|
3647 |
! |
|
3648 |
||
3649 |
nextDecimalNumber |
|
3650 |
"read and return the next number from the receiver stream. |
|
3651 |
Leaves the stream positioned after the digits" |
|
3652 |
||
3653 |
^ Number readFrom:self |
|
3654 |
||
3655 |
" |
|
3656 |
|s| |
|
3657 |
s := '1234.0a' readStream. |
|
3658 |
Transcript showCR:(s nextDecimalNumber). |
|
3659 |
s peek -> $a |
|
3660 |
" |
|
3661 |
! |
|
3662 |
||
3663 |
nextDecimalNumber:numChars |
|
3664 |
"read and return the next number of numChars size from the receiver stream. |
|
3665 |
Does NOT skip separators. |
|
19396 | 3666 |
Leaves the stream positioned after the digits. |
3667 |
Raises an error, if the characters cannot be converted to a number" |
|
18720 | 3668 |
|
3669 |
|chars| |
|
3670 |
||
3671 |
chars := self next:numChars. |
|
3672 |
^ Integer readFrom:chars |
|
3673 |
||
3674 |
" |
|
3675 |
|s| |
|
3676 |
s := '12.34a' readStream. |
|
3677 |
Transcript showCR:(s nextDecimalNumber:4). |
|
3678 |
Transcript showCR:(s nextDecimalInteger). |
|
3679 |
s peek -> $a |
|
3680 |
" |
|
3681 |
! ! |
|
3682 |
||
6857 | 3683 |
!Stream methodsFor:'reading-strings'! |
3084 | 3684 |
|
3685 |
nextLine |
|
3686 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
3687 |
character (i.e. read a single line of text). |
|
13329 | 3688 |
If the previous-to-last character is a cr, this is also removed, |
19648 | 3689 |
so it's possible to read alien (i.e. ms-dos) text as well. |
3084 | 3690 |
Added for protocol compatibility with externalStreams." |
3691 |
||
13329 | 3692 |
|answerStream| |
3693 |
||
3462 | 3694 |
self atEnd ifTrue:[ |
8614 | 3695 |
^ self pastEndRead |
3462 | 3696 |
]. |
22417 | 3697 |
answerStream := self contentsSpecies writeStream:80. |
13329 | 3698 |
self upTo:Character cr into:answerStream. |
20102 | 3699 |
(answerStream size ~~ 0 and:[answerStream last = Character return]) ifTrue:[ |
13329 | 3700 |
answerStream backStep. |
3701 |
]. |
|
3702 |
^ answerStream contents |
|
20242 | 3703 |
|
22417 | 3704 |
"Modified: / 19-05-1998 / 17:26:25 / cg" |
3705 |
"Modified: / 10-01-2018 / 18:35:11 / stefan" |
|
3084 | 3706 |
! ! |
3707 |
||
12623 | 3708 |
|
23896 | 3709 |
!Stream methodsFor:'stream-to-stream copy'! |
3710 |
||
3711 |
copy:numberOfElementsOrNil into:outStream |
|
3712 |
"read from the receiver, and write numberOfElements elements to outStream, a WriteStream. |
|
3713 |
Return the number of elements which have been transferred. |
|
3714 |
If numberOfElementsOrNil is nil, copy until the end of myself." |
|
3715 |
||
23912 | 3716 |
^ self copy:numberOfElementsOrNil into:outStream bufferSize:(outStream bufferSizeForBulkCopy) |
23909 | 3717 |
|
3718 |
"Modified: / 13-03-2019 / 23:06:37 / Stefan Vogel" |
|
23912 | 3719 |
"Modified: / 14-03-2019 / 00:22:39 / Claus Gittinger" |
23896 | 3720 |
! |
3721 |
||
3722 |
copy:numberOfElementsOrNil into:aWriteStream bufferSize:bufferSizeArg |
|
3723 |
"read from the receiver, and write numberOfElementsOrNil elements to outStream, a WriteStream. |
|
3724 |
Return the number of elements which have been transferred. |
|
3725 |
If numberOfElementsOrNil is nil, copy until the end of myself." |
|
3726 |
||
3727 |
|bufferSpecies bufferSize elementsLeft buffer countWritten freeBuffer| |
|
3728 |
||
3729 |
countWritten := 0. |
|
3730 |
numberOfElementsOrNil isNil ifTrue:[ |
|
3731 |
"read to end..." |
|
3732 |
elementsLeft := -1. |
|
3733 |
bufferSize := bufferSizeArg. |
|
3734 |
] ifFalse:[ |
|
3735 |
elementsLeft := numberOfElementsOrNil. |
|
3736 |
bufferSize := bufferSizeArg min:numberOfElementsOrNil. |
|
3737 |
]. |
|
3738 |
||
3739 |
bufferSpecies := self contentsSpecies. |
|
3740 |
bufferSpecies == ByteArray ifTrue:[ |
|
3741 |
"an ExternalBytes buffer is faster when writing to a windows ExternalStream" |
|
3742 |
buffer:= ExternalBytes unprotectedNew:bufferSize. |
|
3743 |
freeBuffer := true. |
|
3744 |
] ifFalse:[ |
|
3745 |
buffer := bufferSpecies new:bufferSize. |
|
3746 |
freeBuffer := false. |
|
3747 |
]. |
|
3748 |
||
3749 |
"read loop: read required bytes" |
|
3750 |
[ |
|
3751 |
|readCount writeCount| |
|
3752 |
||
3753 |
readCount := self nextAvailable:bufferSize into:buffer startingAt:1. |
|
3754 |
readCount ~~ 0 ifTrue:[ |
|
3755 |
elementsLeft := elementsLeft - readCount. |
|
3756 |
writeCount := 0. |
|
3757 |
"write loop: write until all is written" |
|
3758 |
[ |
|
3759 |
|count| |
|
3760 |
||
3761 |
count := aWriteStream |
|
3762 |
nextPutAll:readCount-writeCount |
|
3763 |
from:buffer |
|
3764 |
startingAt:writeCount+1. |
|
3765 |
writeCount := writeCount + count. |
|
3766 |
writeCount < readCount ifTrue:[ |
|
3767 |
aWriteStream writeWait. |
|
3768 |
true. |
|
3769 |
] ifFalse:[ |
|
3770 |
false |
|
3771 |
]. |
|
3772 |
] whileTrue. |
|
3773 |
countWritten := countWritten + writeCount. |
|
3774 |
]. |
|
3775 |
"Note: atEnd will block if reading from an empty pipe or socket. |
|
3776 |
avoid atEnd if possible, because it reads a single byte. |
|
3777 |
If we read until end, bytesLeft is negative and will never become 0!!" |
|
3778 |
(elementsLeft == 0) or:[readCount == 0 and:[self atEnd]] |
|
3779 |
] whileFalse. |
|
3780 |
||
3781 |
freeBuffer ifTrue:[ buffer free ]. |
|
3782 |
^ countWritten. |
|
3783 |
||
3784 |
" |
|
3785 |
|s| |
|
3786 |
s := WriteStream on:(String new:100). |
|
3787 |
'/etc/passwd' asFilename readStream |
|
3788 |
copy:nil into:s bufferSize:10. |
|
3789 |
s contents |
|
3790 |
||
3791 |
|s| |
|
3792 |
s := WriteStream on:(String new:100). |
|
3793 |
'/etc/passwd' asFilename readStream |
|
3794 |
copy:100 into:s bufferSize:10. |
|
3795 |
s contents |
|
3796 |
" |
|
3797 |
||
3798 |
"Modified: / 13-03-2019 / 12:00:46 / Claus Gittinger" |
|
3799 |
"Modified (comment): / 13-03-2019 / 17:03:20 / Stefan Vogel" |
|
3800 |
! |
|
3801 |
||
3802 |
copyToEndFrom:inStream |
|
3803 |
"read from inStream, and write all elements up to the end to the receiver. |
|
3804 |
Return the number of elements which have been transferred. |
|
3805 |
Same functionality as #copyToEndInto:, but reversed arg and receiver |
|
3806 |
(useful in a cascade message of the writeStream)" |
|
3807 |
||
3808 |
^ inStream copy:nil into:self |
|
3809 |
||
3810 |
"Modified (comment): / 13-03-2019 / 17:02:19 / Stefan Vogel" |
|
3811 |
! |
|
3812 |
||
3813 |
copyToEndInto:outStream |
|
3814 |
"read from the receiver, and write all elements up to the end to outStream, a WriteStream. |
|
3815 |
Return the number of elements which have been transferred" |
|
3816 |
||
23912 | 3817 |
^ self copy:nil into:outStream bufferSize:(outStream bufferSizeForBulkCopy) |
23896 | 3818 |
|
3819 |
"/ data rate to USB2.0 stick (Win32): |
|
3820 |
"/ 120 KB/s 8Kb SingleBuffer |
|
3821 |
"/ 741 KB/s 64Kb SingleBuffer |
|
3822 |
"/ 1345 KB/s 128Kb SingleBuffer |
|
3823 |
"/ 2087 KB/s 256Kb SingleBuffer |
|
3824 |
"/ 3573 KB/s 1024Kb SingleBuffer |
|
3825 |
||
3826 |
"/|t retVal| |
|
3827 |
"/ |
|
3828 |
"/t := Time millisecondsToRun:[ |
|
3829 |
"/ retVal := self copyToEndInto:outStream bufferSize:(64*1024). |
|
3830 |
"/]. |
|
3831 |
"/ |
|
3832 |
"/Transcript showCR:('%1 KB copied in %2s (%3 KB/s)' |
|
3833 |
"/ bindWith:((retVal/1024)asFixedPoint:2) |
|
3834 |
"/ with:((t/1000)asFixedPoint:2) |
|
3835 |
"/ with:((retVal/1024/(t/1000))asFixedPoint:2)). |
|
3836 |
"/^ retVal. |
|
3837 |
"/ |
|
3838 |
||
23909 | 3839 |
"Modified: / 13-03-2019 / 23:06:44 / Stefan Vogel" |
23912 | 3840 |
"Modified: / 14-03-2019 / 00:22:44 / Claus Gittinger" |
23896 | 3841 |
! |
3842 |
||
3843 |
copyToEndInto:outStream bufferSize:bufferSize |
|
3844 |
"read from the receiver, and write all elements up to the end to outStream, aWriteStream. |
|
3845 |
Return the number of elements which have been transferred" |
|
3846 |
||
3847 |
^ self copy:nil into:outStream bufferSize:bufferSize |
|
3848 |
||
3849 |
" |
|
3850 |
'hello world' readStream copyToEndInto:'/tmp/mist' asFilename writeStream. |
|
3851 |
'hello world' readStream copyToEndInto:'' writeStream. |
|
3852 |
('/tmp/mist' asFilename readStream binary; yourself) copyToEndInto:#[] writeStream |
|
3853 |
#[1 2 3 4 5 6 7] readStream copyToEndInto:'/tmp/mist' asFilename writeStream binary; yourself. |
|
3854 |
||
3855 |
|s| |
|
3856 |
s := #() writeStream. |
|
3857 |
#(1 2 3 a 'b' 6.4 true) readStream next; copyToEndInto:s. s inspect. |
|
3858 |
" |
|
3859 |
||
3860 |
"Modified: / 13-03-2019 / 11:54:17 / Claus Gittinger" |
|
3861 |
"Modified (comment): / 13-03-2019 / 17:02:51 / Stefan Vogel" |
|
3862 |
! ! |
|
3863 |
||
611 | 3864 |
!Stream methodsFor:'testing'! |
77 | 3865 |
|
611 | 3866 |
atEnd |
3867 |
"return true if the end of the stream has been reached; |
|
3868 |
- we do not know here how to do it, it must be redefined in subclass" |
|
77 | 3869 |
|
611 | 3870 |
^ self subclassResponsibility |
9294 | 3871 |
! |
3872 |
||
3873 |
isEmpty |
|
3874 |
"return true, if the contents of the stream is empty" |
|
3875 |
||
3876 |
^ self subclassResponsibility |
|
3877 |
! |
|
3878 |
||
14092 | 3879 |
isEmptyOrNil |
3880 |
"return true, if the contents of the stream is empty |
|
3881 |
(we already know, that we are not nil)" |
|
3882 |
||
3883 |
^ self isEmpty |
|
3884 |
! |
|
3885 |
||
15048 | 3886 |
isEncodedStream |
18394 | 3887 |
"true, iff this is an encoder/decoder stream" |
3888 |
||
15048 | 3889 |
^ false |
3890 |
! |
|
3891 |
||
16085 | 3892 |
isLineNumberReadStream |
18394 | 3893 |
"true, iff this is a lineNumbering stream" |
3894 |
||
16085 | 3895 |
^ false |
3896 |
! |
|
3897 |
||
15048 | 3898 |
isPositionable |
3899 |
"return true, if the stream supports positioning (some do not). |
|
3900 |
Since this is an abstract class, false is returned here - just to make certain." |
|
3901 |
||
3902 |
^ false |
|
3903 |
||
3904 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
3905 |
! |
|
3906 |
||
3907 |
isPrinterStream |
|
3908 |
"return true, if this is a printerStream. |
|
3909 |
Since this is an abstract class, false is returned here." |
|
3910 |
||
3911 |
^ false |
|
3912 |
||
3913 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
3914 |
"Created: 3.6.1996 / 12:05:35 / cg" |
|
3915 |
! |
|
3916 |
||
3917 |
isStream |
|
3918 |
"return true, if the receiver is some kind of Stream. Always return true here." |
|
3919 |
||
3920 |
^ true |
|
3921 |
||
3922 |
"Modified: 15.5.1996 / 17:54:48 / cg" |
|
3923 |
! |
|
3924 |
||
3925 |
isTerminalStream |
|
18394 | 3926 |
"true, iff this is a terminal emulator stream" |
3927 |
||
15048 | 3928 |
^ false |
3929 |
! |
|
3930 |
||
15719 | 3931 |
isTextCollector |
18394 | 3932 |
"true, iff this is a text collector emulating a stream" |
3933 |
||
15719 | 3934 |
^ false |
3935 |
||
3936 |
" |
|
3937 |
Transcript isTextCollector |
|
3938 |
" |
|
3939 |
||
3940 |
"Created: / 29-08-2013 / 11:33:10 / cg" |
|
3941 |
! |
|
3942 |
||
9294 | 3943 |
notEmpty |
3944 |
"return true, if the contents of the stream is not empty" |
|
3945 |
||
3946 |
^ self isEmpty not |
|
14092 | 3947 |
! |
3948 |
||
3949 |
notEmptyOrNil |
|
3950 |
"return true, if the contents of the stream is empty |
|
3951 |
(we already know, that we are not nil)" |
|
3952 |
||
3953 |
^ self isEmpty not |
|
1 | 3954 |
! ! |
3955 |
||
11750 | 3956 |
!Stream methodsFor:'visiting'! |
3957 |
||
3958 |
acceptVisitor:aVisitor with:aParameter |
|
16720 | 3959 |
"dispatch for visitor pattern; send #visitStream:with: to aVisitor." |
3960 |
||
11750 | 3961 |
^ aVisitor visitStream:self with:aParameter |
3962 |
! ! |
|
3963 |
||
12399 | 3964 |
!Stream methodsFor:'waiting for I/O'! |
3965 |
||
3966 |
readWait |
|
3967 |
"suspend the current process, until the receiver |
|
3968 |
becomes ready for reading. If data is already available, |
|
19221 | 3969 |
return immediately. |
12399 | 3970 |
The other threads are not affected by the wait." |
3971 |
||
3972 |
^ self readWaitWithTimeoutMs:nil |
|
3973 |
! |
|
3974 |
||
12401 | 3975 |
readWaitTimeoutMs:timeout |
3976 |
"ST-80 compatibility" |
|
3977 |
^ self readWaitWithTimeoutMs:timeout |
|
3978 |
! |
|
3979 |
||
18328 | 3980 |
readWaitWithTimeout:secondsOrTimeDurationOrNil |
12399 | 3981 |
"suspend the current process, until the receiver |
3982 |
becomes ready for reading or a timeout (in seconds) expired. |
|
3983 |
If data is already available, return immediate. |
|
3984 |
With nil seconds, wait forever. |
|
20254 | 3985 |
Return true if a timeout occurred (i.e. false, if data is available). |
12399 | 3986 |
The other threads are not affected by the wait." |
3987 |
||
3988 |
|ms| |
|
3989 |
||
18328 | 3990 |
secondsOrTimeDurationOrNil notNil ifTrue:[ |
22494 | 3991 |
secondsOrTimeDurationOrNil isTimeDuration ifTrue:[ |
3992 |
ms := secondsOrTimeDurationOrNil getMilliseconds. |
|
16402 | 3993 |
] ifFalse:[ |
22494 | 3994 |
ms := (secondsOrTimeDurationOrNil * 1000) rounded. |
16402 | 3995 |
] |
12399 | 3996 |
]. |
3997 |
^ self readWaitWithTimeoutMs:ms |
|
22494 | 3998 |
|
3999 |
"Modified: / 19-01-2018 / 19:18:26 / stefan" |
|
12399 | 4000 |
! |
4001 |
||
4002 |
readWaitWithTimeoutMs:millis |
|
4003 |
"suspend the current process, until the receiver |
|
4004 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
4005 |
If data is already available, return immediate. |
|
4006 |
With nil millis, wait forever. |
|
20254 | 4007 |
Return true if a timeout occurred (i.e. false, if data is available). |
12399 | 4008 |
The other threads are not affected by the wait." |
4009 |
||
4010 |
^ false "/ never have to wait |
|
4011 |
! |
|
4012 |
||
12401 | 4013 |
readWriteWait |
4014 |
"suspend the current process, until the receiver |
|
4015 |
becomes ready for writing or reading. |
|
4016 |
Return immediate if the receiver is already ready. |
|
4017 |
The other threads are not affected by the wait." |
|
4018 |
||
4019 |
self readWriteWaitWithTimeoutMs:nil |
|
4020 |
! |
|
4021 |
||
4022 |
readWriteWaitWithTimeoutMs:millis |
|
4023 |
^ false "/ never have to wait |
|
4024 |
! |
|
4025 |
||
12399 | 4026 |
writeWait |
12401 | 4027 |
"suspend the current process, until the receiver |
4028 |
becomes ready for writing. |
|
4029 |
Return immediate if the receiver is already ready. |
|
4030 |
The other threads are not affected by the wait." |
|
4031 |
||
4032 |
self writeWaitWithTimeoutMs:nil |
|
4033 |
! |
|
4034 |
||
4035 |
writeWaitTimeoutMs:timeout |
|
4036 |
"ST-80 compatibility" |
|
4037 |
^ self writeWaitWithTimeoutMs:timeout |
|
4038 |
! |
|
4039 |
||
22494 | 4040 |
writeWaitWithTimeout:secondsOrTimeDurationOrNil |
12401 | 4041 |
"suspend the current process, until the receiver |
4042 |
becomes ready for writing or a timeout (in seconds) expired. |
|
20254 | 4043 |
Return true if a timeout occurred (i.e. false, if data is available). |
12401 | 4044 |
Return immediate if the receiver is already ready. |
4045 |
The other threads are not affected by the wait." |
|
4046 |
||
4047 |
|ms| |
|
4048 |
||
22494 | 4049 |
secondsOrTimeDurationOrNil notNil ifTrue:[ |
4050 |
secondsOrTimeDurationOrNil isTimeDuration ifTrue:[ |
|
4051 |
ms := secondsOrTimeDurationOrNil getMilliseconds. |
|
16402 | 4052 |
] ifFalse:[ |
22494 | 4053 |
ms := (secondsOrTimeDurationOrNil * 1000) rounded. |
16402 | 4054 |
] |
12401 | 4055 |
]. |
4056 |
^ self writeWaitWithTimeoutMs:ms |
|
22494 | 4057 |
|
4058 |
"Modified: / 19-01-2018 / 19:19:15 / stefan" |
|
12399 | 4059 |
! |
4060 |
||
4061 |
writeWaitWithTimeoutMs:millis |
|
4062 |
^ false "/ never have to wait |
|
4063 |
! ! |
|
4064 |
||
62 | 4065 |
!Stream methodsFor:'writing'! |
1 | 4066 |
|
611 | 4067 |
cr |
1403 | 4068 |
"append a carriage-return to the stream. |
4069 |
This is only allowed, if the receiver supports writing." |
|
611 | 4070 |
|
4071 |
self nextPut:(Character cr) |
|
1403 | 4072 |
|
4073 |
"Modified: 15.5.1996 / 18:01:21 / cg" |
|
611 | 4074 |
! |
4075 |
||
4076 |
crTab |
|
4077 |
"append a carriage-return followed by a tab to the stream. |
|
1403 | 4078 |
Same as crtab for ST/X backward compatibility. |
4079 |
This is only allowed, if the receiver supports writing." |
|
611 | 4080 |
|
5873 | 4081 |
<resource:#obsolete> |
4082 |
||
9061 | 4083 |
self obsoleteMethodWarning:'use #crtab'. |
611 | 4084 |
self crtab |
1403 | 4085 |
|
4086 |
"Modified: 15.5.1996 / 18:01:28 / cg" |
|
611 | 4087 |
! |
4088 |
||
9001 | 4089 |
crlf |
4090 |
"append a CR LF to the stream. |
|
4091 |
This is only allowed, if the receiver supports writing." |
|
4092 |
||
4093 |
self nextPut:(Character return); |
|
4094 |
nextPut:(Character lf). |
|
4095 |
! |
|
4096 |
||
611 | 4097 |
crtab |
1403 | 4098 |
"append a carriage-return followed by a tab to the stream. |
4099 |
This is only allowed, if the receiver supports writing." |
|
1 | 4100 |
|
611 | 4101 |
self crtab:1 |
1403 | 4102 |
|
4103 |
"Modified: 15.5.1996 / 18:01:35 / cg" |
|
611 | 4104 |
! |
4105 |
||
4106 |
crtab:n |
|
1403 | 4107 |
"append a carriage-return followed by n tabs to the stream. |
4108 |
This is only allowed, if the receiver supports writing." |
|
611 | 4109 |
|
4110 |
self nextPut:(Character cr). |
|
4111 |
self next:n put:(Character tab) |
|
1403 | 4112 |
|
4113 |
"Modified: 15.5.1996 / 18:01:39 / cg" |
|
611 | 4114 |
! |
4115 |
||
4116 |
endEntry |
|
4117 |
"ignored here - for compatibility with Transcript" |
|
4118 |
||
4119 |
^ self |
|
4120 |
! |
|
4121 |
||
4122 |
ff |
|
1403 | 4123 |
"append a form-feed (new-pagee) to the receiver-stream. |
4124 |
This is only allowed, if the receiver supports writing." |
|
611 | 4125 |
|
4126 |
self nextPut:(Character ff) |
|
1403 | 4127 |
|
4128 |
"Modified: 15.5.1996 / 18:01:47 / cg" |
|
1 | 4129 |
! |
4130 |
||
701 | 4131 |
flush |
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
4132 |
"write out all unbuffered data - ignored here, but added |
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
4133 |
to make internalStreams protocol compatible with externalStreams" |
701 | 4134 |
|
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
4135 |
"Modified: 7.5.1996 / 23:54:53 / stefan" |
701 | 4136 |
! |
4137 |
||
16453 | 4138 |
format:formatSpec with:args |
4139 |
"convenient formatted printing: |
|
4140 |
%1..%9 - positional parameters from args-collection |
|
4141 |
%(name) - named parameter from args-dictionary |
|
4142 |
%% - escape for % |
|
4143 |
%<cr> - cr (also tab, nl)" |
|
4144 |
||
23068 | 4145 |
formatSpec expandPlaceholders:$% with:args ignoreNumericEscapes:false on:self |
16453 | 4146 |
|
4147 |
" |
|
4148 |
1 to: 10 do:[:i | |
|
20242 | 4149 |
Transcript |
4150 |
format:'[%1] Hello %2 World - this is %3%<cr>' |
|
16453 | 4151 |
with:{i . 'my' . 'nice'} |
4152 |
]. |
|
4153 |
" |
|
23068 | 4154 |
|
4155 |
"Modified: / 14-06-2018 / 11:46:37 / Claus Gittinger" |
|
16453 | 4156 |
! |
4157 |
||
22007 | 4158 |
lf |
4159 |
"append a LF to the stream. |
|
4160 |
This is only allowed, if the receiver supports writing." |
|
4161 |
||
4162 |
self nextPut:(Character lf). |
|
4163 |
||
4164 |
"Created: / 13-07-2017 / 14:07:09 / cg" |
|
4165 |
! |
|
4166 |
||
1 | 4167 |
next:count put:anObject |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4168 |
"put the argument, anObject count times onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4169 |
This is only allowed, if the receiver supports writing." |
1 | 4170 |
|
345 | 4171 |
|n "{ Class: SmallInteger }"| |
4172 |
||
4173 |
n := count. |
|
4174 |
n timesRepeat:[self nextPut:anObject]. |
|
23935 | 4175 |
"/ return self |
62 | 4176 |
|
4177 |
" |
|
4178 |
|s| |
|
4179 |
||
4180 |
s := WriteStream on:#(). |
|
4181 |
s nextPut:1. |
|
4182 |
s next:5 put:2. |
|
4183 |
s nextPut:3. |
|
4184 |
s contents |
|
4185 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4186 |
|
23935 | 4187 |
"Modified: / 11-07-1996 / 10:00:13 / cg" |
4188 |
"Modified (comment): / 17-03-2019 / 15:04:09 / Claus Gittinger" |
|
1 | 4189 |
! |
4190 |
||
14792 | 4191 |
next:count putAll:aCollection |
4192 |
"put all elements from the argument, aCollection count times onto the receiver. |
|
4193 |
This is only allowed, if the receiver supports writing." |
|
4194 |
||
4195 |
|n "{ Class: SmallInteger }"| |
|
4196 |
||
4197 |
n := count. |
|
4198 |
n timesRepeat:[self nextPutAll:aCollection]. |
|
23935 | 4199 |
"/ return self |
14792 | 4200 |
|
4201 |
" |
|
4202 |
|s| |
|
4203 |
||
4204 |
s := WriteStream on:(String new). |
|
4205 |
s next:5 putAll:'Hello'. |
|
4206 |
s contents |
|
4207 |
" |
|
23935 | 4208 |
|
4209 |
"Modified (comment): / 17-03-2019 / 15:04:14 / Claus Gittinger" |
|
14792 | 4210 |
! |
4211 |
||
21813 | 4212 |
next:n putAll:aCollection startingAt:pos1 |
4213 |
"append n elements starting at pos1 of the argument, aCollection to the stream." |
|
4214 |
||
4215 |
^ self nextPutAll:aCollection startingAt:pos1 to:pos1+n-1 |
|
4216 |
||
4217 |
" |
|
4218 |
|s| |
|
4219 |
||
4220 |
s := '' writeStream. |
|
4221 |
s nextPutAll:'hello '. |
|
4222 |
s next:5 putAll:'1234world012345' startingAt:5. |
|
4223 |
s contents |
|
4224 |
" |
|
4225 |
||
4226 |
"Modified: / 12-07-1996 / 10:31:36 / cg" |
|
4227 |
"Modified (comment): / 15-06-2017 / 02:30:52 / cg" |
|
4228 |
! |
|
4229 |
||
611 | 4230 |
nextPut:anObject |
4231 |
"put the argument, anObject onto the receiver |
|
4232 |
- we do not know here how to do it, it must be redefined in subclass" |
|
4233 |
||
4234 |
^ self subclassResponsibility |
|
4235 |
! |
|
4236 |
||
1 | 4237 |
nextPutAll:aCollection |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4238 |
"put all elements of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4239 |
This is only allowed, if the receiver supports writing." |
1 | 4240 |
|
19082 | 4241 |
(aCollection notNil and:[aCollection isSequenceable]) ifFalse:[ |
4242 |
"/ fallback |
|
20242 | 4243 |
aCollection do:[:eachElement| |
19082 | 4244 |
self nextPut:eachElement. |
4245 |
]. |
|
4246 |
^ self. |
|
4247 |
]. |
|
4248 |
||
17330 | 4249 |
self nextPutAll:aCollection startingAt:1 to:aCollection size |
62 | 4250 |
|
4251 |
" |
|
4252 |
|s| |
|
4253 |
||
4254 |
s := WriteStream on:#(). |
|
4255 |
s nextPutAll:(1 to:5). |
|
4256 |
s nextPutAll:#('one' 'two' 'three'). |
|
4257 |
s contents |
|
4258 |
" |
|
4259 |
" |
|
4260 |
|s| |
|
4261 |
||
4262 |
s := WriteStream on:(String new). |
|
4263 |
s nextPutAll:($a to:$f). |
|
20242 | 4264 |
s nextPutAll:'one '; |
62 | 4265 |
nextPutAll:'two '; |
4266 |
nextPutAll:'three'. |
|
4267 |
s contents |
|
4268 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4269 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4270 |
"Modified: 11.7.1996 / 10:00:21 / cg" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4271 |
! |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4272 |
|
17615 | 4273 |
nextPutAll:count from:aCollection startingAt:initialIndex |
4274 |
"append count elements with index starting at initialIndex |
|
4275 |
of the argument, aCollection onto the receiver. |
|
4276 |
This is only allowed, if the receiver supports writing. |
|
17616 | 4277 |
Answer the number of elements that were appended. |
20242 | 4278 |
This is for compatibility with ExternalStream, where less then |
17616 | 4279 |
count elements may be written. Dolphin defines this as well." |
4280 |
||
4281 |
self nextPutAll:aCollection startingAt:initialIndex to:initialIndex+count-1. |
|
17615 | 4282 |
^ count |
4283 |
||
4284 |
" |
|
4285 |
|s| |
|
4286 |
||
4287 |
s := WriteStream on:#(). |
|
4288 |
s nextPutAll:4 from:#('one' 'two' 'three' 'four' 'five') startingAt:2. |
|
4289 |
s contents |
|
4290 |
" |
|
4291 |
||
4292 |
"Modified: 11.7.1996 / 10:00:32 / cg" |
|
4293 |
! |
|
4294 |
||
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4295 |
nextPutAll:aCollection startingAt:first |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4296 |
"append the elements starting with index to the end |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4297 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4298 |
This is only allowed, if the receiver supports writing." |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4299 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4300 |
self nextPutAll:aCollection startingAt:first to:(aCollection size). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4301 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4302 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4303 |
|s| |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4304 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4305 |
s := WriteStream on:#(). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4306 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2. |
20242 | 4307 |
s contents |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4308 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4309 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4310 |
"Modified: 11.7.1996 / 10:00:28 / cg" |
1 | 4311 |
! |
4312 |
||
4313 |
nextPutAll:aCollection startingAt:first to:last |
|
24031 | 4314 |
"append the elements from first index to last index |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4315 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4316 |
This is only allowed, if the receiver supports writing." |
1 | 4317 |
|
4318 |
aCollection from:first to:last do:[:element | |
|
23540 | 4319 |
self nextPut:element |
1 | 4320 |
]. |
62 | 4321 |
|
4322 |
" |
|
4323 |
|s| |
|
4324 |
||
4325 |
s := WriteStream on:#(). |
|
4326 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4. |
|
4327 |
s contents |
|
4328 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4329 |
|
23540 | 4330 |
"Modified: / 11-07-1996 / 10:00:32 / cg" |
4331 |
"Modified: / 22-11-2018 / 12:52:25 / Stefan Vogel" |
|
24031 | 4332 |
"Modified (comment): / 01-04-2019 / 17:12:15 / Claus Gittinger" |
1 | 4333 |
! |
4334 |
||
14263 | 4335 |
nextPutAllLines:aCollectionOfStrings |
4336 |
"put all elements of the argument, aCollection as individual lines |
|
20242 | 4337 |
onto the receiver, append a cr (carriage return) after each. |
14263 | 4338 |
This is only useful with character streams in textMode, |
4339 |
and only allowed, if the receiver supports writing." |
|
4340 |
||
4341 |
aCollectionOfStrings do:[:eachLine | |
|
4342 |
self nextPutLine:eachLine. |
|
4343 |
]. |
|
4344 |
||
4345 |
"Modified: / 08-11-1996 / 23:53:41 / cg" |
|
4346 |
"Created: / 27-07-2012 / 09:26:09 / cg" |
|
4347 |
! |
|
4348 |
||
11322 | 4349 |
nextPutAllText:aText |
4350 |
"normal streams can not handle text/emphasis, so convert aText to the string" |
|
4351 |
||
4352 |
aText string printOn:self. |
|
4353 |
! |
|
4354 |
||
4355 |
nextPutAllUnicode:aString |
|
4356 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
4357 |
||
4358 |
aString do:[:eachCharacter| |
|
4359 |
self nextPutUtf8:eachCharacter. |
|
4360 |
]. |
|
4361 |
! |
|
4362 |
||
5628
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4363 |
nextPutAllUntranslated:aCollection |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4364 |
"for compatibility with printStreams (putAll - as-is without escapes)" |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4365 |
|
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4366 |
self nextPutAll:aCollection |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4367 |
! |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
4368 |
|
743 | 4369 |
nextPutLine:aCollection |
4370 |
"put all elements of the argument, aCollection onto the receiver, |
|
16454 | 4371 |
and append a cr (carriage return). aCollection should contain characters. |
20173 | 4372 |
This is only useful with character streams in textMode |
4373 |
and only allowed if the receiver supports writing." |
|
743 | 4374 |
|
4375 |
self nextPutAll:aCollection. |
|
4376 |
self cr. |
|
4377 |
||
4378 |
"Created: 13.12.1995 / 10:49:17 / cg" |
|
1949 | 4379 |
"Modified: 8.11.1996 / 23:53:41 / cg" |
743 | 4380 |
! |
4381 |
||
11322 | 4382 |
nextPutUnicode:aCharacter |
4383 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
4384 |
||
4385 |
self nextPutUtf8:aCharacter. |
|
4386 |
! |
|
4387 |
||
611 | 4388 |
print:anObject |
4389 |
"append a printed representation of anObject to the receiver. |
|
1403 | 4390 |
Same as 'anObject printOn:self'; Added for ST-80 compatibility." |
2 | 4391 |
|
611 | 4392 |
anObject printOn:self |
1403 | 4393 |
|
4394 |
" |
|
4395 |
|s| |
|
4396 |
||
4397 |
s := WriteStream on:''. |
|
4398 |
s nextPutAll:'one '; |
|
4399 |
print:1; |
|
4400 |
nextPutAll:' two '; |
|
4401 |
print:2. |
|
4402 |
||
4403 |
s contents |
|
4404 |
" |
|
4405 |
||
4406 |
"Modified: 15.5.1996 / 18:06:06 / cg" |
|
2 | 4407 |
! |
4408 |
||
14360 | 4409 |
printCR:anObject |
4410 |
"append a printed representation of anObject to the receiver, |
|
4411 |
followed by a newline character." |
|
4412 |
||
4413 |
self print:anObject. |
|
4414 |
self cr. |
|
4415 |
||
4416 |
"Created: / 26-09-2012 / 18:21:06 / cg" |
|
4417 |
! |
|
4418 |
||
16864 | 4419 |
println |
4420 |
"for those used to Java/Javascript, a compatibility message. |
|
4421 |
Most useful inside expecco" |
|
4422 |
||
4423 |
self cr |
|
4424 |
! |
|
4425 |
||
4426 |
println:anObject |
|
4427 |
"for those used to Java/Javascript, a compatibility message. |
|
4428 |
Most useful inside expecco" |
|
4429 |
||
4430 |
self showCR:anObject |
|
4431 |
! |
|
4432 |
||
1403 | 4433 |
show:something |
4434 |
"append a printed representation of the argument to the stream. |
|
4435 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4436 |
allows you to say: |
10920 | 4437 |
Smalltalk at:#Transcript put:Stdout |
1422 | 4438 |
or to use #show:/#showCR: with internal or external streams." |
1 | 4439 |
|
10920 | 4440 |
something printOn:self |
1 | 4441 |
! |
4442 |
||
11863 | 4443 |
show:something with:arg |
11949 | 4444 |
"append a printed representation of the argument to the stream, expanding |
4445 |
the placeHolder %1 with the printString of arg. |
|
4446 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4447 |
allows you to say: |
11949 | 4448 |
Smalltalk at:#Transcript put:Stdout |
4449 |
or to use #show:/#showCR: with internal or external streams." |
|
4450 |
||
13027 | 4451 |
self show:(something bindWith:arg) |
4452 |
||
4453 |
"Modified: / 19-08-2010 / 15:42:00 / cg" |
|
11863 | 4454 |
! |
4455 |
||
4456 |
show:something with:arg1 with:arg2 |
|
11949 | 4457 |
"append a printed representation of the argument to the stream, expanding |
4458 |
the placeHolders %1 and %2 with the printStrings of arg1 and arg2. |
|
4459 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4460 |
allows you to say: |
11949 | 4461 |
Smalltalk at:#Transcript put:Stdout |
4462 |
or to use #show:/#showCR: with internal or external streams." |
|
4463 |
||
13027 | 4464 |
self show:(something bindWith:arg1 with:arg2) |
4465 |
||
4466 |
"Modified: / 19-08-2010 / 15:42:09 / cg" |
|
11863 | 4467 |
! |
4468 |
||
4469 |
show:something with:arg1 with:arg2 with:arg3 |
|
11949 | 4470 |
"append a printed representation of the argument to the stream, expanding |
4471 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4472 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4473 |
allows you to say: |
11949 | 4474 |
Smalltalk at:#Transcript put:Stdout |
4475 |
or to use #show:/#showCR: with internal or external streams." |
|
4476 |
||
13027 | 4477 |
self show:(something bindWith:arg1 with:arg2 with:arg3) |
4478 |
||
4479 |
"Modified: / 19-08-2010 / 15:42:17 / cg" |
|
4480 |
! |
|
4481 |
||
4482 |
show:something with:arg1 with:arg2 with:arg3 with:arg4 |
|
4483 |
"append a printed representation of the argument to the stream, expanding |
|
4484 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4485 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4486 |
allows you to say: |
13027 | 4487 |
Smalltalk at:#Transcript put:Stdout |
4488 |
or to use #show:/#showCR: with internal or external streams." |
|
4489 |
||
4490 |
self show:(something bindWith:arg1 with:arg2 with:arg3 with:arg4) |
|
4491 |
||
4492 |
"Created: / 19-08-2010 / 15:42:25 / cg" |
|
11863 | 4493 |
! |
4494 |
||
16794 | 4495 |
show:something with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
4496 |
"append a printed representation of the argument to the stream, expanding |
|
4497 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4498 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4499 |
allows you to say: |
16794 | 4500 |
Smalltalk at:#Transcript put:Stdout |
4501 |
or to use #show:/#showCR: with internal or external streams." |
|
4502 |
||
4503 |
self show:(something bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
4504 |
||
4505 |
"Created: / 19-08-2010 / 15:42:25 / cg" |
|
4506 |
! |
|
4507 |
||
15711 | 4508 |
show:something withArguments:args |
4509 |
"append a printed representation of the argument to the stream, expanding |
|
4510 |
the placeHolders %1,%2 and %3 with the printStrings of argi. |
|
4511 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4512 |
allows you to say: |
15711 | 4513 |
Smalltalk at:#Transcript put:Stdout |
4514 |
or to use #show:/#showCR: with internal or external streams." |
|
4515 |
||
4516 |
self show:(something bindWithArguments:args) |
|
4517 |
! |
|
4518 |
||
1414 | 4519 |
showCR:aString |
1403 | 4520 |
"append a printed representation of the argument to the stream |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4521 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4522 |
This makes streams somewhat compatible to TextCollectors and |
20242 | 4523 |
allows you to say: |
4524 |
Smalltalk at:#Transcript put:Stdout |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4525 |
or to use #show:/#showCR: with internal or external streams." |
1 | 4526 |
|
4527 |
self show:aString. |
|
4528 |
self cr |
|
1403 | 4529 |
|
1414 | 4530 |
"Created: 18.5.1996 / 15:34:17 / cg" |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4531 |
"Modified: 11.7.1996 / 10:01:27 / cg" |
1414 | 4532 |
! |
4533 |
||
13027 | 4534 |
showCR:something with:arg |
4535 |
"append a printed representation of the argument to the stream, expanding |
|
4536 |
the placeHolder %1 with the printString of arg. |
|
4537 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4538 |
allows you to say: |
13027 | 4539 |
Smalltalk at:#Transcript put:Stdout |
4540 |
or to use #show:/#showCR: with internal or external streams." |
|
4541 |
||
4542 |
self showCR:(something bindWith:arg) |
|
4543 |
||
4544 |
"Created: / 19-08-2010 / 15:41:46 / cg" |
|
4545 |
! |
|
4546 |
||
4547 |
showCR:something with:arg1 with:arg2 |
|
4548 |
"append a printed representation of the argument to the stream, expanding |
|
4549 |
the placeHolders %1 and %2 with the printStrings of arg1 and arg2. |
|
4550 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4551 |
allows you to say: |
13027 | 4552 |
Smalltalk at:#Transcript put:Stdout |
4553 |
or to use #show:/#showCR: with internal or external streams." |
|
4554 |
||
4555 |
self showCR:(something bindWith:arg1 with:arg2) |
|
4556 |
||
4557 |
"Created: / 19-08-2010 / 15:42:37 / cg" |
|
4558 |
! |
|
4559 |
||
4560 |
showCR:something with:arg1 with:arg2 with:arg3 |
|
4561 |
"append a printed representation of the argument to the stream, expanding |
|
4562 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4563 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4564 |
allows you to say: |
13027 | 4565 |
Smalltalk at:#Transcript put:Stdout |
4566 |
or to use #show:/#showCR: with internal or external streams." |
|
4567 |
||
4568 |
self showCR:(something bindWith:arg1 with:arg2 with:arg3) |
|
4569 |
||
23738 | 4570 |
" |
4571 |
Transcript showCR:'hello %1 %2 %3' with:'foo' with:10 with:'bla' |
|
4572 |
" |
|
4573 |
||
13027 | 4574 |
"Created: / 19-08-2010 / 15:42:43 / cg" |
23738 | 4575 |
"Modified (comment): / 15-02-2019 / 09:48:27 / Claus Gittinger" |
13027 | 4576 |
! |
4577 |
||
4578 |
showCR:something with:arg1 with:arg2 with:arg3 with:arg4 |
|
4579 |
"append a printed representation of the argument to the stream, expanding |
|
4580 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4581 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4582 |
allows you to say: |
13027 | 4583 |
Smalltalk at:#Transcript put:Stdout |
4584 |
or to use #show:/#showCR: with internal or external streams." |
|
4585 |
||
4586 |
self showCR:(something bindWith:arg1 with:arg2 with:arg3 with:arg4) |
|
4587 |
||
4588 |
"Created: / 19-08-2010 / 15:42:50 / cg" |
|
4589 |
! |
|
4590 |
||
16794 | 4591 |
showCR:something with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
4592 |
"append a printed representation of the argument to the stream, expanding |
|
4593 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
4594 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4595 |
allows you to say: |
16794 | 4596 |
Smalltalk at:#Transcript put:Stdout |
4597 |
or to use #show:/#showCR: with internal or external streams." |
|
4598 |
||
4599 |
self showCR:(something bindWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
4600 |
||
4601 |
"Created: / 19-08-2010 / 15:42:50 / cg" |
|
4602 |
! |
|
4603 |
||
15711 | 4604 |
showCR:something withArguments:args |
4605 |
"append a printed representation of the argument to the stream, expanding |
|
4606 |
the placeHolders %1,%2 and %3 with the printStrings of argi. |
|
4607 |
This makes streams somewhat compatible to TextCollectors and |
|
20242 | 4608 |
allows you to say: |
15711 | 4609 |
Smalltalk at:#Transcript put:Stdout |
4610 |
or to use #show:/#showCR: with internal or external streams." |
|
4611 |
||
4612 |
self showCR:(something bindWithArguments:args) |
|
4613 |
! |
|
4614 |
||
1414 | 4615 |
showCr:aString |
4616 |
"append a printed representation of the argument to the stream |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4617 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4618 |
This is obsolete ST/X backward compatibility; use #showCR:" |
1414 | 4619 |
|
5873 | 4620 |
<resource:#obsolete> |
4621 |
||
1414 | 4622 |
self obsoleteMethodWarning:'use #showCR:'. |
4623 |
self showCR:aString. |
|
4624 |
||
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4625 |
"Modified: 11.7.1996 / 10:01:50 / cg" |
62 | 4626 |
! |
4627 |
||
4628 |
space |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4629 |
"append a space character to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4630 |
This is only allowed, if the receiver supports writing." |
62 | 4631 |
|
4632 |
self nextPut:(Character space) |
|
1403 | 4633 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4634 |
"Modified: 11.7.1996 / 10:02:06 / cg" |
62 | 4635 |
! |
4636 |
||
4637 |
spaces:count |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4638 |
"append count space-characters to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4639 |
This is only allowed, if the receiver supports writing." |
62 | 4640 |
|
4641 |
self next:count put:(Character space) |
|
1403 | 4642 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4643 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
62 | 4644 |
! |
4645 |
||
611 | 4646 |
store:anObject |
4647 |
"append a printed representation of anObject to the receiver, |
|
1403 | 4648 |
from which the receiver can be reconstructed (i.e. its storeString). |
4649 |
Same as 'anObject storeOn:self'; Added for ST-80 compatibility." |
|
77 | 4650 |
|
611 | 4651 |
anObject storeOn:self |
1403 | 4652 |
|
4653 |
"Modified: 15.5.1996 / 18:05:55 / cg" |
|
77 | 4654 |
! |
4655 |
||
8645 | 4656 |
sync |
4657 |
"write out all unbuffered data - ignored here, but added |
|
4658 |
to make internalStreams protocol compatible with externalStreams" |
|
4659 |
! |
|
4660 |
||
11649 | 4661 |
syncData |
4662 |
"write out all unbuffered data - ignored here, but added |
|
4663 |
to make internalStreams protocol compatible with externalStreams" |
|
4664 |
! |
|
4665 |
||
611 | 4666 |
tab |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4667 |
"append a tab-character to the stream. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4668 |
This is only allowed, if the receiver supports writing." |
77 | 4669 |
|
611 | 4670 |
self nextPut:(Character tab) |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4671 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
4672 |
"Modified: 11.7.1996 / 10:02:20 / cg" |
2443 | 4673 |
! |
4674 |
||
4675 |
tab:count |
|
4676 |
"append count tab-characters to the receiver. |
|
4677 |
This is only allowed, if the receiver supports writing." |
|
4678 |
||
4679 |
self next:count put:(Character tab) |
|
4680 |
||
4681 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
|
77 | 4682 |
! ! |
4683 |
||
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4684 |
!Stream methodsFor:'writing-chunks'! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4685 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4686 |
nextChunkPut:aString |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4687 |
"put aString as a chunk onto the receiver; |
20242 | 4688 |
double all exclamation marks except within primitives and append a |
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4689 |
single delimiting exclamation mark at the end. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4690 |
This modification of the chunk format (not doubling exclas in primitive code) |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4691 |
was done to have primitive code more readable and easier be edited in the fileBrowser |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4692 |
or other editors. |
15086 | 4693 |
It's no incompatibility, since inline primitives are an ST/X special |
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4694 |
and code containing ST/X primitives cannot be loaded into other smalltalks anyway." |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4695 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4696 |
self nextPutAllAsChunk:aString. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4697 |
self nextPut:(self class chunkSeparator) |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4698 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4699 |
"Modified: 9.12.1995 / 15:56:54 / cg" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4700 |
! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4701 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4702 |
nextPutAllAsChunk:aString |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4703 |
"put aString as a chunk onto the receiver; |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4704 |
double all exclamation marks except within primitives. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4705 |
This modification of the chunk format (not doubling exclas in primitive code) |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4706 |
was done to have primitive code more readable and easier be edited in the fileBrowser |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4707 |
or other editors. |
19648 | 4708 |
It's no incompatibility, since inline primitives are an ST/X special |
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4709 |
and code containing ST/X primitives cannot be loaded into other smalltalks anyway." |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4710 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4711 |
|sep stopChars inPrimitive character |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4712 |
index "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4713 |
endIndex "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4714 |
stop "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4715 |
next "{ Class:SmallInteger }"| |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4716 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4717 |
endIndex := aString size. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4718 |
endIndex == 0 ifTrue:[^ self]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4719 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4720 |
sep := self class chunkSeparator. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4721 |
stopChars := '{}' copyWith:sep. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4722 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4723 |
inPrimitive := false. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4724 |
index := 1. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4725 |
stop := endIndex + 1. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4726 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4727 |
[index <= endIndex] whileTrue:[ |
16870 | 4728 |
" |
20242 | 4729 |
find position of next interesting character; |
16870 | 4730 |
output stuff up to that one in one piece |
4731 |
" |
|
4732 |
next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop. |
|
4733 |
||
4734 |
((index == 1) and:[next == stop]) ifTrue:[ |
|
4735 |
self nextPutAll:aString |
|
4736 |
] ifFalse:[ |
|
4737 |
self nextPutAll:aString startingAt:index to:(next - 1) |
|
4738 |
]. |
|
4739 |
||
4740 |
index := next. |
|
4741 |
(index <= endIndex) ifTrue:[ |
|
4742 |
character := aString at:index. |
|
4743 |
||
4744 |
(character == ${ ) ifTrue:[ |
|
4745 |
"/ starts a primitive |
|
4746 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
|
4747 |
inPrimitive := true |
|
4748 |
] |
|
4749 |
] ifFalse:[ |
|
4750 |
"/ ends a primitive |
|
4751 |
(character == $} ) ifTrue:[ |
|
4752 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
|
4753 |
inPrimitive := false |
|
4754 |
] |
|
4755 |
] ifFalse:[ |
|
4756 |
"/ |
|
4757 |
"/ exclas have to be doubled - except if within a primitive |
|
4758 |
"/ |
|
4759 |
inPrimitive ifFalse:[ |
|
4760 |
(character == sep) ifTrue:[ |
|
4761 |
self nextPut:sep |
|
4762 |
] |
|
4763 |
] |
|
4764 |
] |
|
4765 |
]. |
|
4766 |
||
4767 |
self nextPut:character. |
|
4768 |
index := index + 1. |
|
4769 |
]. |
|
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4770 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4771 |
(aString endsWith:Character cr) ifFalse:[ |
16870 | 4772 |
self cr. |
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4773 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4774 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4775 |
"Modified: / 21.4.1998 / 17:22:47 / cg" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4776 |
! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4777 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4778 |
nextPutChunkSeparator |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4779 |
"append a chunk separator character" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4780 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4781 |
self nextPut:(self class chunkSeparator) |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4782 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4783 |
"Created: 13.9.1995 / 17:39:26 / claus" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4784 |
! ! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
4785 |
|
1949 | 4786 |
!Stream class methodsFor:'documentation'! |
701 | 4787 |
|
4788 |
version |
|
18478 | 4789 |
^ '$Header$' |
12093 | 4790 |
! |
4791 |
||
4792 |
version_CVS |
|
18478 | 4793 |
^ '$Header$' |
701 | 4794 |
! ! |
6857 | 4795 |
|
14792 | 4796 |
|
611 | 4797 |
Stream initialize! |