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