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