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