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