author | Stefan Vogel <sv@exept.de> |
Wed, 12 Jun 2013 10:37:20 +0200 | |
changeset 15397 | 3e7f6d3661ef |
parent 15165 | 0b3db61eb3f3 |
child 15590 | 599f382cedc7 |
child 18067 | 27352a7171ab |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
216 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
13 |
|
1 | 14 |
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
|
15 |
instanceVariableNames:'signalAtEnd' |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
16 |
classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal |
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
17 |
WriteErrorSignal EndOfStreamSignal LineTooLongErrorSignal |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
18 |
ChunkSeparator' |
743 | 19 |
poolDictionaries:'' |
20 |
category:'Streams' |
|
1 | 21 |
! |
22 |
||
1949 | 23 |
!Stream class methodsFor:'documentation'! |
88 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
216 | 28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
An abstract class defining common behavior for all stream-like objects. |
|
42 |
See concrete subclasses for more detail. |
|
345 | 43 |
|
1404 | 44 |
The protocol as implemented here is often only provided as a fallBack |
45 |
for very uncommon cases. Much of it is redefined for performance. |
|
46 |
(In streams which know more about their internal representation ...) |
|
47 |
||
48 |
||
345 | 49 |
Subclasses should (at least) implement: |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
50 |
#next (if readable) |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
51 |
#nextPut: (if writable) |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
52 |
#contents |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
53 |
#atEnd |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
54 |
#isReadable |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
55 |
#isWritable |
1295 | 56 |
|
1404 | 57 |
Peekable & Positionable streams should (at least) implement: |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
58 |
#peek |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
59 |
#position |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
60 |
#position: |
1404 | 61 |
|
62 |
||
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
63 |
[instance variables:] |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
64 |
signalAtEnd <nil | Boolean> controls behavior when a read |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
65 |
is attempted past the end-of-stream |
8309 | 66 |
if true, the endOfStreamSignal is raised. |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
67 |
if false, nil is returned. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
68 |
if nil (the default), the signal |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
69 |
is raised, but if there is no handler, |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
70 |
nil is returned. |
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
71 |
|
8309 | 72 |
[Class variables / Exceptions:] |
73 |
StreamError <Exception> parent of all stream errors |
|
74 |
||
75 |
PositionError <Exception> position attemted on a stream |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
76 |
which does not support positioning, |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
77 |
or if the position is invalid. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
78 |
|
8309 | 79 |
ReadError <Exception> raised on read errors |
80 |
||
81 |
WriteError <Exception> raised on write errors |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
82 |
|
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
83 |
EndOfStreamSignal <Signal> raised at end of stream if signalAtEnd |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
84 |
is enabled. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
85 |
|
1295 | 86 |
[author:] |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
87 |
Claus Gittinger |
88 | 88 |
" |
89 |
! ! |
|
1 | 90 |
|
1949 | 91 |
!Stream class methodsFor:'initialization'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
92 |
|
5991 | 93 |
initSignals |
94 |
StreamErrorSignal := StreamError. |
|
95 |
StreamErrorSignal notifierString:'Stream error'. |
|
96 |
||
8071 | 97 |
PositionErrorSignal := PositionError. |
6314 | 98 |
PositionErrorSignal notifierString:'stream has no concept of a position'. |
5991 | 99 |
|
8071 | 100 |
ReadErrorSignal := ReadError. |
5991 | 101 |
ReadErrorSignal notifierString:'read error'. |
102 |
||
8071 | 103 |
WriteErrorSignal := WriteError. |
5991 | 104 |
WriteErrorSignal notifierString:'write error'. |
105 |
||
106 |
LineTooLongErrorSignal := QuerySignal new. |
|
8515 | 107 |
LineTooLongErrorSignal parent:StreamError. |
5991 | 108 |
LineTooLongErrorSignal nameClass:self message:#lineTooLongErrorSignal. |
109 |
LineTooLongErrorSignal notifierString:'line too long'. |
|
110 |
||
8515 | 111 |
EndOfStreamSignal := EndOfStreamNotification. |
5991 | 112 |
EndOfStreamSignal notifierString:'end of stream'. |
113 |
||
114 |
"Created: / 7.9.2001 / 14:15:13 / cg" |
|
115 |
"Modified: / 7.9.2001 / 14:15:27 / cg" |
|
116 |
! |
|
117 |
||
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
118 |
initialize |
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
119 |
ChunkSeparator := $!!. |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
120 |
|
8309 | 121 |
LineTooLongErrorSignal isNil ifTrue:[ |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
122 |
self initSignals |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
123 |
] |
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
124 |
|
3911 | 125 |
"Modified: / 1.11.1998 / 15:57:37 / stefan" |
5991 | 126 |
"Modified: / 7.9.2001 / 14:15:51 / cg" |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
127 |
! ! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
128 |
|
1949 | 129 |
!Stream class methodsFor:'instance creation'! |
611 | 130 |
|
131 |
new |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
132 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
133 |
|
611 | 134 |
"report an error - Streams are created using on:-messages" |
135 |
||
4530
793b116fef3e
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4467
diff
changeset
|
136 |
self error:'Streams cannot be created with new' |
611 | 137 |
! ! |
138 |
||
1949 | 139 |
!Stream class methodsFor:'Signal constants'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
140 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
141 |
endOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
142 |
"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
|
143 |
|
8515 | 144 |
^ EndOfStreamNotification |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
145 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
146 |
|
6348 | 147 |
incompleteNextCountSignal |
148 |
"return the signal raised if not all requested elements are returned" |
|
149 |
||
150 |
^ IncompleteNextCountError |
|
151 |
! |
|
152 |
||
3877
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
153 |
lineTooLongErrorSignal |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
154 |
"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
|
155 |
|
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
156 |
^ LineTooLongErrorSignal |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
157 |
|
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
158 |
"Created: / 15.10.1998 / 12:11:14 / cg" |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
159 |
! |
16673e28625b
added LineTooLongErrorSignal
Claus Gittinger <cg@exept.de>
parents:
3593
diff
changeset
|
160 |
|
611 | 161 |
positionErrorSignal |
162 |
"return the signal raised if positioning is requested for |
|
163 |
a stream which does not support that kind of operation" |
|
164 |
||
8309 | 165 |
^ PositionError |
611 | 166 |
! |
167 |
||
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
168 |
readErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
169 |
"return the signal raised on read errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
170 |
|
8309 | 171 |
^ ReadError |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
172 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
173 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
174 |
streamErrorSignal |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
175 |
"return the parent of all stream errors; |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
176 |
handling this one also handles all other errors. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
177 |
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
|
178 |
operations, such as failed ioctls in externalStream etc." |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
179 |
|
8309 | 180 |
^ StreamError |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
181 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
182 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
183 |
writeErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
184 |
"return the signal raised on write errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
185 |
|
8309 | 186 |
^ WriteError |
1 | 187 |
! ! |
188 |
||
5392
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
189 |
!Stream class methodsFor:'constants'! |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
190 |
|
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
191 |
chunkSeparator |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
192 |
"return the chunk-separation character" |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
193 |
|
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
194 |
^ ChunkSeparator |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
195 |
! ! |
deafa504029a
moved chunkSeparator from PositionableStream
Claus Gittinger <cg@exept.de>
parents:
5072
diff
changeset
|
196 |
|
14792 | 197 |
|
1 | 198 |
!Stream methodsFor:'accessing'! |
199 |
||
200 |
contents |
|
11693 | 201 |
"return the entire contents of the stream. |
202 |
For a readStream, that is the rest (i.e. upToEnd), |
|
203 |
for a writeStream, that is the collected data. As we do not know here, |
|
204 |
what we are, this is the responsibility of a subclass..." |
|
205 |
||
206 |
^ self subclassResponsibility |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
207 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
208 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
209 |
signalAtEnd |
3105 | 210 |
"return the signalAtEnd flag setting. |
211 |
If true, reading past the end will always raise an EndOfStream exception. |
|
212 |
If false, no exception is raised and nil is returned from all reading messages. |
|
213 |
If nil (default), the exception is raised if there is a handler; otherwise, nil is returned. |
|
214 |
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
|
215 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
216 |
^ signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
217 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
218 |
"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
|
219 |
"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
|
220 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
221 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
222 |
signalAtEnd:aBoolean |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
223 |
"set the signalAtEnd flag setting. If true, reading past the end |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
224 |
will raise an EndOfStream exception. If false, no exception is |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
225 |
raised and nil is returned from all reading messages. |
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
226 |
The default is to raise a signal, but return nil if |
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
227 |
not handled." |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
228 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
229 |
signalAtEnd := aBoolean. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
230 |
|
3591 | 231 |
"default behavior: return nil if unhandled ... |
232 |
|s| |
|
233 |
||
234 |
s := '12' readStream. |
|
235 |
Transcript showCR:s next. |
|
236 |
Transcript showCR:s next. |
|
237 |
Transcript showCR:s next. |
|
238 |
Transcript showCR:s next. |
|
239 |
" |
|
240 |
||
241 |
"... raise error if handled. |
|
242 |
|s| |
|
243 |
||
244 |
s := '12' readStream. |
|
245 |
Stream endOfStreamSignal handle:[:ex | |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
246 |
Transcript showCR:'end reached'. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
247 |
ex return |
3591 | 248 |
] do:[ |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
249 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
250 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
251 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
252 |
Transcript showCR:s next. |
3591 | 253 |
] |
254 |
" |
|
255 |
||
256 |
"force raise (useful for debugging): |
|
257 |
|s| |
|
258 |
||
259 |
s := '12' readStream. |
|
260 |
s signalAtEnd:true. |
|
261 |
Transcript showCR:s next. |
|
262 |
Transcript showCR:s next. |
|
263 |
Transcript showCR:s next. |
|
264 |
Transcript showCR:s next. |
|
265 |
" |
|
266 |
||
267 |
||
268 |
"force no-raise (useful for compatibility with other systems): |
|
269 |
|s| |
|
270 |
||
271 |
s := '12' readStream. |
|
272 |
s signalAtEnd:false. |
|
273 |
Stream endOfStreamSignal handle:[:ex | |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
274 |
Transcript showCR:'end reached'. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
275 |
ex return |
3591 | 276 |
] do:[ |
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
277 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
278 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
279 |
Transcript showCR:s next. |
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
280 |
Transcript showCR:s next. |
3591 | 281 |
] |
282 |
" |
|
283 |
||
284 |
"Modified: / 16.6.1998 / 16:04:41 / cg" |
|
1 | 285 |
! ! |
286 |
||
611 | 287 |
!Stream methodsFor:'closing'! |
288 |
||
289 |
close |
|
290 |
"close the stream - nothing done here. |
|
291 |
Added for compatibility with external streams." |
|
292 |
||
293 |
^ self |
|
294 |
! ! |
|
295 |
||
8630 | 296 |
!Stream methodsFor:'converting'! |
297 |
||
298 |
asStream |
|
299 |
^ self |
|
300 |
! ! |
|
301 |
||
1401 | 302 |
!Stream methodsFor:'emphasis'! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
303 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
304 |
bold |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
305 |
"set emphasis to #bold. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
306 |
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
|
307 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
308 |
self emphasis:#bold. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
309 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
310 |
"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
|
311 |
"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
|
312 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
313 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
314 |
boldItalic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
315 |
"set emphasis to #boldItalic |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
316 |
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
|
317 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
318 |
self emphasis:#(bold italic). |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
319 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
320 |
"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
|
321 |
"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
|
322 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
323 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
324 |
emphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
325 |
"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
|
326 |
text streams" |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
327 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
328 |
^ nil |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
329 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
330 |
"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
|
331 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
332 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
333 |
emphasis:anEmphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
334 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
335 |
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
|
336 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
337 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
338 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
339 |
"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
|
340 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
341 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
342 |
italic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
343 |
"set emphasis to #italic. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
344 |
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
|
345 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
346 |
self emphasis:#italic. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
347 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
348 |
"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
|
349 |
"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
|
350 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
351 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
352 |
normal |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
353 |
"set emphasis to #normal. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
354 |
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
|
355 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
356 |
self emphasis:nil |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
357 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
358 |
"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
|
359 |
"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
|
360 |
! |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
361 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
362 |
strikeout |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
363 |
"set emphasis to #strikeout. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
364 |
this allows Streams to be used interchangeable with printStreams" |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
365 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
366 |
self emphasis:#strikeout. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
367 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
368 |
"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
|
369 |
"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
|
370 |
! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
371 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
372 |
underline |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
373 |
"set emphasis to #underline. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
374 |
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
|
375 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
376 |
self emphasis:#underline. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
377 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
378 |
"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
|
379 |
"Modified: 3.6.1996 / 17:15:38 / cg" |
14347 | 380 |
! |
381 |
||
382 |
withEmphasis:anEmphasis do:aBlock |
|
383 |
"evaluate aBlock while my emphasis has been changed to anEmphasis. |
|
384 |
Emphasis is ignored here, but implemented in some subclasses (PrinterStream, TextCollector etc.)." |
|
385 |
||
386 |
|oldEmphasis| |
|
387 |
||
388 |
oldEmphasis := self emphasis. |
|
389 |
[ |
|
390 |
self emphasis:anEmphasis. |
|
391 |
aBlock value |
|
392 |
] ensure:[ |
|
393 |
self emphasis:oldEmphasis. |
|
394 |
]. |
|
395 |
||
396 |
"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
|
397 |
! ! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
398 |
|
1401 | 399 |
!Stream methodsFor:'enumerating'! |
400 |
||
401 |
do:aBlock |
|
402 |
"evaluate the argument, aBlock for all remaining elements, |
|
403 |
up to the end of the stream" |
|
404 |
||
405 |
[self atEnd] whileFalse:[ |
|
406 |
aBlock value:(self next) |
|
407 |
] |
|
408 |
||
409 |
" |
|
410 |
|s| |
|
411 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
412 |
s next. |
|
413 |
s next. |
|
1422 | 414 |
s do:[:element | Transcript showCR:element] |
1401 | 415 |
" |
6384 | 416 |
! |
417 |
||
418 |
linesDo:aBlock |
|
419 |
"evaluate the argument, aBlock for all lines, |
|
420 |
up to the end of the stream" |
|
421 |
||
422 |
[self atEnd] whileFalse:[ |
|
423 |
aBlock value:(self nextLine) |
|
424 |
] |
|
425 |
||
426 |
" |
|
427 |
|s| |
|
428 |
s := '/etc/hosts' asFilename readStream. |
|
429 |
s linesDo:[:line | Transcript showCR:line]. |
|
430 |
s close |
|
431 |
" |
|
432 |
||
433 |
" |
|
434 |
Filename readingFile:'/etc/hosts' |
|
435 |
do:[:s | |
|
436 |
s linesDo:[:line | Transcript showCR:line]. |
|
437 |
]. |
|
438 |
" |
|
1401 | 439 |
! ! |
440 |
||
441 |
!Stream methodsFor:'error handling'! |
|
442 |
||
7104
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
443 |
checkNilFileStream |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
444 |
"Do nothing if this is a valid FileStream |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
445 |
(i.e. the previous open operation was successful). |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
446 |
Also implemented in UndefinedObject, to raise an Error there. |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
447 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
448 |
This is an aid for converting from the old error reporting (returning nil) |
8309 | 449 |
to the new error reporting (with real Exceptions). |
7104
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
450 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
451 |
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
|
452 |
|
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
453 |
^ self |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
454 |
! |
c88669d779f5
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
7013
diff
changeset
|
455 |
|
1401 | 456 |
pastEnd |
457 |
"someone tried to read after the end of the stream. |
|
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
458 |
If signalAtEnd == true, raise a signal. If its false, return nil. |
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
459 |
Otherwise raise the signal, but only if handled; otherwise return nil." |
1401 | 460 |
|
8622 | 461 |
<resource: #obsolete> |
462 |
||
9061 | 463 |
self obsoleteMethodWarning:'use #pastEndRead'. |
10181 | 464 |
^ self pastEndRead |
465 |
||
466 |
"Modified: / 18-11-2006 / 15:36:44 / cg" |
|
8614 | 467 |
! |
468 |
||
469 |
pastEndRead |
|
470 |
"someone tried to read after the end of the stream. |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
471 |
If signalAtEnd == true, raise a signal. |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
472 |
If it is false, return nil. |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
473 |
Otherwise raise a notification, which is ignored if not handled; |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
474 |
otherwise return nil." |
8614 | 475 |
|
13380 | 476 |
|shouldSignalAtEnd| |
477 |
||
478 |
shouldSignalAtEnd := self signalAtEnd. |
|
479 |
||
480 |
shouldSignalAtEnd == true ifTrue:[ |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
481 |
"raise - a hard error..." |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
482 |
^ EndOfStreamError raiseRequestFrom:self |
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
483 |
]. |
13380 | 484 |
shouldSignalAtEnd == false ifTrue:[ |
8515 | 485 |
"never raise ..." |
486 |
^ nil |
|
1401 | 487 |
]. |
488 |
||
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
489 |
"EndOfStreamNotification is ignored, if there is no handler. |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
490 |
In this case, nil is returned" |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
491 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
492 |
^ EndOfStreamNotification raiseRequestFrom:self |
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
493 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
494 |
|
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
495 |
" ... no handler, no raise |
3591 | 496 |
|s| |
497 |
||
498 |
s := '12' readStream. |
|
499 |
Transcript showCR:s next. |
|
500 |
Transcript showCR:s next. |
|
501 |
Transcript showCR:s next. |
|
502 |
Transcript showCR:s next. |
|
503 |
" |
|
504 |
||
505 |
"... raise error if handled. |
|
506 |
|s| |
|
507 |
||
508 |
s := '12' readStream. |
|
8992
0feb5e68e5a7
Raise EndOfStreamError when signalAtEnd: is set to true
Stefan Vogel <sv@exept.de>
parents:
8988
diff
changeset
|
509 |
EndOfStreamNotification handle:[:ex | |
8515 | 510 |
Transcript showCR:'end reached'. |
511 |
ex return |
|
3591 | 512 |
] do:[ |
8515 | 513 |
Transcript showCR:s next. |
514 |
Transcript showCR:s next. |
|
515 |
Transcript showCR:s next. |
|
516 |
Transcript showCR:s next. |
|
3591 | 517 |
] |
518 |
" |
|
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
519 |
|
3591 | 520 |
"force raise (useful for debugging): |
521 |
|s| |
|
522 |
||
523 |
s := '12' readStream. |
|
524 |
s signalAtEnd:true. |
|
525 |
Transcript showCR:s next. |
|
526 |
Transcript showCR:s next. |
|
527 |
Transcript showCR:s next. |
|
528 |
Transcript showCR:s next. |
|
529 |
" |
|
530 |
||
531 |
||
532 |
"force no-raise (useful for compatibility with other systems): |
|
533 |
|s| |
|
534 |
||
535 |
s := '12' readStream. |
|
536 |
s signalAtEnd:false. |
|
537 |
Stream endOfStreamSignal handle:[:ex | |
|
8515 | 538 |
Transcript showCR:'end reached'. |
539 |
ex return |
|
3591 | 540 |
] do:[ |
8515 | 541 |
Transcript showCR:s next. |
542 |
Transcript showCR:s next. |
|
543 |
Transcript showCR:s next. |
|
544 |
Transcript showCR:s next. |
|
3591 | 545 |
] |
546 |
" |
|
547 |
||
548 |
"Modified: / 16.6.1998 / 16:04:13 / cg" |
|
1401 | 549 |
! ! |
550 |
||
611 | 551 |
!Stream methodsFor:'misc'! |
552 |
||
553 |
binary |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
554 |
"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
|
555 |
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
|
556 |
byte-valued integers respectively. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
557 |
Ignored here, but added to make internalStreams protocol compatible |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
558 |
with externalStreams." |
611 | 559 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
560 |
"Modified: 15.5.1996 / 17:38:36 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
561 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
562 |
|
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
563 |
blocking:aBoolean |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
564 |
"set non-blocking mode. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
565 |
Ignored, since internal streams never block" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
566 |
|
7498
9637184b10fe
ExternalStream>>blocking: returns previous blocking status
Stefan Vogel <sv@exept.de>
parents:
7497
diff
changeset
|
567 |
^ false. |
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
568 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
569 |
|
8507
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
570 |
eolMode:aSymbol |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
571 |
"Ignored here, but added to make internalStreams protocol compatible |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
572 |
with externalStreams." |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
573 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
574 |
|
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
575 |
lineEndCRLF |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
576 |
"Ignored here, but added to make internalStreams protocol compatible |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
577 |
with externalStreams." |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
578 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
579 |
|
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
580 |
lineEndTransparent |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
581 |
"Ignored here, but added to make internalStreams protocol compatible |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
582 |
with externalStreams." |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
583 |
! |
9d392516725c
more external stream compatibility
Stefan Vogel <sv@exept.de>
parents:
8338
diff
changeset
|
584 |
|
14434 | 585 |
stream |
586 |
"for compatibility with encodedStream" |
|
587 |
||
588 |
^ self |
|
589 |
! |
|
590 |
||
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
591 |
text |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
592 |
"switch to text mode. |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
593 |
Ignored here, but added to make internalStreams protocol compatible |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
594 |
with externalStreams." |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
595 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
596 |
"Modified: 15.5.1996 / 17:38:36 / cg" |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
597 |
"Created: 13.9.1996 / 18:33:26 / cg" |
611 | 598 |
! ! |
599 |
||
8768 | 600 |
!Stream methodsFor:'misc functions'! |
601 |
||
9001 | 602 |
copy:numberOfBytes into:outStream bufferSize:bufferSize |
603 |
"read from the receiver, and write all data up to count or the end to another stream. |
|
604 |
Return the number of bytes which have been transferred" |
|
605 |
||
606 |
|bufferSpecies buffer bytesWritten readCount writeCount count freeBuffer remaining| |
|
607 |
||
608 |
bytesWritten := 0. |
|
609 |
bufferSpecies := self contentsSpecies. |
|
610 |
bufferSpecies == ByteArray ifTrue:[ |
|
611 |
buffer:= ExternalBytes unprotectedNew:bufferSize. |
|
612 |
freeBuffer := true. |
|
613 |
] ifFalse:[ |
|
614 |
buffer := self contentsSpecies new:bufferSize. |
|
615 |
freeBuffer := false. |
|
616 |
]. |
|
617 |
||
618 |
remaining := numberOfBytes. |
|
619 |
"Note: atEnd will block if reading from an empty pipe or socket" |
|
620 |
[remaining ~~ 0 and:[self atEnd]] whileFalse:[ |
|
621 |
readCount := self nextAvailableBytes:(bufferSize min:remaining) into:buffer startingAt:1. |
|
622 |
readCount > 0 ifTrue:[ |
|
623 |
writeCount := 0. |
|
624 |
[ |
|
625 |
count := outStream nextPutBytes:readCount-writeCount |
|
626 |
from:buffer |
|
627 |
startingAt:writeCount+1. |
|
628 |
bytesWritten := bytesWritten + count. |
|
629 |
writeCount := writeCount + count. |
|
630 |
writeCount < readCount ifTrue:[ |
|
631 |
outStream writeWait. |
|
632 |
true. |
|
633 |
] ifFalse:[ |
|
634 |
false |
|
635 |
]. |
|
636 |
] whileTrue. |
|
637 |
remaining := remaining - writeCount. |
|
638 |
]. |
|
639 |
]. |
|
640 |
freeBuffer ifTrue:[ buffer free ]. |
|
641 |
^ bytesWritten |
|
642 |
||
643 |
" |
|
644 |
'hello world' readStream copyToEndInto:'/tmp/mist' asFilename writeStream. |
|
645 |
'hello world' readStream copyToEndInto:#[] writeStream. |
|
646 |
('/tmp/mist' asFilename readStream binary; yourself) copyToEndInto:#[] writeStream |
|
647 |
#[1 2 3 4 5 6 7] readStream copyToEndInto:'/tmp/mist' asFilename writeStream. |
|
648 |
#[1 2 3 4 5 6 7] readStream copyToEndInto:'' writeStream. |
|
649 |
||
650 |
" |
|
651 |
! |
|
652 |
||
11745 | 653 |
copyToEndFrom:inStream |
654 |
"read from inStream, and write all data up to the end to the receiver. |
|
655 |
Return the number of bytes which have been transferred. |
|
656 |
Same functionality as copyToEnd:, but reversed arg and receiver |
|
657 |
(useful in a cascade message of the writeStream)" |
|
658 |
||
659 |
^ inStream copyToEndInto:self |
|
660 |
! |
|
661 |
||
8768 | 662 |
copyToEndInto:outStream |
663 |
"read from the receiver, and write all data up to the end to another stream. |
|
664 |
Return the number of bytes which have been transferred" |
|
665 |
||
666 |
^ self copyToEndInto:outStream bufferSize:(128*1024) |
|
667 |
||
668 |
"/ data rate to USB2.0 stick (Win32): |
|
669 |
"/ 120 KB/s 8Kb SingleBuffer |
|
670 |
"/ 741 KB/s 64Kb SingleBuffer |
|
671 |
"/ 1345 KB/s 128Kb SingleBuffer |
|
672 |
"/ 2087 KB/s 256Kb SingleBuffer |
|
673 |
"/ 3573 KB/s 1024Kb SingleBuffer |
|
674 |
||
675 |
"/|t retVal| |
|
676 |
"/ |
|
677 |
"/t := Time millisecondsToRun:[ |
|
678 |
"/ retVal := self copyToEndInto:outStream bufferSize:(64*1024). |
|
679 |
"/]. |
|
680 |
"/ |
|
681 |
"/Transcript showCR:('%1 KB copied in %2s (%3 KB/s)' |
|
682 |
"/ bindWith:((retVal/1024)asFixedPoint:2) |
|
683 |
"/ with:((t/1000)asFixedPoint:2) |
|
684 |
"/ with:((retVal/1024/(t/1000))asFixedPoint:2)). |
|
685 |
"/^ retVal. |
|
686 |
"/ |
|
687 |
! |
|
688 |
||
689 |
copyToEndInto:outStream bufferSize:bufferSize |
|
690 |
"read from the receiver, and write all data up to the end to another stream. |
|
691 |
Return the number of bytes which have been transferred" |
|
692 |
||
693 |
|bufferSpecies buffer bytesWritten readCount writeCount count freeBuffer| |
|
694 |
||
695 |
bytesWritten := 0. |
|
696 |
bufferSpecies := self contentsSpecies. |
|
697 |
bufferSpecies == ByteArray ifTrue:[ |
|
698 |
buffer:= ExternalBytes unprotectedNew:bufferSize. |
|
699 |
freeBuffer := true. |
|
700 |
] ifFalse:[ |
|
701 |
buffer := self contentsSpecies new:bufferSize. |
|
702 |
freeBuffer := false. |
|
703 |
]. |
|
704 |
||
9001 | 705 |
"Note: atEnd will block if reading from an empty pipe or socket" |
8768 | 706 |
[self atEnd] whileFalse:[ |
707 |
readCount := self nextAvailableBytes:bufferSize into:buffer startingAt:1. |
|
708 |
readCount > 0 ifTrue:[ |
|
709 |
writeCount := 0. |
|
710 |
[ |
|
711 |
count := outStream nextPutBytes:readCount-writeCount |
|
712 |
from:buffer |
|
713 |
startingAt:writeCount+1. |
|
714 |
bytesWritten := bytesWritten + count. |
|
715 |
writeCount := writeCount + count. |
|
716 |
writeCount < readCount ifTrue:[ |
|
717 |
outStream writeWait. |
|
718 |
true. |
|
719 |
] ifFalse:[ |
|
720 |
false |
|
721 |
]. |
|
722 |
] whileTrue. |
|
9001 | 723 |
] |
8768 | 724 |
]. |
725 |
freeBuffer ifTrue:[ buffer free ]. |
|
726 |
^ bytesWritten |
|
727 |
||
728 |
" |
|
729 |
'hello world' readStream copyToEndInto:'/tmp/mist' asFilename writeStream. |
|
730 |
'hello world' readStream copyToEndInto:#[] writeStream. |
|
731 |
('/tmp/mist' asFilename readStream binary; yourself) copyToEndInto:#[] writeStream |
|
732 |
#[1 2 3 4 5 6 7] readStream copyToEndInto:'/tmp/mist' asFilename writeStream. |
|
733 |
#[1 2 3 4 5 6 7] readStream copyToEndInto:'' writeStream. |
|
734 |
||
735 |
" |
|
736 |
! ! |
|
737 |
||
611 | 738 |
!Stream methodsFor:'non homogenous reading'! |
739 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
740 |
nextAvailableBytes:numBytes into:aCollection startingAt:initialIndex |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
741 |
"for compatibility with ExternalStream" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
742 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
743 |
^ self nextBytes:numBytes into:aCollection startingAt:initialIndex |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
744 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7483
diff
changeset
|
745 |
|
8988
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
746 |
nextByte |
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
747 |
"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
|
748 |
- 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
|
749 |
|
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
750 |
^ self next |
8988
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
751 |
! |
2e82cf20dbbd
define #nextByte as subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
8970
diff
changeset
|
752 |
|
2714 | 753 |
nextBytes:count |
11249 | 754 |
"read the next count bytes and return it as a byteArray. |
755 |
If EOF is encountered while reading, a truncated byteArray is returned. |
|
756 |
If EOF is already reached before the first byte can be read, |
|
2714 | 757 |
nil is returned." |
758 |
||
759 |
|data n| |
|
760 |
||
7187 | 761 |
data := ByteArray uninitializedNew:count. |
2714 | 762 |
n := self nextBytes:count into:data startingAt:1. |
763 |
n ~~ count ifTrue:[ |
|
7187 | 764 |
n == 0 ifTrue:[ |
765 |
^ nil |
|
766 |
]. |
|
767 |
data := data copyTo:n |
|
2714 | 768 |
]. |
769 |
^ data |
|
770 |
||
3346 | 771 |
"Created: / 21.6.1997 / 11:18:57 / cg" |
772 |
"Modified: / 30.3.1998 / 18:04:58 / cg" |
|
2714 | 773 |
! |
774 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
775 |
nextBytes:count into:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
776 |
"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
|
777 |
bytes read. On EOF, 0 is returned. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
778 |
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
|
779 |
is raised if the connection is broken. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
780 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
781 |
The object must have non-pointer indexed instvars (i.e. it must be |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
782 |
a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
783 |
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
|
784 |
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
|
785 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
786 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
787 |
Warning: in general, you cannot use this method to pass data from other |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
788 |
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
|
789 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
790 |
^ self nextBytes:count into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
791 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
792 |
"Modified: 22.4.1997 / 10:41:39 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
793 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
794 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
795 |
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
|
796 |
"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
|
797 |
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
|
798 |
collection. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
799 |
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
|
800 |
The receiver must support reading of binary bytes. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
801 |
|
9001 | 802 |
Notice: this method is provided here for protocol completeness |
7506 | 803 |
with externalStreams - it is normally not used with other |
804 |
streams." |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
805 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
806 |
|n "{Class: SmallInteger }" |
12350
25846cf4f53e
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12134
diff
changeset
|
807 |
dstIndex binary b| |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
808 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
809 |
dstIndex := initialIndex. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
810 |
n := 0. |
7506 | 811 |
|
8815 | 812 |
binary := self isBinary. |
813 |
[self atEnd] whileFalse:[ |
|
814 |
n == numBytes ifTrue:[ |
|
815 |
^ n |
|
7506 | 816 |
]. |
8815 | 817 |
binary ifTrue:[ |
12375 | 818 |
b := self nextByte. |
8815 | 819 |
] ifFalse:[ |
12350
25846cf4f53e
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12134
diff
changeset
|
820 |
b := self next. |
25846cf4f53e
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12134
diff
changeset
|
821 |
b isInteger ifFalse:[ |
25846cf4f53e
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12134
diff
changeset
|
822 |
b := b asInteger |
25846cf4f53e
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12134
diff
changeset
|
823 |
]. |
7506 | 824 |
]. |
12374
5e10abdb6366
changed: #nextBytes:into:startingAt:
Claus Gittinger <cg@exept.de>
parents:
12350
diff
changeset
|
825 |
aCollection byteAt:dstIndex put:b. |
8815 | 826 |
dstIndex := dstIndex + 1. |
827 |
n := n + 1. |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
828 |
]. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
829 |
^ n |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
830 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
831 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
832 |
|s n buffer| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
833 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
834 |
buffer := ByteArray new:10. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
835 |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
836 |
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
|
837 |
s next:3. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
838 |
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
|
839 |
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
|
840 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
841 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
842 |
"Modified: 22.4.1997 / 10:43:08 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
843 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
844 |
|
2587 | 845 |
nextBytes:numBytes into:aCollection startingAt:initialIndex blockSize:blockSize |
846 |
"like nextBytes:into:startingAt:, but read in blocks of the given size. |
|
847 |
This leads to better beahvior when reading large chunks from a slow device, |
|
848 |
such as a cdrom drive (since a single unix-read is not interruptable)." |
|
849 |
||
850 |
|nR oR n| |
|
851 |
||
852 |
nR := numBytes. |
|
853 |
oR := initialIndex. |
|
854 |
[nR > 0] whileTrue:[ |
|
3154 | 855 |
n := nR. |
856 |
n > blockSize ifTrue:[n := blockSize]. |
|
857 |
n := self nextBytes:n into:aCollection startingAt:oR. |
|
858 |
n == 0 ifTrue:[ |
|
859 |
^ numBytes - nR |
|
860 |
]. |
|
861 |
oR := oR + n. |
|
862 |
nR := nR - n |
|
2587 | 863 |
]. |
864 |
^ numBytes |
|
865 |
||
866 |
"Created: 24.4.1997 / 21:09:34 / cg" |
|
867 |
"Modified: 24.4.1997 / 21:19:50 / cg" |
|
868 |
! |
|
869 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
870 |
nextBytesInto:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
871 |
"read bytes into an object, regardless of binary/text mode. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
872 |
The number of bytes to read is defined by the objects size. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
873 |
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
|
874 |
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
|
875 |
is raised if the connection is broken. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
876 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
877 |
The object to read into must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
878 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
879 |
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
|
880 |
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
|
881 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
882 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
883 |
Warning: in general, you cannot use this method to pass data from other |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
884 |
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
|
885 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
886 |
^ self nextBytes:(anObject byteSize) into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
887 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
888 |
" to read 100 bytes from a stream: |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
889 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
890 |
|b aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
891 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
892 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
893 |
b := ByteArray new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
894 |
aStream nextBytesInto:b. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
895 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
896 |
b inspect |
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 |
|
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 |
|s aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
901 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
902 |
s := String new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
903 |
aStream nextBytesInto:s. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
904 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
905 |
s inspect |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
906 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
907 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
908 |
"Modified: 22.4.1997 / 10:42:02 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
909 |
"Created: 22.4.1997 / 10:42:26 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
910 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
911 |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
912 |
nextHyperMSB:msbFlag |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
913 |
"return a signed hyper (8 bytes) from the stream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
914 |
The receiver must support reading of binary bytes. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
915 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
916 |
The msbFlag argument controls if the integer is to be read with |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
917 |
most-significant-byte-first (true) or least-first (false). |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
918 |
This interface is provided to allow talking to external programs, |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
919 |
where its known that the byte order is some definite one. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
920 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
921 |
order, please use the corresponding xxxNet methods, which use a standard |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
922 |
network byte order." |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
923 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
924 |
|uval| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
925 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
926 |
uval := self nextUnsignedHyperMSB:msbFlag. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
927 |
"change from unsigned 0..FF..FF to signed -80..00..7FF..FF" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
928 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
929 |
uval >= 16r8000000000000000 ifTrue:[ |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
930 |
^ uval - 16r10000000000000000 |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
931 |
]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
932 |
^ uval |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
933 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
934 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
935 |
|bytes s| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
936 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
937 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
938 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
939 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
940 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
941 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
942 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
943 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
944 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
945 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
946 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
947 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
948 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
949 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
950 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
951 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
952 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
953 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
954 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
955 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
956 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
957 |
Transcript showCR:(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
958 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
959 |
Transcript showCR:(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
960 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
961 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
962 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
963 |
! |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
964 |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
965 |
nextIEEEDouble |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
966 |
"read 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
|
967 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
968 |
^ Float readBinaryIEEEDoubleFrom:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
969 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
970 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
971 |
nextIEEESingle |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
972 |
"read 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
|
973 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
974 |
^ ShortFloat readBinaryIEEESingleFrom:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
975 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
976 |
|
611 | 977 |
nextLongMSB:msbFlag |
978 |
"return a signed long (4 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
979 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
980 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
981 |
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
|
982 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
983 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
984 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
985 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
986 |
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
|
987 |
network byte order." |
611 | 988 |
|
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
989 |
|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
|
990 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
991 |
b1 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
992 |
b2 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
993 |
b3 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
994 |
b4 := self nextByte. |
611 | 995 |
|
996 |
msbFlag ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
997 |
"most significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
998 |
uval := (b1 bitShift:8) bitOr:b2. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
999 |
uval := (uval bitShift:8) bitOr:b3. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1000 |
val := (uval bitShift:8) bitOr:b4. |
611 | 1001 |
] ifFalse:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1002 |
"least significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1003 |
uval := (b4 bitShift:8) bitOr:b3. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1004 |
uval := (uval bitShift:8) bitOr:b2. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1005 |
val := (uval bitShift:8) bitOr:b1. |
611 | 1006 |
]. |
1007 |
"change from unsigned 0..FFFFFFFF to signed -80000000..7FFFFFFF" |
|
1008 |
||
3176 | 1009 |
val >= 16r80000000 ifTrue:[ |
1010 |
^ val - 16r100000000 |
|
1011 |
]. |
|
1012 |
^ val |
|
1013 |
||
1014 |
" |
|
1015 |
|bytes s| |
|
1016 |
||
1017 |
bytes := #[16rFF 16rFF 16rFF 16rFF]. |
|
1018 |
s := bytes readStream. |
|
1019 |
Transcript showCR:(s nextLongMSB:true). |
|
1020 |
s reset. |
|
1021 |
Transcript showCR:(s nextLongMSB:false). |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1022 |
|
3176 | 1023 |
bytes := #[16r12 16r34 16r56 16r78]. |
1024 |
s := bytes readStream. |
|
1025 |
Transcript showCR:(s nextLongMSB:true). |
|
1026 |
s reset. |
|
1027 |
Transcript showCR:(s nextLongMSB:false). |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1028 |
|
3176 | 1029 |
bytes := #[16r89 16rab 16rcd 16ref]. |
1030 |
s := bytes readStream. |
|
1031 |
Transcript showCR:(s nextLongMSB:true). |
|
1032 |
s reset. |
|
1033 |
Transcript showCR:(s nextLongMSB:false). |
|
1034 |
" |
|
1035 |
||
1036 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
611 | 1037 |
! |
1038 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1039 |
nextLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1040 |
"return a signed 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
|
1041 |
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
|
1042 |
|
8894
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1043 |
^ self nextLongMSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1044 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1045 |
"Created: 10.1.1996 / 19:49:28 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1046 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1047 |
|
12129 | 1048 |
nextNumber:numBytes |
611 | 1049 |
"Return the next n bytes as a positive Integer; bytes are taken msb-first." |
1050 |
||
12129 | 1051 |
^ self nextUnsigned:numBytes MSB:true |
611 | 1052 |
! |
1053 |
||
1054 |
nextShortMSB:msbFlag |
|
1055 |
"return a signed short (2 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1056 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1057 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1058 |
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
|
1059 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1060 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1061 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1062 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1063 |
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
|
1064 |
network byte order." |
611 | 1065 |
|
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1066 |
|b1 b2 uval "{ Class: SmallInteger }"| |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1067 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1068 |
b1 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1069 |
b2 := self nextByte. |
611 | 1070 |
|
1071 |
msbFlag ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1072 |
"most significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1073 |
uval := b1 bitShift:8. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1074 |
uval := uval bitOr:b2. |
611 | 1075 |
] ifFalse:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1076 |
"least significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1077 |
uval := b2 bitShift:8. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1078 |
uval := uval bitOr:b1. |
611 | 1079 |
]. |
1080 |
"change from unsigned 0..FFFF to signed -8000..7FFF" |
|
1081 |
uval >= 16r8000 ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1082 |
^ uval - 16r10000 |
611 | 1083 |
]. |
1084 |
^ uval |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1085 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1086 |
"Modified: 11.7.1996 / 10:07:04 / cg" |
611 | 1087 |
! |
1088 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1089 |
nextShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1090 |
"return a signed 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
|
1091 |
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
|
1092 |
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
|
1093 |
|
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1094 |
^ self nextShortMSB:true |
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1095 |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1096 |
"Created: 10.1.1996 / 19:49:41 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1097 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1098 |
|
4588 | 1099 |
nextSignedByte |
1100 |
"return a signed byte (-128..127) from the stream. |
|
1101 |
The receiver must support reading of binary bytes." |
|
1102 |
||
1103 |
|uval "{ Class: SmallInteger }"| |
|
1104 |
||
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1105 |
uval := self nextByte. |
4588 | 1106 |
"change from unsigned 0..FF to signed -80..7F" |
1107 |
uval >= 16r80 ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1108 |
^ uval - 16r100 |
4588 | 1109 |
]. |
1110 |
^ uval |
|
1111 |
||
1112 |
" |
|
1113 |
#[16rFF 16r80 16r7F 16r01] readStream nextSignedByte |
|
1114 |
" |
|
1115 |
! |
|
1116 |
||
12129 | 1117 |
nextUnsigned:numBytes MSB:msbFlag |
1118 |
"return a numBytes-sized unsigned (numBytes bytes) from the stream as an Integer. |
|
1119 |
The receiver must support reading of binary bytes. |
|
1120 |
||
1121 |
The msbFlag argument controls if the integer is to be read with |
|
1122 |
most-significant-byte-first (true) or least-first (false). |
|
1123 |
This interface is provided to allow talking to external programs, |
|
1124 |
where its known that the byte order is some definite one. |
|
1125 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
|
1126 |
order, please use the corresponding xxxNet methods, which use a standard |
|
1127 |
network byte order." |
|
1128 |
||
1129 |
|val shift| |
|
1130 |
||
1131 |
"claus: this method is central in binaryStorage - |
|
1132 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
1133 |
||
1134 |
numBytes == 1 ifTrue:[ |
|
1135 |
^ self nextByte |
|
1136 |
]. |
|
1137 |
numBytes == 2 ifTrue:[ |
|
1138 |
^ self nextUnsignedShortMSB:msbFlag |
|
1139 |
]. |
|
1140 |
numBytes == 3 ifTrue:[ |
|
1141 |
val := self nextUnsignedShortMSB:msbFlag. |
|
1142 |
msbFlag ifTrue:[ |
|
1143 |
^ (val bitShift:8) + self nextByte |
|
1144 |
]. |
|
1145 |
^ val + (self nextByte bitShift:16) |
|
1146 |
]. |
|
1147 |
numBytes == 4 ifTrue:[ |
|
1148 |
^ self nextUnsignedLongMSB:msbFlag |
|
1149 |
]. |
|
1150 |
||
1151 |
val := 0. |
|
1152 |
msbFlag ifTrue:[ |
|
1153 |
numBytes timesRepeat:[ |
|
1154 |
val := (val bitShift:8) + self nextByte |
|
1155 |
]. |
|
1156 |
] ifFalse:[ |
|
1157 |
shift := 0. |
|
1158 |
numBytes timesRepeat:[ |
|
1159 |
val := val + (self nextByte bitShift:shift). |
|
1160 |
shift := shift + 8. |
|
1161 |
]. |
|
1162 |
]. |
|
1163 |
^ val |
|
1164 |
||
1165 |
" |
|
1166 |
|s| |
|
1167 |
||
1168 |
s := #[ 16r01 16r02 16r03 16r04 16r05 ] readStream. |
|
1169 |
(s nextUnsigned:3 MSB:true) hexPrintString. |
|
1170 |
||
1171 |
s := #[ 16r01 16r02 16r03 16r04 16r05 ] readStream. |
|
1172 |
(s nextUnsigned:3 MSB:false) hexPrintString. |
|
1173 |
" |
|
1174 |
! |
|
1175 |
||
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1176 |
nextUnsignedHyperMSB:msbFlag |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1177 |
"return an unsigned hyper (8 bytes) from the stream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1178 |
The receiver must support reading of binary bytes. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1179 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1180 |
The msbFlag argument controls if the integer is to be read with |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1181 |
most-significant-byte-first (true) or least-first (false). |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1182 |
This interface is provided to allow talking to external programs, |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1183 |
where its known that the byte order is some definite one. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1184 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1185 |
order, please use the corresponding xxxNet methods, which use a standard |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1186 |
network byte order." |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1187 |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
1188 |
|bytes uval t| |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1189 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1190 |
bytes := self nextBytes:8. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1191 |
uval := 0. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1192 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1193 |
msbFlag ifTrue:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1194 |
"most significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1195 |
1 to:8 do:[:i | |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1196 |
t := (uval bitShift:8). |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1197 |
uval := t bitOr:(bytes at:i). |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1198 |
]. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1199 |
] ifFalse:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1200 |
"least significant first" |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1201 |
8 to:1 by:-1 do:[:i | |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1202 |
t := (uval bitShift:8). |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1203 |
uval := t bitOr:(bytes at:i). |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1204 |
]. |
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1205 |
]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1206 |
^ uval |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1207 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1208 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1209 |
|bytes s| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1210 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1211 |
bytes := #[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1212 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1213 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1214 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1215 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1216 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1217 |
bytes := #[16r10 16r00 16r00 16r00 16r00 16r00 16r00 16r00]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1218 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1219 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1220 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1221 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1222 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1223 |
bytes := #[16r12 16r34 16r56 16r78 16r9a 16rbc 16rde 16rf0]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1224 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1225 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1226 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1227 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1228 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1229 |
bytes := #[16rFe 16rdc 16rba 16r98 16r76 16r54 16r32 16r10]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1230 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1231 |
Transcript showCR:(s nextUnsignedHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1232 |
s reset. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1233 |
Transcript showCR:(s nextUnsignedHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1234 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1235 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1236 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1237 |
! |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1238 |
|
611 | 1239 |
nextUnsignedLongMSB:msbFlag |
1240 |
"return an unsigned long (4 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1241 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1242 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1243 |
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
|
1244 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1245 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1246 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1247 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1248 |
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
|
1249 |
network byte order." |
611 | 1250 |
|
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1251 |
|b1 b2 b3 b4 val| |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1252 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1253 |
b1 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1254 |
b2 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1255 |
b3 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1256 |
b4 := self nextByte. |
611 | 1257 |
|
1258 |
msbFlag ifTrue:[ |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1259 |
val := b1. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1260 |
val := (val bitShift:8) bitOr:b2. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1261 |
val := (val bitShift:8) bitOr:b3. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1262 |
val := (val * 256) + b4. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1263 |
^ val |
611 | 1264 |
]. |
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1265 |
val := b4. |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1266 |
val := (val bitShift:8) bitOr:b3. |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1267 |
val := (val bitShift:8) bitOr:b2. |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1268 |
val := (val * 256) + b1. |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1269 |
^ val |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1270 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1271 |
"Modified: 11.7.1996 / 10:07:13 / cg" |
611 | 1272 |
! |
1273 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1274 |
nextUnsignedLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1275 |
"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
|
1276 |
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
|
1277 |
|
8894
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1278 |
^ self nextUnsignedLongMSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1279 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1280 |
"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
|
1281 |
"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
|
1282 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1283 |
|
611 | 1284 |
nextUnsignedShortMSB:msbFlag |
1285 |
"return an unsigned short (2 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1286 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1287 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1288 |
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
|
1289 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1290 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1291 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1292 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1293 |
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
|
1294 |
network byte order." |
611 | 1295 |
|
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1296 |
|b1 b2| |
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1297 |
|
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1298 |
b1 := self nextByte. |
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1299 |
b2 := self nextByte. |
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1300 |
|
611 | 1301 |
msbFlag ifTrue:[ |
9266
3563ddfd55d2
use nextByte to access bytes (for InternalStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
9070
diff
changeset
|
1302 |
^ (b1 bitShift:8) bitOr:b2 |
611 | 1303 |
]. |
6355
fb179369bd9f
#nextUnsignedLong:MSB: was wrong for lsb case
Claus Gittinger <cg@exept.de>
parents:
6348
diff
changeset
|
1304 |
^ (b2 bitShift:8) bitOr:b1 |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1305 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1306 |
"Modified: 11.7.1996 / 10:07:20 / cg" |
611 | 1307 |
! |
1308 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1309 |
nextUnsignedShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1310 |
"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
|
1311 |
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
|
1312 |
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
|
1313 |
|
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1314 |
^ self nextUnsignedShortMSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1315 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1316 |
"Created: 10.1.1996 / 19:50:02 / cg" |
611 | 1317 |
! ! |
1318 |
||
1319 |
!Stream methodsFor:'non homogenous writing'! |
|
1320 |
||
1321 |
nextLongPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1322 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1323 |
Write the argument, aNumber as a long (four bytes). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1324 |
The most significant byte is sent first." |
611 | 1325 |
|
1326 |
^ self nextPutLong:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1327 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1328 |
"Modified: 10.1.1996 / 19:38:54 / cg" |
611 | 1329 |
! |
1330 |
||
1331 |
nextNumber:n put:v |
|
1332 |
"Append to the receiver the argument, v, which is a positive Integer, |
|
1333 |
as the next n bytes. Bytes are written msb first. |
|
1334 |
Possibly pad with leading zeros. |
|
1335 |
The receiver must support writing of binary bytes." |
|
1336 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1337 |
|vlen "{ Class: SmallInteger }" |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1338 |
i "{ Class: SmallInteger }"| |
611 | 1339 |
|
1340 |
"claus: this method is central in binaryStorage - |
|
1341 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
1342 |
||
1343 |
v class == SmallInteger ifTrue:[ "- this is a hint to stc" |
|
9407 | 1344 |
n == 1 ifTrue:[ |
1345 |
(v between:0 and:16rFF) ifTrue:[ |
|
1346 |
self nextPutByte:v. |
|
1347 |
^ self |
|
1348 |
]. |
|
1349 |
]. |
|
1350 |
n == 2 ifTrue:[ |
|
1351 |
(v between:0 and:16rFFFF) ifTrue:[ |
|
1352 |
self nextPutByte:(v bitShift:-8); nextPutByte:(v bitAnd:16rFF). |
|
1353 |
^ self |
|
1354 |
]. |
|
1355 |
]. |
|
1356 |
n == 3 ifTrue:[ |
|
1357 |
(v between:0 and:16rFFFFFF) ifTrue:[ |
|
1358 |
self nextPutByte:((v bitShift:-16) bitAnd:16rFF). |
|
1359 |
self nextPutByte:((v bitShift:-8) bitAnd:16rFF). |
|
1360 |
self nextPutByte:(v bitAnd:16rFF). |
|
1361 |
^ self |
|
1362 |
]. |
|
1363 |
]. |
|
1364 |
n == 4 ifTrue:[ |
|
1365 |
(v >= 0) ifTrue:[ |
|
1366 |
self nextPutByte:((v bitShift:-24) bitAnd:16rFF). |
|
1367 |
self nextPutByte:((v bitShift:-16) bitAnd:16rFF). |
|
1368 |
self nextPutByte:((v bitShift:-8) bitAnd:16rFF). |
|
1369 |
self nextPutByte:(v bitAnd:16rFF). |
|
1370 |
^ self |
|
1371 |
]. |
|
1372 |
]. |
|
611 | 1373 |
]. |
1374 |
||
1375 |
" |
|
1376 |
arbitrary long |
|
1377 |
" |
|
1378 |
n < (vlen := v digitLength) ifTrue: [ |
|
9407 | 1379 |
" |
1380 |
the number is too big to be repesented in n bytes |
|
1381 |
" |
|
1382 |
self error:'number too big' |
|
611 | 1383 |
]. |
1384 |
||
1385 |
"pad with leading zeros" |
|
1386 |
i := n. |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1387 |
[i > vlen] whileTrue:[ |
9407 | 1388 |
self nextPutByte:0. |
1389 |
i := i - 1 |
|
611 | 1390 |
]. |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1391 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1392 |
i == 1 ifTrue:[ |
9407 | 1393 |
^ self nextPutByte:v |
611 | 1394 |
]. |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1395 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1396 |
[i > 0] whileTrue:[ |
9407 | 1397 |
self nextPutByte:(v digitAt:i). |
1398 |
i := i - 1 |
|
611 | 1399 |
] |
9407 | 1400 |
|
1401 |
"Modified: / 22-06-2006 / 11:31:13 / fm" |
|
611 | 1402 |
! |
1403 |
||
11322 | 1404 |
nextPutAllUtf8:aString |
1405 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
1406 |
||
1407 |
aString do:[:eachCharacter| |
|
1408 |
self nextPutUtf8:eachCharacter. |
|
1409 |
]. |
|
1410 |
! |
|
1411 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1412 |
nextPutByte:aByteValue |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1413 |
"write a byte. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1414 |
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
|
1415 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1416 |
self nextPut:aByteValue |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1417 |
|
9407 | 1418 |
"Created: / 22-04-1997 / 10:43:55 / cg" |
1419 |
"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
|
1420 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1421 |
|
12093 | 1422 |
nextPutBytes:anObject |
1423 |
"write bytes from an object; the number of bytes is defined by |
|
1424 |
the objects size. |
|
1425 |
Return the number of bytes written or nil on error. |
|
1426 |
The object must have non-pointer indexed instvars |
|
1427 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
1428 |
Use with care - non object oriented i/o. |
|
1429 |
Warning: in general, you cannot use this method to pass non-byte data to other |
|
1430 |
architectures since it does not care for byte order or float representation." |
|
1431 |
||
1432 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
|
1433 |
||
1434 |
"Created: 22.4.1997 / 10:44:18 / cg" |
|
1435 |
! |
|
1436 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1437 |
nextPutBytes:count from:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1438 |
"write count bytes from an object. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1439 |
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
|
1440 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1441 |
(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
|
1442 |
Use with care - non object oriented i/o. |
12093 | 1443 |
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
|
1444 |
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
|
1445 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1446 |
^ self nextPutBytes:count from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1447 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1448 |
"Created: 22.4.1997 / 10:43:59 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1449 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1450 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1451 |
nextPutBytes:count from:anObject startingAt:start |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1452 |
"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
|
1453 |
Return the number of bytes written. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1454 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1455 |
(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
|
1456 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1457 |
This is provided for compatibility with externalStream; |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1458 |
to support binary storage" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1459 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1460 |
|idx| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1461 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1462 |
idx := start. |
7506 | 1463 |
self isBinary ifTrue:[ |
1464 |
1 to:count do:[:i | |
|
1465 |
self nextPutByte:(anObject byteAt:idx). |
|
1466 |
idx := idx + 1 |
|
1467 |
]. |
|
1468 |
] ifFalse:[ |
|
1469 |
1 to:count do:[:i | |
|
1470 |
self nextPut:(anObject at:idx). |
|
1471 |
idx := idx + 1 |
|
1472 |
]. |
|
1473 |
]. |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1474 |
^ count |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1475 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1476 |
"Created: 22.4.1997 / 10:44:09 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1477 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1478 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1479 |
nextPutBytesFrom:anObject |
12093 | 1480 |
"write bytes from an object; the number of bytes is defined by the objects size. |
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1481 |
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
|
1482 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1483 |
(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
|
1484 |
Use with care - non object oriented i/o. |
12093 | 1485 |
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
|
1486 |
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
|
1487 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1488 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1489 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1490 |
"Created: 22.4.1997 / 10:44:18 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1491 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
1492 |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1493 |
nextPutHyper:aNumber MSB:msbFlag |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1494 |
"Write the argument, aNumber as a hyper (8 bytes). |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1495 |
If msbFlag is true, data is written most-significant byte first; |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1496 |
otherwise least first. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1497 |
Returns the receiver on ok, nil on error. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1498 |
The receiver must support writing of binary bytes. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1499 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1500 |
This interface is provided to allow talking to external programs, |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1501 |
where its known that the byte order is some definite one. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1502 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1503 |
order, please use the corresponding xxxNet methods, which use a standard |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1504 |
network byte order." |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1505 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1506 |
msbFlag ifTrue:[ |
9407 | 1507 |
1 to:8 do:[:i | |
1508 |
self nextPutByte:(aNumber digitByteAt:8+1-i) |
|
1509 |
]. |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1510 |
] ifFalse:[ |
9407 | 1511 |
1 to:8 do:[:i | |
1512 |
self nextPutByte:(aNumber digitByteAt:i) |
|
1513 |
]. |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1514 |
]. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1515 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1516 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1517 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1518 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1519 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1520 |
s nextPutHyper:16r123456789abcdef0 MSB:false. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1521 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1522 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1523 |
(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1524 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1525 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1526 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1527 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1528 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1529 |
s nextPutHyper:16r123456789abcdef0 MSB:true. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1530 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1531 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1532 |
(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1533 |
. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1534 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1535 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1536 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1537 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1538 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1539 |
s nextPutHyper:16r-8000000000000000 MSB:true. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1540 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1541 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1542 |
(s nextHyperMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1543 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1544 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1545 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1546 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1547 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1548 |
s nextPutHyper:16r-8000000000000000 MSB:false. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1549 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1550 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1551 |
(s nextHyperMSB:false) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1552 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1553 |
|
9407 | 1554 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
1555 |
"Modified: / 22-06-2006 / 11:31:37 / fm" |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1556 |
! |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1557 |
|
11616
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1558 |
nextPutIEEEDouble:aFloat |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1559 |
"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
|
1560 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1561 |
Float storeBinaryIEEEDouble:aFloat on:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1562 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1563 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1564 |
nextPutIEEESingle:aFloat |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1565 |
"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
|
1566 |
|
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1567 |
ShortFloat storeBinaryIEEESingle:aFloat on:self |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1568 |
! |
0ca41183ee3e
added IEESingle and IEEDouble readers and writers
Claus Gittinger <cg@exept.de>
parents:
11322
diff
changeset
|
1569 |
|
611 | 1570 |
nextPutLong:aNumber MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1571 |
"Write the argument, aNumber as a long (four bytes). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1572 |
If msbFlag is true, data is written most-significant byte first; |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1573 |
otherwise least first. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1574 |
Returns the receiver on ok, nil on error. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1575 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1576 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1577 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1578 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1579 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1580 |
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
|
1581 |
network byte order." |
611 | 1582 |
|
5960 | 1583 |
|hh hl lh ll b1 b2 b3 b4| |
1584 |
||
1585 |
ll := aNumber digitByteAt:1. |
|
1586 |
lh := aNumber digitByteAt:2. |
|
1587 |
hl := aNumber digitByteAt:3. |
|
1588 |
hh := aNumber digitByteAt:4. |
|
611 | 1589 |
msbFlag ifTrue:[ |
9407 | 1590 |
"high byte first" |
1591 |
b1 := hh. |
|
1592 |
b2 := hl. |
|
1593 |
b3 := lh. |
|
1594 |
b4 := ll. |
|
2332 | 1595 |
] ifFalse:[ |
9407 | 1596 |
"low word first" |
1597 |
b1 := ll. |
|
1598 |
b2 := lh. |
|
1599 |
b3 := hl. |
|
1600 |
b4 := hh. |
|
611 | 1601 |
]. |
9407 | 1602 |
self nextPutByte:b1. |
1603 |
self nextPutByte:b2. |
|
1604 |
self nextPutByte:b3. |
|
1605 |
self nextPutByte:b4. |
|
5960 | 1606 |
|
1607 |
" |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1608 |
|s bytes| |
5960 | 1609 |
|
1610 |
s := #[] writeStream. |
|
1611 |
s nextPutLong:16r12345678 MSB:false. |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1612 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1613 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1614 |
(s nextLongMSB:false) hexPrintString. |
5960 | 1615 |
" |
1616 |
" |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1617 |
|s bytes| |
5960 | 1618 |
|
1619 |
s := #[] writeStream. |
|
1620 |
s nextPutLong:16r12345678 MSB:true. |
|
6360
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1621 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1622 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1623 |
(s nextLongMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1624 |
. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1625 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1626 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1627 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1628 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1629 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1630 |
s nextPutLong:16r-80000000 MSB:true. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1631 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1632 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1633 |
(s nextLongMSB:true) hexPrintString. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1634 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1635 |
" |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1636 |
|s bytes| |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1637 |
|
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1638 |
s := #[] writeStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1639 |
s nextPutLong:16r-80000000 MSB:false. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1640 |
bytes := s contents. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1641 |
s := bytes readStream. |
9bb87d3988c5
read/write of hypers (8byte ints)
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
1642 |
(s nextLongMSB:false) hexPrintString. |
5960 | 1643 |
" |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1644 |
|
9407 | 1645 |
"Modified: / 01-11-1997 / 18:30:52 / cg" |
1646 |
"Modified: / 22-06-2006 / 11:31:43 / fm" |
|
611 | 1647 |
! |
1648 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1649 |
nextPutLongNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1650 |
"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
|
1651 |
Returns the receiver on ok, nil on error. |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1652 |
The receiver must support writing of binary bytes." |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1653 |
|
8894
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1654 |
^ self nextPutLong:aNumber MSB:true |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1655 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1656 |
"Modified: 10.1.1996 / 19:47:10 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1657 |
"Created: 10.1.1996 / 19:50:23 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1658 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1659 |
|
611 | 1660 |
nextPutShort:aNumber MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1661 |
"Write the argument, aNumber as a short (two bytes). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1662 |
If msbFlag is true, data is written most-significant byte first; |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1663 |
otherwise least first. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1664 |
Returns the receiver on ok, nil on error. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1665 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1666 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1667 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1668 |
where its known that the byte order is some definite one. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1669 |
If you dont care (i.e. talk to other smalltalks) or you can control the |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1670 |
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
|
1671 |
network byte order." |
611 | 1672 |
|
2332 | 1673 |
|iNum "{ Class: SmallInteger }" hi lo b1 b2| |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1674 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
1675 |
iNum := aNumber. |
5960 | 1676 |
lo := iNum digitByteAt:1. |
1677 |
hi := iNum digitByteAt:2. |
|
611 | 1678 |
msbFlag ifTrue:[ |
9407 | 1679 |
"high word first" |
1680 |
b1 := hi. |
|
1681 |
b2 := lo. |
|
2332 | 1682 |
] ifFalse:[ |
9407 | 1683 |
"low word first" |
1684 |
b1 := lo. |
|
1685 |
b2 := hi. |
|
611 | 1686 |
]. |
9407 | 1687 |
self nextPutByte:b1. |
1688 |
self nextPutByte:b2. |
|
5960 | 1689 |
|
1690 |
" |
|
1691 |
|s| |
|
1692 |
||
1693 |
s := #[] writeStream. |
|
1694 |
s nextPutShort:16r1234 MSB:false. |
|
1695 |
s contents. |
|
1696 |
" |
|
1697 |
" |
|
1698 |
|s| |
|
1699 |
||
1700 |
s := #[] writeStream. |
|
1701 |
s nextPutShort:16r1234 MSB:true. |
|
1702 |
s contents. |
|
1703 |
" |
|
9407 | 1704 |
|
1705 |
"Modified: / 22-06-2006 / 11:30:26 / fm" |
|
611 | 1706 |
! |
1707 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1708 |
nextPutShortNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1709 |
"Write the argument, aNumber as a short (two bytes) in the network byte order. |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1710 |
Returns the receiver on ok, nil on error. |
8894
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1711 |
The receiver must support writing of binary bytes. |
63cd83aa44e8
No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents:
8815
diff
changeset
|
1712 |
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
|
1713 |
|
8970 | 1714 |
^ self nextPutShort:aNumber MSB:true. |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1715 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1716 |
"Created: 10.1.1996 / 19:50:33 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1717 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1718 |
|
11322 | 1719 |
nextPutUtf8:aCharacter |
1720 |
"append my UTF-8 representation to the argument, aStream. |
|
1721 |
Up to 31 bits can be encoded in up to 6 bytes. |
|
14593 | 1722 |
However, currently, characters are limited to 31 bits." |
11322 | 1723 |
|
1724 |
|codePoint b1 b2 b3 b4 b5 v| |
|
1725 |
||
1726 |
codePoint := aCharacter codePoint. |
|
1727 |
||
1728 |
codePoint <= 16r7F ifTrue:[ |
|
1729 |
self nextPut:aCharacter. |
|
1730 |
^ self. |
|
1731 |
]. |
|
1732 |
||
1733 |
b1 := Character codePoint:((codePoint bitAnd:16r3F) bitOr:2r10000000). |
|
1734 |
v := codePoint bitShift:-6. |
|
1735 |
v <= 16r1F ifTrue:[ |
|
1736 |
self nextPut:(Character value:(v bitOr:2r11000000)). |
|
1737 |
self nextPut:b1. |
|
1738 |
^ self. |
|
1739 |
]. |
|
1740 |
b2 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
1741 |
v := v bitShift:-6. |
|
1742 |
v <= 16r0F ifTrue:[ |
|
1743 |
self nextPut:(Character value:(v bitOr:2r11100000)). |
|
1744 |
self nextPut:b2; nextPut:b1. |
|
1745 |
^ self. |
|
1746 |
]. |
|
1747 |
b3 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
1748 |
v := v bitShift:-6. |
|
1749 |
v <= 16r07 ifTrue:[ |
|
1750 |
self nextPut:(Character value:(v bitOr:2r11110000)). |
|
1751 |
self nextPut:b3; nextPut:b2; nextPut:b1. |
|
1752 |
^ self. |
|
1753 |
]. |
|
1754 |
b4 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
1755 |
v := v bitShift:-6. |
|
1756 |
v <= 16r03 ifTrue:[ |
|
1757 |
self nextPut:(Character value:(v bitOr:2r11111000)). |
|
1758 |
self nextPut:b4; nextPut:b3; nextPut:b2; nextPut:b1. |
|
1759 |
^ self. |
|
1760 |
]. |
|
1761 |
b5 := Character codePoint:((v bitAnd:16r3F) bitOr:2r10000000). |
|
1762 |
v := v bitShift:-6. |
|
1763 |
v <= 16r01 ifTrue:[ |
|
1764 |
self nextPut:(Character value:(v bitOr:2r11111100)). |
|
1765 |
self nextPut:b5; nextPut:b4; nextPut:b3; nextPut:b2; nextPut:b1. |
|
1766 |
^ self. |
|
1767 |
]. |
|
1768 |
||
1769 |
||
1770 |
self error:'codePoint > 31bit in #nextPutUtf8:'. |
|
1771 |
||
1772 |
" |
|
1773 |
(String streamContents:[:s| |
|
1774 |
s nextPutUtf8:$a. |
|
1775 |
s nextPutUtf8:$ü. |
|
1776 |
s nextPutUtf8: (Character value:16r1fff). |
|
1777 |
s nextPutUtf8: (Character value:16rffff). |
|
14593 | 1778 |
s nextPutUtf8: (Character value:16r1ffffff). |
11322 | 1779 |
s nextPutUtf8: (Character value:16r800). |
1780 |
]) |
|
1781 |
asByteArray |
|
1782 |
||
1783 |
" |
|
1784 |
! |
|
1785 |
||
611 | 1786 |
nextPutWord:aNumber |
1787 |
"write the argument, aNumber as a signed short (two bytes); |
|
1788 |
write msb-first for compatibility with other smalltalks. |
|
1789 |
The receiver must support writing of binary bytes. |
|
1790 |
I dont know if it should be named nextPutWord: or nextWordPut:; |
|
1791 |
one of them will vanish ..." |
|
1792 |
||
1793 |
^ self nextPutShort:aNumber MSB:true |
|
1794 |
! |
|
1795 |
||
9407 | 1796 |
nextTwoBytesPut: anInteger |
15397 | 1797 |
<resource: #obsolete> |
9407 | 1798 |
"Write anInteger as the next two bytes of the |
1799 |
receiver stream." |
|
15397 | 1800 |
|
1801 |
self obsoleteMethodWarning:'use #nextPutShort:MSB:'. |
|
1802 |
||
9407 | 1803 |
self |
1804 |
nextPutByte: (anInteger bitAnd: 255); |
|
1805 |
nextPutByte: ((anInteger bitShift: -8) bitAnd: 255) |
|
1806 |
||
1807 |
"Created: / 21-06-2006 / 19:42:10 / fm" |
|
1808 |
! |
|
1809 |
||
611 | 1810 |
nextWordPut:aNumber |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1811 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1812 |
Write the argument, aNumber as a short (two bytes). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1813 |
The most significant byte is sent first." |
611 | 1814 |
|
1815 |
^ self nextPutShort:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1816 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
1817 |
"Modified: 10.1.1996 / 19:39:19 / cg" |
611 | 1818 |
! ! |
1819 |
||
1820 |
!Stream methodsFor:'private'! |
|
1821 |
||
1822 |
contentsSpecies |
|
1823 |
"this should return the class of which an instance is |
|
1403 | 1824 |
returned by the #contents method. Here, Array is returned, |
1825 |
since the abstract Stream-class has no idea of the underlying |
|
1826 |
collection class. |
|
1827 |
It is redefined in some subclasses - for example, to return String." |
|
611 | 1828 |
|
1829 |
^ Array |
|
1403 | 1830 |
|
1831 |
"Modified: 15.5.1996 / 17:53:31 / cg" |
|
611 | 1832 |
! ! |
1833 |
||
1834 |
!Stream methodsFor:'queries'! |
|
1835 |
||
1836 |
isBinary |
|
1403 | 1837 |
"return true, if in binary mode. Always returns false here, |
1838 |
to make internalStreams protocol compatible with externalStreams." |
|
611 | 1839 |
|
7503 | 1840 |
^ self contentsSpecies == ByteArray |
1403 | 1841 |
|
1842 |
"Modified: 15.5.1996 / 17:53:51 / cg" |
|
611 | 1843 |
! |
1844 |
||
11948 | 1845 |
isOpen |
1846 |
"for compatibility with externalStream: |
|
1847 |
return true, if this stream is open." |
|
1848 |
||
1849 |
^ true |
|
1850 |
! |
|
1851 |
||
611 | 1852 |
isReadable |
1853 |
"return true, if reading is supported by the recevier. |
|
1403 | 1854 |
This has to be redefined in concrete subclasses." |
611 | 1855 |
|
1856 |
^ self subclassResponsibility |
|
1403 | 1857 |
|
1858 |
"Modified: 15.5.1996 / 17:54:31 / cg" |
|
611 | 1859 |
! |
1860 |
||
1861 |
isWritable |
|
1862 |
"return true, if writing is supported by the recevier. |
|
1403 | 1863 |
This has to be redefined in concrete subclasses." |
611 | 1864 |
|
1865 |
^ self subclassResponsibility |
|
1403 | 1866 |
|
1867 |
"Modified: 15.5.1996 / 17:54:54 / cg" |
|
611 | 1868 |
! |
1869 |
||
1870 |
lineLength |
|
1403 | 1871 |
"return the lineLength which `looks good' when pretty printed |
1872 |
text is sent to this stream. |
|
1873 |
This has NO meaning whatsoever to regular streams; |
|
1874 |
however, it may be used as a layout hint for prettyprinting functions |
|
1875 |
- for compatibility with TextCollectors, which returns its views actual |
|
1876 |
line length, and allows the prettyprinter to wrap at that position." |
|
611 | 1877 |
|
1878 |
^ 80 |
|
1403 | 1879 |
|
1880 |
"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
|
1881 |
! |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1882 |
|
5395 | 1883 |
lineNumber |
1884 |
"return the current lineNumber if known" |
|
1885 |
||
1886 |
^ nil |
|
1887 |
||
1888 |
||
1889 |
! |
|
1890 |
||
8645 | 1891 |
numberOfTerminalCols |
1892 |
^ self lineLength |
|
1893 |
! |
|
1894 |
||
1895 |
numberOfTerminalLines |
|
1896 |
^ 24 |
|
1897 |
! |
|
1898 |
||
3493
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1899 |
pageFormat |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1900 |
"return the pageFormat - nil here. |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1901 |
This has NO meaning whatsoever to regular streams; |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1902 |
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
|
1903 |
|
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1904 |
^ nil |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1905 |
|
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1906 |
"Modified: / 15.5.1996 / 17:57:01 / cg" |
87864e021c20
added #pageFormat for printerStream protocol compatibility.
Claus Gittinger <cg@exept.de>
parents:
3462
diff
changeset
|
1907 |
"Created: / 29.5.1998 / 16:57:48 / cg" |
8645 | 1908 |
! |
1909 |
||
14303 | 1910 |
size |
1911 |
"return the number of elements in the streamed collection." |
|
1912 |
||
1913 |
self subclassResponsibility |
|
1914 |
||
1915 |
"Created: / 05-08-2012 / 18:38:12 / cg" |
|
1916 |
! |
|
1917 |
||
8645 | 1918 |
terminalType |
1919 |
^ 'dump' |
|
611 | 1920 |
! ! |
1921 |
||
62 | 1922 |
!Stream methodsFor:'reading'! |
1 | 1923 |
|
1924 |
next |
|
1925 |
"return the next element of the stream |
|
1926 |
- we do not know here how to do it, it must be redefined in subclass" |
|
1927 |
||
1928 |
^ self subclassResponsibility |
|
1929 |
! |
|
1930 |
||
1931 |
next:count |
|
1403 | 1932 |
"return the next count elements of the stream as aCollection, |
1933 |
which depends on the streams type - (see #contentsSpecies)." |
|
1 | 1934 |
|
329 | 1935 |
|answerStream |
285 | 1936 |
cnt "{ Class: SmallInteger }" | |
1 | 1937 |
|
285 | 1938 |
cnt := count. |
7467 | 1939 |
answerStream := WriteStream on:(self contentsSpecies new:cnt). |
12426 | 1940 |
1 to:cnt do:[:index | |next| |
1941 |
next := self next. |
|
1942 |
next isNil ifTrue:[ |
|
1943 |
"if next did not raise EndOfStreamError, we have to do it" |
|
1944 |
EndOfStreamError raiseRequestFrom:self. |
|
12623 | 1945 |
"if you proceed, you get what we have already collected" |
1946 |
^ answerStream contents |
|
12426 | 1947 |
]. |
1948 |
answerStream nextPut:next. |
|
1 | 1949 |
]. |
329 | 1950 |
^ answerStream contents |
1 | 1951 |
|
275 | 1952 |
" |
1953 |
(ReadStream on:#(1 2 3 4 5)) next:3 |
|
1954 |
(ReadStream on:'hello') next:3 |
|
1955 |
" |
|
1403 | 1956 |
|
1957 |
"Modified: 15.5.1996 / 17:57:58 / cg" |
|
1 | 1958 |
! |
1959 |
||
7467 | 1960 |
next:count into:aWriteStream |
1961 |
"put the next count elements of the stream into aWriteStream" |
|
1962 |
||
1963 |
|cnt "{ Class: SmallInteger }" | |
|
1964 |
||
1965 |
cnt := count. |
|
12426 | 1966 |
1 to:cnt do:[:index | |next| |
1967 |
next := self next. |
|
1968 |
next isNil ifTrue:[ |
|
1969 |
"if next did not raise EndOfStreamError, we have to do it" |
|
1970 |
EndOfStreamError raiseRequestFrom:self. |
|
1971 |
]. |
|
1972 |
aWriteStream nextPut:next. |
|
7467 | 1973 |
]. |
1974 |
||
1975 |
" |
|
1976 |
|writeStream| |
|
1977 |
writeStream := #() writeStream. |
|
1978 |
#(1 2 3 4 5) readStream next:3 into:writeStream. |
|
1979 |
writeStream contents. |
|
1980 |
||
1981 |
|writeStream| |
|
1982 |
writeStream := '' writeStream. |
|
1983 |
'hello' readStream next:3 into:writeStream. |
|
1984 |
writeStream contents. |
|
1985 |
" |
|
1986 |
||
1987 |
"Modified: 15.5.1996 / 17:57:58 / cg" |
|
1988 |
! |
|
1989 |
||
285 | 1990 |
nextAvailable:count |
1403 | 1991 |
"return the next count elements of the stream as aCollection. |
285 | 1992 |
If the stream reaches the end before count elements have been read, |
1403 | 1993 |
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
|
1994 |
The type of collection is specified in #contentsSpecies." |
285 | 1995 |
|
345 | 1996 |
|answerStream |
285 | 1997 |
cnt "{ Class: SmallInteger }"| |
1998 |
||
1999 |
cnt := count. |
|
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2000 |
answerStream := WriteStream on:(self contentsSpecies new:cnt). |
285 | 2001 |
1 to:cnt do:[:index | |
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2002 |
self atEnd ifTrue:[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2003 |
^ answerStream contents |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2004 |
]. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2005 |
answerStream nextPut:(self next) |
285 | 2006 |
]. |
329 | 2007 |
^ answerStream contents |
285 | 2008 |
|
2009 |
" |
|
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
2010 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
285 | 2011 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
2012 |
(ReadStream on:'hello') nextAvailable:3 |
|
2013 |
(ReadStream on:'hello') nextAvailable:10 |
|
2014 |
" |
|
1403 | 2015 |
|
3590
d22de87c7fbd
removed endOfStreamQuery - instead, handle unhandled exception
Claus Gittinger <cg@exept.de>
parents:
3586
diff
changeset
|
2016 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
285 | 2017 |
! |
2018 |
||
1 | 2019 |
nextMatchFor:anObject |
62 | 2020 |
"read an element from the receiver, return true if it was equal to |
1403 | 2021 |
the argument, anObject; false otherwise." |
62 | 2022 |
|
2023 |
^ (self next = anObject) |
|
2024 |
||
2025 |
" |
|
2026 |
|s| |
|
2027 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2028 |
s nextMatchFor:2 |
|
2029 |
" |
|
2030 |
" |
|
2031 |
|s| |
|
2032 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2033 |
s nextMatchFor:2. |
|
2034 |
s nextMatchFor:2 |
|
2035 |
" |
|
1403 | 2036 |
|
2037 |
"Modified: 15.5.1996 / 17:58:57 / cg" |
|
62 | 2038 |
! |
2039 |
||
6862 | 2040 |
nextOrNil |
2041 |
"like #next, this returns the next element, if available. |
|
7118 | 2042 |
If nothing is available, this does never raise a read-beyond end signal. |
6862 | 2043 |
Instead, nil is returned immediately." |
2044 |
||
2045 |
self atEnd ifTrue:[^ nil]. |
|
2046 |
^ self next |
|
2047 |
! |
|
2048 |
||
7242 | 2049 |
skip:numberToSkip |
2050 |
"skip numberToSkip objects, return the receiver" |
|
345 | 2051 |
|
62 | 2052 |
"dont know how to unread ..." |
7242 | 2053 |
numberToSkip < 0 ifTrue:[ |
8309 | 2054 |
PositionError raiseRequest. |
7242 | 2055 |
^ self |
62 | 2056 |
]. |
7242 | 2057 |
numberToSkip timesRepeat:self next |
62 | 2058 |
|
2059 |
" |
|
2060 |
|s| |
|
2061 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2062 |
s skip:4. |
|
2063 |
s next |
|
2064 |
" |
|
4467 | 2065 |
|
2066 |
"Modified: / 30.7.1999 / 12:12:10 / cg" |
|
62 | 2067 |
! |
2068 |
||
2069 |
skipFor:anObject |
|
1403 | 2070 |
"skip all objects up-to and including anObject; |
2071 |
return the element after anObject." |
|
62 | 2072 |
|
2073 |
(self skipThrough:anObject) notNil ifTrue:[ |
|
6373
d6ffb0101dde
workaround bitShift-bitOr codeGenerator bug in stc
Claus Gittinger <cg@exept.de>
parents:
6360
diff
changeset
|
2074 |
^ self next |
62 | 2075 |
]. |
2076 |
^ nil |
|
2077 |
||
2078 |
" |
|
2079 |
|s| |
|
2080 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
6010 | 2081 |
s skipFor:4. |
2082 |
" |
|
2083 |
" |
|
2084 |
|s| |
|
2085 |
s := ReadStream on:'12345678'. |
|
2086 |
s skipFor:$4. |
|
62 | 2087 |
" |
1403 | 2088 |
|
2089 |
"Modified: 15.5.1996 / 17:59:23 / cg" |
|
62 | 2090 |
! |
2091 |
||
10360
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2092 |
skipLine |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2093 |
"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
|
2094 |
return nil if EOF reached, self otherwise. |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2095 |
Not allowed in binary mode." |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2096 |
|
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2097 |
^ self skipThrough:Character cr |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2098 |
! |
f8a5e7c8c8d8
new: #skipLine (was only in ExternalStream)
Stefan Vogel <sv@exept.de>
parents:
10359
diff
changeset
|
2099 |
|
62 | 2100 |
skipThrough:anObject |
6010 | 2101 |
"skip all objects up-to and including anObject. |
2102 |
Return the receiver if skip was successful, |
|
2103 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
|
62 | 2104 |
The next read operation will return the element after anObject." |
1 | 2105 |
|
2106 |
|nextElement| |
|
2107 |
||
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2108 |
[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2109 |
nextElement := self nextOrNil. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2110 |
(nextElement isNil and:[self atEnd]) ifTrue:[ |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2111 |
^ nil. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2112 |
]. |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2113 |
nextElement = anObject |
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2114 |
] whileFalse. |
2 | 2115 |
|
62 | 2116 |
" |
2117 |
|s| |
|
10358
5a679e45aeaa
Speed up #nextAvailable: and #skipThrough:
Stefan Vogel <sv@exept.de>
parents:
10181
diff
changeset
|
2118 |
s := ReadStream on:#(1 nil 2 3 4 5 6 7 8). |
62 | 2119 |
s skipThrough:4. |
2120 |
s next |
|
2121 |
" |
|
6010 | 2122 |
" |
2123 |
|s| |
|
2124 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2125 |
s skipThrough:4. |
|
2126 |
s skipThrough:4. |
|
2127 |
s next |
|
2128 |
" |
|
2129 |
" |
|
2130 |
|s| |
|
2131 |
s := ReadStream on:'12345678'. |
|
2132 |
s skipThrough:$4. |
|
2133 |
s next |
|
2134 |
" |
|
2135 |
" |
|
2136 |
|s| |
|
2137 |
s := ReadStream on:'12345678'. |
|
2138 |
s skipThrough:$4. |
|
2139 |
s skipThrough:$4. |
|
2140 |
s next |
|
2141 |
" |
|
2142 |
" |
|
2143 |
|s| |
|
2144 |
s := ReadStream on:'12345678'. |
|
2145 |
s skipThrough:$4. |
|
2146 |
s skipThrough:$4. |
|
2147 |
s atEnd |
|
2148 |
" |
|
77 | 2149 |
! |
2150 |
||
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2151 |
skipThroughAll:aCollection |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2152 |
"skip for and through the sequence given by the argument, aCollection; |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2153 |
return nil if not found, the receiver otherwise. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2154 |
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
|
2155 |
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
|
2156 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2157 |
|buffer l first idx| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2158 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2159 |
l := aCollection size. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2160 |
first := aCollection at:1. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2161 |
[self atEnd] whileFalse:[ |
2332 | 2162 |
buffer isNil ifTrue:[ |
2163 |
buffer := self nextAvailable:l. |
|
2164 |
]. |
|
2165 |
buffer = aCollection ifTrue:[ |
|
2166 |
^ self |
|
2167 |
]. |
|
2168 |
idx := buffer indexOf:first startingAt:2. |
|
2169 |
idx == 0 ifTrue:[ |
|
2170 |
buffer := nil |
|
2171 |
] ifFalse:[ |
|
2172 |
buffer := (buffer copyFrom:idx) , (self nextAvailable:(idx - 1)) |
|
2173 |
] |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2174 |
]. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2175 |
^ nil |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2176 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2177 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2178 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2179 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2180 |
s skipThroughAll:'901'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2181 |
s upToEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2182 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2183 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2184 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2185 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2186 |
s skipThroughAll:'1234'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2187 |
s upToEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2188 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2189 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2190 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2191 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2192 |
s skipThroughAll:'999'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2193 |
s atEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2194 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2195 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2196 |
"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
|
2197 |
"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
|
2198 |
! |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
2199 |
|
611 | 2200 |
through:anObject |
2201 |
"read a collection of all objects up-to anObject and return these |
|
2202 |
elements, including anObject. |
|
2203 |
The next read operation will return the element after anObject. |
|
1409 | 2204 |
If anObject is not encountered, all elements up to the end are read |
2205 |
and returned. |
|
611 | 2206 |
Compare this with #upTo: which also reads up to some object |
2207 |
and also positions behind it, but does not include it in the returned |
|
2208 |
value." |
|
2209 |
||
2210 |
|answerStream element| |
|
2211 |
||
2212 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2213 |
[self atEnd] whileFalse:[ |
|
2332 | 2214 |
element := self next. |
2215 |
answerStream nextPut:element. |
|
2216 |
(element = anObject) ifTrue: [ |
|
2217 |
^ answerStream contents |
|
2218 |
] |
|
611 | 2219 |
]. |
2220 |
^ answerStream contents |
|
2221 |
||
2222 |
" |
|
2223 |
|s| |
|
2224 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 2225 |
Transcript showCR:(s through:4). |
2226 |
Transcript showCR:s next |
|
1409 | 2227 |
|
2228 |
|s| |
|
2229 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 2230 |
Transcript showCR:(s through:9). |
2231 |
Transcript showCR:s next |
|
1409 | 2232 |
|
611 | 2233 |
|s| |
2234 |
s := ReadStream on:'hello world'. |
|
1422 | 2235 |
Transcript showCR:(s through:Character space). |
2236 |
Transcript showCR:(s upToEnd) |
|
611 | 2237 |
" |
1409 | 2238 |
|
2239 |
"Modified: 17.5.1996 / 08:51:40 / cg" |
|
611 | 2240 |
! |
2241 |
||
1548 | 2242 |
throughAll:aCollection |
2243 |
"read & return a collection of all objects up-to and including |
|
2244 |
a subcollection given by aCollection. |
|
2245 |
(i.e. read until a ``substring'' is encountered.) |
|
2246 |
The next read operation will return the element after aCollection. |
|
2247 |
If aCollection is not encountered, all elements up to the end are read |
|
2248 |
and returned." |
|
2249 |
||
2250 |
|answerStream element last rslt| |
|
2251 |
||
2252 |
last := aCollection last. |
|
2253 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2254 |
[self atEnd] whileFalse:[ |
|
2332 | 2255 |
element := self next. |
2256 |
answerStream nextPut:element. |
|
2257 |
element == last ifTrue:[ |
|
2258 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
|
2259 |
^ rslt |
|
2260 |
] |
|
2261 |
]. |
|
1548 | 2262 |
]. |
2263 |
^ answerStream contents |
|
2264 |
||
2265 |
" |
|
2266 |
|s| |
|
2267 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2268 |
Transcript showCR:(s throughAll:#(4 4 4)). |
|
2269 |
Transcript showCR:s next |
|
2270 |
||
2271 |
|s| |
|
2272 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
2273 |
Transcript showCR:(s throughAll:#(4 5 6)). |
|
2274 |
Transcript showCR:s next |
|
2275 |
||
2276 |
|s| |
|
2277 |
s := ReadStream on:'hello world, this is some text'. |
|
2278 |
Transcript showCR:(s throughAll:'world'). |
|
2279 |
Transcript showCR:(s throughAll:'some'). |
|
2280 |
Transcript showCR:s upToEnd. |
|
2281 |
" |
|
2282 |
||
2283 |
"Modified: 15.7.1996 / 09:08:07 / cg" |
|
2284 |
! |
|
2285 |
||
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2286 |
throughAny:aCollection |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2287 |
"read & return a collection of all objects up-to and including |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2288 |
an element contained in aCollection. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2289 |
(i.e. read until any from aCollection is encountered.) |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2290 |
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
|
2291 |
and returned." |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2292 |
|
9070 | 2293 |
|answerStream element| |
2294 |
||
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2295 |
answerStream := WriteStream on:(self contentsSpecies new). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2296 |
[self atEnd] whileFalse:[ |
9070 | 2297 |
element := self next. |
2298 |
answerStream nextPut:element. |
|
2299 |
(aCollection includes:element) ifTrue:[ |
|
2300 |
^ answerStream contents |
|
2301 |
]. |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2302 |
]. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2303 |
^ answerStream contents |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2304 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2305 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2306 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2307 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2308 |
Transcript showCR:(s throughAny:#(3 4 5)). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2309 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2310 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2311 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2312 |
s := ReadStream on:'hello world, this is some text'. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2313 |
Transcript showCR:(s throughAny:'wt'). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2314 |
Transcript showCR:(s throughAny:'wt'). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2315 |
Transcript showCR:s upToEnd. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2316 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2317 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2318 |
"Modified: / 11.1.1998 / 15:28:04 / cg" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2319 |
! |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2320 |
|
427 | 2321 |
upTo:anObject |
2322 |
"read a collection of all objects up-to anObject and return these |
|
2323 |
elements, but excluding anObject. |
|
2324 |
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
|
2325 |
(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
|
2326 |
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
|
2327 |
returned collection. |
1409 | 2328 |
If anObject is not encountered, all elements up to the end are read |
2329 |
and returned. |
|
427 | 2330 |
Compare this with #through: which also reads up to some object |
2331 |
and also positions behind it, but DOES include it in the returned |
|
2332 |
value." |
|
2333 |
||
11659 | 2334 |
|answerStream| |
427 | 2335 |
|
2336 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
11659 | 2337 |
self upTo:anObject into:answerStream. |
427 | 2338 |
^ answerStream contents |
2339 |
||
2340 |
" |
|
2341 |
|s| |
|
2342 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 2343 |
Transcript showCR:(s upTo:4). |
2344 |
Transcript showCR:s next |
|
427 | 2345 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2346 |
compare the above to: |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2347 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2348 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2349 |
Transcript showCR:(s through:4). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2350 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2351 |
|
427 | 2352 |
|s| |
1409 | 2353 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
1422 | 2354 |
Transcript showCR:(s upTo:9). |
2355 |
Transcript showCR:s next |
|
1409 | 2356 |
|
2357 |
|s| |
|
427 | 2358 |
s := ReadStream on:'hello world'. |
1422 | 2359 |
Transcript showCR:(s upTo:Character space). |
2360 |
Transcript showCR:(s upToEnd) |
|
427 | 2361 |
|
2362 |
(ReadStream on:'12345678905') upTo:$5; upTo:$5 |
|
2363 |
||
2364 |
(ReadStream on:'123456') upTo:$7 |
|
2365 |
||
2366 |
(ReadStream on:#(1 2 3 4 5 6)) upTo:4 |
|
2367 |
||
2368 |
(ReadStream on:'line 1 |
|
10359 | 2369 |
line 2') upTo:Character cr |
427 | 2370 |
|
2371 |
'Makefile' asFilename readStream upTo:Character cr;upTo:Character cr |
|
2372 |
" |
|
1409 | 2373 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
2374 |
"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
|
2375 |
"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
|
2376 |
! |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
2377 |
|
11659 | 2378 |
upTo:anObject into:aStream |
2379 |
"read a collection of all objects up-to anObject and append these |
|
2380 |
elements to aStream, but excluding anObject. |
|
2381 |
The next read operation will return the element after anObject. |
|
2382 |
(i.e. anObject is considered a separator, which is skipped) |
|
2383 |
Similar to #through:, but the matching object is not included in the returned collection. |
|
2384 |
If anObject is not encountered, all elements up to the end are read and returned. |
|
2385 |
Compare this with #through: which also reads up to some object |
|
2386 |
and also positions behind it, but DOES include it in the returned value." |
|
2387 |
||
2388 |
|element| |
|
2389 |
||
2390 |
[ |
|
2391 |
element := self nextOrNil. |
|
2392 |
((element isNil and:[self atEnd]) or:[element = anObject]) ifTrue:[ |
|
2393 |
true |
|
2394 |
] ifFalse:[ |
|
2395 |
aStream nextPut:element. |
|
2396 |
false |
|
2397 |
]. |
|
2398 |
] whileFalse. |
|
2399 |
! |
|
2400 |
||
3586 | 2401 |
upToAllExcluding:aCollection |
2402 |
"read a collection of all objects up-to a element which is contained in |
|
2403 |
aCollection and return these elements, but excluding the matching one. |
|
2404 |
The next read operation will return the element after aCollection. |
|
2405 |
If no such element is encountered, all elements up to the end are read |
|
2406 |
and returned. |
|
6494 | 2407 |
See also #throughAll: which also reads up to some object |
3586 | 2408 |
and also positions behind it, but DOES include it in the returned |
6494 | 2409 |
value. |
2410 |
See also #upToAll:, which returns the same, but leaves the |
|
2411 |
read pointer before the matched subcollection." |
|
3586 | 2412 |
|
2413 |
|answerStream element last rslt| |
|
2414 |
||
2415 |
last := aCollection last. |
|
2416 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2417 |
[self atEnd] whileFalse:[ |
|
6494 | 2418 |
element := self next. |
2419 |
answerStream nextPut:element. |
|
2420 |
element == last ifTrue:[ |
|
2421 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
|
15165
0b3db61eb3f3
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
15086
diff
changeset
|
2422 |
^ rslt copyButLast:aCollection size |
6494 | 2423 |
] |
2424 |
]. |
|
3586 | 2425 |
]. |
2426 |
^ answerStream contents |
|
2427 |
||
2428 |
" |
|
2429 |
|s| |
|
2430 |
s := ReadStream on:'hello world world'. |
|
2431 |
Transcript show:'<'; show:(s upToAllExcluding:'wo'); showCR:'>'. |
|
2432 |
Transcript show:'<'; show:(s upToAllExcluding:'wo'); showCR:'>'. |
|
2433 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
2434 |
" |
|
2435 |
||
2436 |
"Created: / 15.6.1998 / 19:11:31 / cg" |
|
2437 |
! |
|
2438 |
||
2894 | 2439 |
upToAny:aCollectionOfObjects |
2420 | 2440 |
"read a collection of all objects up-to a element which is contained in |
2441 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
|
2442 |
The next read operation will return the element after anObject. |
|
2443 |
If no such element is encountered, all elements up to the end are read |
|
2444 |
and returned. |
|
2445 |
Compare this with #throughAll: which also reads up to some object |
|
2446 |
and also positions behind it, but DOES include it in the returned |
|
2447 |
value." |
|
2448 |
||
12527 | 2449 |
|result| |
2450 |
||
2451 |
result := self upToBeforeAny:aCollectionOfObjects. |
|
2452 |
self atEnd ifFalse:[ |
|
2453 |
self next. |
|
2420 | 2454 |
]. |
12527 | 2455 |
^ result |
2420 | 2456 |
|
2457 |
" |
|
2458 |
|s| |
|
2459 |
s := ReadStream on:'hello world'. |
|
3154 | 2460 |
Transcript showCR:(s upToAny:(Array with:Character space)). |
2420 | 2461 |
Transcript showCR:(s upToEnd) |
2462 |
||
3154 | 2463 |
'Makefile' asFilename readStream upToAny:($A to:$Z) |
2464 |
" |
|
2420 | 2465 |
|
3154 | 2466 |
"Created: / 30.8.1997 / 03:02:05 / cg" |
2467 |
"Modified: / 11.1.1998 / 15:19:18 / cg" |
|
2420 | 2468 |
! |
2469 |
||
12527 | 2470 |
upToBeforeAny:aCollectionOfObjects |
2471 |
"read a collection of all objects up-to a element which is contained in |
|
2472 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
|
2473 |
The next read operation will return the matching element. |
|
2474 |
If no such element is encountered, all elements up to the end are read |
|
2475 |
and returned. |
|
2476 |
This returns the exact same as upToAny: would, but leaves the streams position so that |
|
2477 |
the next read returns the matching delimiter instead of skipping it. |
|
2478 |
Caveat: this is the one which should have been called upTo: in the first place; |
|
2479 |
however, it seems now too late for a change." |
|
2480 |
||
2481 |
|answerStream element| |
|
2482 |
||
2483 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2484 |
[self atEnd] whileFalse:[ |
|
2485 |
element := self peek. |
|
2486 |
(aCollectionOfObjects includes:element) ifTrue: [ |
|
2487 |
^ answerStream contents |
|
2488 |
]. |
|
2489 |
answerStream nextPut:element. |
|
2490 |
self next. |
|
2491 |
]. |
|
2492 |
^ answerStream contents |
|
2493 |
||
2494 |
" |
|
2495 |
|s| |
|
2496 |
s := ReadStream on:'hello world'. |
|
2497 |
Transcript showCR:(s upToBeforeAny:(Array with:Character space)). |
|
2498 |
Transcript showCR:(s upToEnd) |
|
2499 |
||
2500 |
'Make.proto' asFilename readStream upToBeforeAny:($A to:$Z) |
|
2501 |
" |
|
2502 |
||
2503 |
"Created: / 30.8.1997 / 03:02:05 / cg" |
|
2504 |
"Modified: / 11.1.1998 / 15:19:18 / cg" |
|
2505 |
! |
|
2506 |
||
77 | 2507 |
upToEnd |
2508 |
"return a collection of the elements up-to the end. |
|
1403 | 2509 |
Return an empty collection, if the stream-end is already at the end." |
77 | 2510 |
|
2511 |
|answerStream| |
|
2512 |
||
2513 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2514 |
[self atEnd] whileFalse:[ |
|
2332 | 2515 |
answerStream nextPut:(self next) |
77 | 2516 |
]. |
2517 |
^ answerStream contents |
|
2518 |
||
275 | 2519 |
" |
2520 |
(ReadStream on:'1234567890') upToEnd |
|
2521 |
('123456' readStream) next; next; upToEnd |
|
427 | 2522 |
('1 23456' readStream) upTo:Character space; upToEnd |
1403 | 2523 |
('12' readStream) next; next; upToEnd |
275 | 2524 |
" |
1403 | 2525 |
|
2526 |
"Modified: 15.5.1996 / 18:00:39 / cg" |
|
611 | 2527 |
! ! |
77 | 2528 |
|
6857 | 2529 |
!Stream methodsFor:'reading-strings'! |
3084 | 2530 |
|
2531 |
nextLine |
|
2532 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
2533 |
character (i.e. read a single line of text). |
|
13329 | 2534 |
If the previous-to-last character is a cr, this is also removed, |
2535 |
so its possible to read alien (i.e. ms-dos) text as well. |
|
3084 | 2536 |
Added for protocol compatibility with externalStreams." |
2537 |
||
13329 | 2538 |
|answerStream| |
2539 |
||
3462 | 2540 |
self atEnd ifTrue:[ |
8614 | 2541 |
^ self pastEndRead |
3462 | 2542 |
]. |
13329 | 2543 |
answerStream := WriteStream on:(self contentsSpecies new). |
2544 |
self upTo:Character cr into:answerStream. |
|
13330 | 2545 |
(answerStream size > 0 and:[answerStream last = Character return]) ifTrue:[ |
13329 | 2546 |
answerStream backStep. |
2547 |
]. |
|
2548 |
^ answerStream contents |
|
2549 |
||
3084 | 2550 |
|
3462 | 2551 |
"Modified: / 19.5.1998 / 17:26:25 / cg" |
3084 | 2552 |
! ! |
2553 |
||
12623 | 2554 |
|
611 | 2555 |
!Stream methodsFor:'testing'! |
77 | 2556 |
|
611 | 2557 |
atEnd |
2558 |
"return true if the end of the stream has been reached; |
|
2559 |
- we do not know here how to do it, it must be redefined in subclass" |
|
77 | 2560 |
|
611 | 2561 |
^ self subclassResponsibility |
9294 | 2562 |
! |
2563 |
||
2564 |
isEmpty |
|
2565 |
"return true, if the contents of the stream is empty" |
|
2566 |
||
2567 |
^ self subclassResponsibility |
|
2568 |
! |
|
2569 |
||
14092 | 2570 |
isEmptyOrNil |
2571 |
"return true, if the contents of the stream is empty |
|
2572 |
(we already know, that we are not nil)" |
|
2573 |
||
2574 |
^ self isEmpty |
|
2575 |
! |
|
2576 |
||
15048 | 2577 |
isEncodedStream |
2578 |
^ false |
|
2579 |
! |
|
2580 |
||
2581 |
isPositionable |
|
2582 |
"return true, if the stream supports positioning (some do not). |
|
2583 |
Since this is an abstract class, false is returned here - just to make certain." |
|
2584 |
||
2585 |
^ false |
|
2586 |
||
2587 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
2588 |
! |
|
2589 |
||
2590 |
isPrinterStream |
|
2591 |
"return true, if this is a printerStream. |
|
2592 |
Since this is an abstract class, false is returned here." |
|
2593 |
||
2594 |
^ false |
|
2595 |
||
2596 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
2597 |
"Created: 3.6.1996 / 12:05:35 / cg" |
|
2598 |
! |
|
2599 |
||
2600 |
isStream |
|
2601 |
"return true, if the receiver is some kind of Stream. Always return true here." |
|
2602 |
||
2603 |
^ true |
|
2604 |
||
2605 |
"Modified: 15.5.1996 / 17:54:48 / cg" |
|
2606 |
! |
|
2607 |
||
2608 |
isTerminalStream |
|
2609 |
^ false |
|
2610 |
! |
|
2611 |
||
9294 | 2612 |
notEmpty |
2613 |
"return true, if the contents of the stream is not empty" |
|
2614 |
||
2615 |
^ self isEmpty not |
|
14092 | 2616 |
! |
2617 |
||
2618 |
notEmptyOrNil |
|
2619 |
"return true, if the contents of the stream is empty |
|
2620 |
(we already know, that we are not nil)" |
|
2621 |
||
2622 |
^ self isEmpty not |
|
1 | 2623 |
! ! |
2624 |
||
11750 | 2625 |
!Stream methodsFor:'visiting'! |
2626 |
||
2627 |
acceptVisitor:aVisitor with:aParameter |
|
2628 |
^ aVisitor visitStream:self with:aParameter |
|
2629 |
! ! |
|
2630 |
||
12399 | 2631 |
!Stream methodsFor:'waiting for I/O'! |
2632 |
||
2633 |
readWait |
|
2634 |
"suspend the current process, until the receiver |
|
2635 |
becomes ready for reading. If data is already available, |
|
2636 |
return immediate. |
|
2637 |
The other threads are not affected by the wait." |
|
2638 |
||
2639 |
^ self readWaitWithTimeoutMs:nil |
|
2640 |
! |
|
2641 |
||
12401 | 2642 |
readWaitTimeoutMs:timeout |
2643 |
"ST-80 compatibility" |
|
2644 |
^ self readWaitWithTimeoutMs:timeout |
|
2645 |
! |
|
2646 |
||
12399 | 2647 |
readWaitWithTimeout:seconds |
2648 |
"suspend the current process, until the receiver |
|
2649 |
becomes ready for reading or a timeout (in seconds) expired. |
|
2650 |
If data is already available, return immediate. |
|
2651 |
With nil seconds, wait forever. |
|
2652 |
Return true if a timeout occured (i.e. false, if data is available). |
|
2653 |
The other threads are not affected by the wait." |
|
2654 |
||
2655 |
|ms| |
|
2656 |
||
2657 |
seconds notNil ifTrue:[ |
|
2658 |
ms := seconds * 1000 |
|
2659 |
]. |
|
2660 |
^ self readWaitWithTimeoutMs:ms |
|
2661 |
! |
|
2662 |
||
2663 |
readWaitWithTimeoutMs:millis |
|
2664 |
"suspend the current process, until the receiver |
|
2665 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
2666 |
If data is already available, return immediate. |
|
2667 |
With nil millis, wait forever. |
|
2668 |
Return true if a timeout occured (i.e. false, if data is available). |
|
2669 |
The other threads are not affected by the wait." |
|
2670 |
||
2671 |
^ false "/ never have to wait |
|
2672 |
! |
|
2673 |
||
12401 | 2674 |
readWriteWait |
2675 |
"suspend the current process, until the receiver |
|
2676 |
becomes ready for writing or reading. |
|
2677 |
Return immediate if the receiver is already ready. |
|
2678 |
The other threads are not affected by the wait." |
|
2679 |
||
2680 |
self readWriteWaitWithTimeoutMs:nil |
|
2681 |
! |
|
2682 |
||
2683 |
readWriteWaitWithTimeoutMs:millis |
|
2684 |
^ false "/ never have to wait |
|
2685 |
! |
|
2686 |
||
12399 | 2687 |
writeWait |
12401 | 2688 |
"suspend the current process, until the receiver |
2689 |
becomes ready for writing. |
|
2690 |
Return immediate if the receiver is already ready. |
|
2691 |
The other threads are not affected by the wait." |
|
2692 |
||
2693 |
self writeWaitWithTimeoutMs:nil |
|
2694 |
! |
|
2695 |
||
2696 |
writeWaitTimeoutMs:timeout |
|
2697 |
"ST-80 compatibility" |
|
2698 |
^ self writeWaitWithTimeoutMs:timeout |
|
2699 |
! |
|
2700 |
||
2701 |
writeWaitWithTimeout:timeout |
|
2702 |
"suspend the current process, until the receiver |
|
2703 |
becomes ready for writing or a timeout (in seconds) expired. |
|
2704 |
Return true if a timeout occured (i.e. false, if data is available). |
|
2705 |
Return immediate if the receiver is already ready. |
|
2706 |
The other threads are not affected by the wait." |
|
2707 |
||
2708 |
|ms| |
|
2709 |
||
2710 |
timeout notNil ifTrue:[ |
|
2711 |
ms := timeout * 1000 |
|
2712 |
]. |
|
2713 |
^ self writeWaitWithTimeoutMs:ms |
|
12399 | 2714 |
! |
2715 |
||
2716 |
writeWaitWithTimeoutMs:millis |
|
2717 |
^ false "/ never have to wait |
|
2718 |
! ! |
|
2719 |
||
62 | 2720 |
!Stream methodsFor:'writing'! |
1 | 2721 |
|
339 | 2722 |
commit |
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2723 |
"alias for flush -- ST80 compatibility" |
339 | 2724 |
|
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2725 |
^ self flush |
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2726 |
|
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2727 |
"Modified: 7.5.1996 / 23:55:39 / stefan" |
339 | 2728 |
! |
2729 |
||
611 | 2730 |
cr |
1403 | 2731 |
"append a carriage-return to the stream. |
2732 |
This is only allowed, if the receiver supports writing." |
|
611 | 2733 |
|
2734 |
self nextPut:(Character cr) |
|
1403 | 2735 |
|
2736 |
"Modified: 15.5.1996 / 18:01:21 / cg" |
|
611 | 2737 |
! |
2738 |
||
2739 |
crTab |
|
2740 |
"append a carriage-return followed by a tab to the stream. |
|
1403 | 2741 |
Same as crtab for ST/X backward compatibility. |
2742 |
This is only allowed, if the receiver supports writing." |
|
611 | 2743 |
|
5873 | 2744 |
<resource:#obsolete> |
2745 |
||
9061 | 2746 |
self obsoleteMethodWarning:'use #crtab'. |
611 | 2747 |
self crtab |
1403 | 2748 |
|
2749 |
"Modified: 15.5.1996 / 18:01:28 / cg" |
|
611 | 2750 |
! |
2751 |
||
9001 | 2752 |
crlf |
2753 |
"append a CR LF to the stream. |
|
2754 |
This is only allowed, if the receiver supports writing." |
|
2755 |
||
2756 |
self nextPut:(Character return); |
|
2757 |
nextPut:(Character lf). |
|
2758 |
! |
|
2759 |
||
611 | 2760 |
crtab |
1403 | 2761 |
"append a carriage-return followed by a tab to the stream. |
2762 |
This is only allowed, if the receiver supports writing." |
|
1 | 2763 |
|
611 | 2764 |
self crtab:1 |
1403 | 2765 |
|
2766 |
"Modified: 15.5.1996 / 18:01:35 / cg" |
|
611 | 2767 |
! |
2768 |
||
2769 |
crtab:n |
|
1403 | 2770 |
"append a carriage-return followed by n tabs to the stream. |
2771 |
This is only allowed, if the receiver supports writing." |
|
611 | 2772 |
|
2773 |
self nextPut:(Character cr). |
|
2774 |
self next:n put:(Character tab) |
|
1403 | 2775 |
|
2776 |
"Modified: 15.5.1996 / 18:01:39 / cg" |
|
611 | 2777 |
! |
2778 |
||
2779 |
endEntry |
|
2780 |
"ignored here - for compatibility with Transcript" |
|
2781 |
||
2782 |
^ self |
|
2783 |
! |
|
2784 |
||
2785 |
ff |
|
1403 | 2786 |
"append a form-feed (new-pagee) to the receiver-stream. |
2787 |
This is only allowed, if the receiver supports writing." |
|
611 | 2788 |
|
2789 |
self nextPut:(Character ff) |
|
1403 | 2790 |
|
2791 |
"Modified: 15.5.1996 / 18:01:47 / cg" |
|
1 | 2792 |
! |
2793 |
||
701 | 2794 |
flush |
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2795 |
"write out all unbuffered data - ignored here, but added |
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2796 |
to make internalStreams protocol compatible with externalStreams" |
701 | 2797 |
|
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
2798 |
"Modified: 7.5.1996 / 23:54:53 / stefan" |
701 | 2799 |
! |
2800 |
||
1 | 2801 |
next:count put:anObject |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2802 |
"put the argument, anObject count times onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2803 |
This is only allowed, if the receiver supports writing." |
1 | 2804 |
|
345 | 2805 |
|n "{ Class: SmallInteger }"| |
2806 |
||
2807 |
n := count. |
|
2808 |
n timesRepeat:[self nextPut:anObject]. |
|
12132 | 2809 |
"/ ^ anObject -- return self |
62 | 2810 |
|
2811 |
" |
|
2812 |
|s| |
|
2813 |
||
2814 |
s := WriteStream on:#(). |
|
2815 |
s nextPut:1. |
|
2816 |
s next:5 put:2. |
|
2817 |
s nextPut:3. |
|
2818 |
s contents |
|
2819 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2820 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2821 |
"Modified: 11.7.1996 / 10:00:13 / cg" |
1 | 2822 |
! |
2823 |
||
14792 | 2824 |
next:count putAll:aCollection |
2825 |
"put all elements from the argument, aCollection count times onto the receiver. |
|
2826 |
This is only allowed, if the receiver supports writing." |
|
2827 |
||
2828 |
|n "{ Class: SmallInteger }"| |
|
2829 |
||
2830 |
n := count. |
|
2831 |
n timesRepeat:[self nextPutAll:aCollection]. |
|
2832 |
"/ ^ anObject -- return self |
|
2833 |
||
2834 |
" |
|
2835 |
|s| |
|
2836 |
||
2837 |
s := WriteStream on:(String new). |
|
2838 |
s next:5 putAll:'Hello'. |
|
2839 |
s contents |
|
2840 |
" |
|
2841 |
! |
|
2842 |
||
611 | 2843 |
nextPut:anObject |
2844 |
"put the argument, anObject onto the receiver |
|
2845 |
- we do not know here how to do it, it must be redefined in subclass" |
|
2846 |
||
2847 |
^ self subclassResponsibility |
|
2848 |
! |
|
2849 |
||
1 | 2850 |
nextPutAll:aCollection |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2851 |
"put all elements of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2852 |
This is only allowed, if the receiver supports writing." |
1 | 2853 |
|
2854 |
aCollection do:[:element | |
|
12134 | 2855 |
self nextPut:element |
1 | 2856 |
]. |
62 | 2857 |
|
2858 |
" |
|
2859 |
|s| |
|
2860 |
||
2861 |
s := WriteStream on:#(). |
|
2862 |
s nextPutAll:(1 to:5). |
|
2863 |
s nextPutAll:#('one' 'two' 'three'). |
|
2864 |
s contents |
|
2865 |
" |
|
2866 |
" |
|
2867 |
|s| |
|
2868 |
||
2869 |
s := WriteStream on:(String new). |
|
2870 |
s nextPutAll:($a to:$f). |
|
2871 |
s nextPutAll:'one '; |
|
2872 |
nextPutAll:'two '; |
|
2873 |
nextPutAll:'three'. |
|
2874 |
s contents |
|
2875 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2876 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2877 |
"Modified: 11.7.1996 / 10:00:21 / cg" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2878 |
! |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2879 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2880 |
nextPutAll:aCollection startingAt:first |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2881 |
"append the elements starting with index to the end |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2882 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2883 |
This is only allowed, if the receiver supports writing." |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2884 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2885 |
self nextPutAll:aCollection startingAt:first to:(aCollection size). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2886 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2887 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2888 |
|s| |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2889 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2890 |
s := WriteStream on:#(). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2891 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2892 |
s contents |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2893 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2894 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2895 |
"Modified: 11.7.1996 / 10:00:28 / cg" |
1 | 2896 |
! |
2897 |
||
2898 |
nextPutAll:aCollection startingAt:first to:last |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2899 |
"append the elements with index from first to last |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2900 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2901 |
This is only allowed, if the receiver supports writing." |
1 | 2902 |
|
2903 |
aCollection from:first to:last do:[:element | |
|
2332 | 2904 |
self nextPut:element |
1 | 2905 |
]. |
2906 |
^ aCollection |
|
62 | 2907 |
|
2908 |
" |
|
2909 |
|s| |
|
2910 |
||
2911 |
s := WriteStream on:#(). |
|
2912 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4. |
|
2913 |
s contents |
|
2914 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2915 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2916 |
"Modified: 11.7.1996 / 10:00:32 / cg" |
1 | 2917 |
! |
2918 |
||
14263 | 2919 |
nextPutAllLines:aCollectionOfStrings |
2920 |
"put all elements of the argument, aCollection as individual lines |
|
2921 |
onto the receiver, append a cr (carriage return) after each. |
|
2922 |
This is only useful with character streams in textMode, |
|
2923 |
and only allowed, if the receiver supports writing." |
|
2924 |
||
2925 |
aCollectionOfStrings do:[:eachLine | |
|
2926 |
self nextPutLine:eachLine. |
|
2927 |
]. |
|
2928 |
||
2929 |
"Modified: / 08-11-1996 / 23:53:41 / cg" |
|
2930 |
"Created: / 27-07-2012 / 09:26:09 / cg" |
|
2931 |
! |
|
2932 |
||
11322 | 2933 |
nextPutAllText:aText |
2934 |
"normal streams can not handle text/emphasis, so convert aText to the string" |
|
2935 |
||
2936 |
aText string printOn:self. |
|
2937 |
! |
|
2938 |
||
2939 |
nextPutAllUnicode:aString |
|
2940 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
2941 |
||
2942 |
aString do:[:eachCharacter| |
|
2943 |
self nextPutUtf8:eachCharacter. |
|
2944 |
]. |
|
2945 |
! |
|
2946 |
||
5628
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2947 |
nextPutAllUntranslated:aCollection |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2948 |
"for compatibility with printStreams (putAll - as-is without escapes)" |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2949 |
|
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2950 |
self nextPutAll:aCollection |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2951 |
! |
1dc85c4c4b7c
added #nextPutAllUntranslated: (for printStream compatibility)
Claus Gittinger <cg@exept.de>
parents:
5395
diff
changeset
|
2952 |
|
743 | 2953 |
nextPutLine:aCollection |
2954 |
"put all elements of the argument, aCollection onto the receiver, |
|
1949 | 2955 |
and append a cr (carriage return). |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
2956 |
This is only useful with character streams in textMode, |
1949 | 2957 |
and only allowed, if the receiver supports writing." |
743 | 2958 |
|
2959 |
self nextPutAll:aCollection. |
|
2960 |
self cr. |
|
2961 |
||
2962 |
"Created: 13.12.1995 / 10:49:17 / cg" |
|
1949 | 2963 |
"Modified: 8.11.1996 / 23:53:41 / cg" |
743 | 2964 |
! |
2965 |
||
11322 | 2966 |
nextPutUnicode:aCharacter |
2967 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
2968 |
||
2969 |
self nextPutUtf8:aCharacter. |
|
2970 |
! |
|
2971 |
||
611 | 2972 |
print:anObject |
2973 |
"append a printed representation of anObject to the receiver. |
|
1403 | 2974 |
Same as 'anObject printOn:self'; Added for ST-80 compatibility." |
2 | 2975 |
|
611 | 2976 |
anObject printOn:self |
1403 | 2977 |
|
2978 |
" |
|
2979 |
|s| |
|
2980 |
||
2981 |
s := WriteStream on:''. |
|
2982 |
s nextPutAll:'one '; |
|
2983 |
print:1; |
|
2984 |
nextPutAll:' two '; |
|
2985 |
print:2. |
|
2986 |
||
2987 |
s contents |
|
2988 |
" |
|
2989 |
||
2990 |
"Modified: 15.5.1996 / 18:06:06 / cg" |
|
2 | 2991 |
! |
2992 |
||
14360 | 2993 |
printCR:anObject |
2994 |
"append a printed representation of anObject to the receiver, |
|
2995 |
followed by a newline character." |
|
2996 |
||
2997 |
self print:anObject. |
|
2998 |
self cr. |
|
2999 |
||
3000 |
"Created: / 26-09-2012 / 18:21:06 / cg" |
|
3001 |
! |
|
3002 |
||
1403 | 3003 |
show:something |
3004 |
"append a printed representation of the argument to the stream. |
|
3005 |
This makes streams somewhat compatible to TextCollectors and |
|
3006 |
allows you to say: |
|
10920 | 3007 |
Smalltalk at:#Transcript put:Stdout |
1422 | 3008 |
or to use #show:/#showCR: with internal or external streams." |
1 | 3009 |
|
10920 | 3010 |
something printOn:self |
1 | 3011 |
! |
3012 |
||
11863 | 3013 |
show:something with:arg |
11949 | 3014 |
"append a printed representation of the argument to the stream, expanding |
3015 |
the placeHolder %1 with the printString of arg. |
|
3016 |
This makes streams somewhat compatible to TextCollectors and |
|
3017 |
allows you to say: |
|
3018 |
Smalltalk at:#Transcript put:Stdout |
|
3019 |
or to use #show:/#showCR: with internal or external streams." |
|
3020 |
||
13027 | 3021 |
self show:(something bindWith:arg) |
3022 |
||
3023 |
"Modified: / 19-08-2010 / 15:42:00 / cg" |
|
11863 | 3024 |
! |
3025 |
||
3026 |
show:something with:arg1 with:arg2 |
|
11949 | 3027 |
"append a printed representation of the argument to the stream, expanding |
3028 |
the placeHolders %1 and %2 with the printStrings of arg1 and arg2. |
|
3029 |
This makes streams somewhat compatible to TextCollectors and |
|
3030 |
allows you to say: |
|
3031 |
Smalltalk at:#Transcript put:Stdout |
|
3032 |
or to use #show:/#showCR: with internal or external streams." |
|
3033 |
||
13027 | 3034 |
self show:(something bindWith:arg1 with:arg2) |
3035 |
||
3036 |
"Modified: / 19-08-2010 / 15:42:09 / cg" |
|
11863 | 3037 |
! |
3038 |
||
3039 |
show:something with:arg1 with:arg2 with:arg3 |
|
11949 | 3040 |
"append a printed representation of the argument to the stream, expanding |
3041 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
3042 |
This makes streams somewhat compatible to TextCollectors and |
|
3043 |
allows you to say: |
|
3044 |
Smalltalk at:#Transcript put:Stdout |
|
3045 |
or to use #show:/#showCR: with internal or external streams." |
|
3046 |
||
13027 | 3047 |
self show:(something bindWith:arg1 with:arg2 with:arg3) |
3048 |
||
3049 |
"Modified: / 19-08-2010 / 15:42:17 / cg" |
|
3050 |
! |
|
3051 |
||
3052 |
show:something with:arg1 with:arg2 with:arg3 with:arg4 |
|
3053 |
"append a printed representation of the argument to the stream, expanding |
|
3054 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
3055 |
This makes streams somewhat compatible to TextCollectors and |
|
3056 |
allows you to say: |
|
3057 |
Smalltalk at:#Transcript put:Stdout |
|
3058 |
or to use #show:/#showCR: with internal or external streams." |
|
3059 |
||
3060 |
self show:(something bindWith:arg1 with:arg2 with:arg3 with:arg4) |
|
3061 |
||
3062 |
"Created: / 19-08-2010 / 15:42:25 / cg" |
|
11863 | 3063 |
! |
3064 |
||
1414 | 3065 |
showCR:aString |
1403 | 3066 |
"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
|
3067 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3068 |
This makes streams somewhat compatible to TextCollectors and |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3069 |
allows you to say: |
2332 | 3070 |
Smalltalk at:#Transcript put:Stdout |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3071 |
or to use #show:/#showCR: with internal or external streams." |
1 | 3072 |
|
3073 |
self show:aString. |
|
3074 |
self cr |
|
1403 | 3075 |
|
1414 | 3076 |
"Created: 18.5.1996 / 15:34:17 / cg" |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3077 |
"Modified: 11.7.1996 / 10:01:27 / cg" |
1414 | 3078 |
! |
3079 |
||
13027 | 3080 |
showCR:something with:arg |
3081 |
"append a printed representation of the argument to the stream, expanding |
|
3082 |
the placeHolder %1 with the printString of arg. |
|
3083 |
This makes streams somewhat compatible to TextCollectors and |
|
3084 |
allows you to say: |
|
3085 |
Smalltalk at:#Transcript put:Stdout |
|
3086 |
or to use #show:/#showCR: with internal or external streams." |
|
3087 |
||
3088 |
self showCR:(something bindWith:arg) |
|
3089 |
||
3090 |
"Created: / 19-08-2010 / 15:41:46 / cg" |
|
3091 |
! |
|
3092 |
||
3093 |
showCR:something with:arg1 with:arg2 |
|
3094 |
"append a printed representation of the argument to the stream, expanding |
|
3095 |
the placeHolders %1 and %2 with the printStrings of arg1 and arg2. |
|
3096 |
This makes streams somewhat compatible to TextCollectors and |
|
3097 |
allows you to say: |
|
3098 |
Smalltalk at:#Transcript put:Stdout |
|
3099 |
or to use #show:/#showCR: with internal or external streams." |
|
3100 |
||
3101 |
self showCR:(something bindWith:arg1 with:arg2) |
|
3102 |
||
3103 |
"Created: / 19-08-2010 / 15:42:37 / cg" |
|
3104 |
! |
|
3105 |
||
3106 |
showCR:something with:arg1 with:arg2 with:arg3 |
|
3107 |
"append a printed representation of the argument to the stream, expanding |
|
3108 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
3109 |
This makes streams somewhat compatible to TextCollectors and |
|
3110 |
allows you to say: |
|
3111 |
Smalltalk at:#Transcript put:Stdout |
|
3112 |
or to use #show:/#showCR: with internal or external streams." |
|
3113 |
||
3114 |
self showCR:(something bindWith:arg1 with:arg2 with:arg3) |
|
3115 |
||
3116 |
"Created: / 19-08-2010 / 15:42:43 / cg" |
|
3117 |
! |
|
3118 |
||
3119 |
showCR:something with:arg1 with:arg2 with:arg3 with:arg4 |
|
3120 |
"append a printed representation of the argument to the stream, expanding |
|
3121 |
the placeHolders %1,%2 and %3 with the printStrings of arg1, arg2 and arg3. |
|
3122 |
This makes streams somewhat compatible to TextCollectors and |
|
3123 |
allows you to say: |
|
3124 |
Smalltalk at:#Transcript put:Stdout |
|
3125 |
or to use #show:/#showCR: with internal or external streams." |
|
3126 |
||
3127 |
self showCR:(something bindWith:arg1 with:arg2 with:arg3 with:arg4) |
|
3128 |
||
3129 |
"Created: / 19-08-2010 / 15:42:50 / cg" |
|
3130 |
! |
|
3131 |
||
1414 | 3132 |
showCr:aString |
3133 |
"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
|
3134 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3135 |
This is obsolete ST/X backward compatibility; use #showCR:" |
1414 | 3136 |
|
5873 | 3137 |
<resource:#obsolete> |
3138 |
||
1414 | 3139 |
self obsoleteMethodWarning:'use #showCR:'. |
3140 |
self showCR:aString. |
|
3141 |
||
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3142 |
"Modified: 11.7.1996 / 10:01:50 / cg" |
62 | 3143 |
! |
3144 |
||
3145 |
space |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3146 |
"append a space character to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3147 |
This is only allowed, if the receiver supports writing." |
62 | 3148 |
|
3149 |
self nextPut:(Character space) |
|
1403 | 3150 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3151 |
"Modified: 11.7.1996 / 10:02:06 / cg" |
62 | 3152 |
! |
3153 |
||
3154 |
spaces:count |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3155 |
"append count space-characters to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3156 |
This is only allowed, if the receiver supports writing." |
62 | 3157 |
|
3158 |
self next:count put:(Character space) |
|
1403 | 3159 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3160 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
62 | 3161 |
! |
3162 |
||
611 | 3163 |
store:anObject |
3164 |
"append a printed representation of anObject to the receiver, |
|
1403 | 3165 |
from which the receiver can be reconstructed (i.e. its storeString). |
3166 |
Same as 'anObject storeOn:self'; Added for ST-80 compatibility." |
|
77 | 3167 |
|
611 | 3168 |
anObject storeOn:self |
1403 | 3169 |
|
3170 |
"Modified: 15.5.1996 / 18:05:55 / cg" |
|
77 | 3171 |
! |
3172 |
||
8645 | 3173 |
sync |
3174 |
"write out all unbuffered data - ignored here, but added |
|
3175 |
to make internalStreams protocol compatible with externalStreams" |
|
3176 |
! |
|
3177 |
||
11649 | 3178 |
syncData |
3179 |
"write out all unbuffered data - ignored here, but added |
|
3180 |
to make internalStreams protocol compatible with externalStreams" |
|
3181 |
! |
|
3182 |
||
611 | 3183 |
tab |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3184 |
"append a tab-character to the stream. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3185 |
This is only allowed, if the receiver supports writing." |
77 | 3186 |
|
611 | 3187 |
self nextPut:(Character tab) |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3188 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
3189 |
"Modified: 11.7.1996 / 10:02:20 / cg" |
2443 | 3190 |
! |
3191 |
||
3192 |
tab:count |
|
3193 |
"append count tab-characters to the receiver. |
|
3194 |
This is only allowed, if the receiver supports writing." |
|
3195 |
||
3196 |
self next:count put:(Character tab) |
|
3197 |
||
3198 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
|
77 | 3199 |
! ! |
3200 |
||
8054
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3201 |
!Stream methodsFor:'writing-chunks'! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3202 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3203 |
nextChunkPut:aString |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3204 |
"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
|
3205 |
double all exclamation marks except within primitives and append a |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3206 |
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
|
3207 |
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
|
3208 |
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
|
3209 |
or other editors. |
15086 | 3210 |
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
|
3211 |
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
|
3212 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3213 |
self nextPutAllAsChunk:aString. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3214 |
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
|
3215 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3216 |
"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
|
3217 |
! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3218 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3219 |
nextPutAllAsChunk:aString |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3220 |
"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
|
3221 |
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
|
3222 |
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
|
3223 |
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
|
3224 |
or other editors. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3225 |
Its no incompatibility, since inline primitives are an ST/X special |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3226 |
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
|
3227 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3228 |
|sep stopChars inPrimitive character |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3229 |
index "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3230 |
endIndex "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3231 |
stop "{ Class:SmallInteger }" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3232 |
next "{ Class:SmallInteger }"| |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3233 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3234 |
endIndex := aString size. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3235 |
endIndex == 0 ifTrue:[^ self]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3236 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3237 |
sep := self class chunkSeparator. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3238 |
stopChars := '{}' copyWith:sep. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3239 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3240 |
inPrimitive := false. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3241 |
index := 1. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3242 |
stop := endIndex + 1. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3243 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3244 |
[index <= endIndex] whileTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3245 |
" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3246 |
find position of next interesting character; |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3247 |
output stuff up to that one in one piece |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3248 |
" |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3249 |
next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3250 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3251 |
((index == 1) and:[next == stop]) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3252 |
self nextPutAll:aString |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3253 |
] ifFalse:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3254 |
self nextPutAll:aString startingAt:index to:(next - 1) |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3255 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3256 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3257 |
index := next. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3258 |
(index <= endIndex) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3259 |
character := aString at:index. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3260 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3261 |
(character == ${ ) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3262 |
"/ starts a primitive |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3263 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3264 |
inPrimitive := true |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3265 |
] |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3266 |
] ifFalse:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3267 |
"/ ends a primitive |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3268 |
(character == $} ) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3269 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3270 |
inPrimitive := false |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3271 |
] |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3272 |
] ifFalse:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3273 |
"/ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3274 |
"/ exclas have to be doubled - except if within a primitive |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3275 |
"/ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3276 |
inPrimitive ifFalse:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3277 |
(character == sep) ifTrue:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3278 |
self nextPut:sep |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3279 |
] |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3280 |
] |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3281 |
] |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3282 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3283 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3284 |
self nextPut:character. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3285 |
index := index + 1. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3286 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3287 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3288 |
(aString endsWith:Character cr) ifFalse:[ |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3289 |
self cr. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3290 |
]. |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3291 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3292 |
"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
|
3293 |
"/ foo |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3294 |
! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3295 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3296 |
nextPutChunkSeparator |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3297 |
"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
|
3298 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3299 |
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
|
3300 |
|
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3301 |
"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
|
3302 |
! ! |
7f31b0651027
chunk stuff moved from positionable stream (did not need positioning)
Claus Gittinger <cg@exept.de>
parents:
7687
diff
changeset
|
3303 |
|
1949 | 3304 |
!Stream class methodsFor:'documentation'! |
701 | 3305 |
|
3306 |
version |
|
15397 | 3307 |
^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.201 2013-06-12 08:37:20 stefan Exp $' |
12093 | 3308 |
! |
3309 |
||
3310 |
version_CVS |
|
15397 | 3311 |
^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.201 2013-06-12 08:37:20 stefan Exp $' |
701 | 3312 |
! ! |
6857 | 3313 |
|
14792 | 3314 |
|
611 | 3315 |
Stream initialize! |