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