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