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