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