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