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