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