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