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