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