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