author | Claus Gittinger <cg@exept.de> |
Fri, 16 Jan 1998 15:54:52 +0100 | |
changeset 3176 | a54a89fb0e5b |
parent 3172 | f73912c49864 |
child 3184 | d99302322139 |
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 |
" |
|
12 |
||
13 |
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
|
14 |
instanceVariableNames:'signalAtEnd' |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
15 |
classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal |
3106 | 16 |
WriteErrorSignal EndOfStreamSignal EndOfStreamQuerySignal' |
743 | 17 |
poolDictionaries:'' |
18 |
category:'Streams' |
|
1 | 19 |
! |
20 |
||
1949 | 21 |
!Stream class methodsFor:'documentation'! |
88 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
216 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
An abstract class defining common behavior for all stream-like objects. |
|
40 |
See concrete subclasses for more detail. |
|
345 | 41 |
|
1404 | 42 |
The protocol as implemented here is often only provided as a fallBack |
43 |
for very uncommon cases. Much of it is redefined for performance. |
|
44 |
(In streams which know more about their internal representation ...) |
|
45 |
||
46 |
||
345 | 47 |
Subclasses should (at least) implement: |
2332 | 48 |
#next (if readable) |
49 |
#nextPut: (if writable) |
|
50 |
#contents |
|
51 |
#atEnd |
|
52 |
#isReadable |
|
53 |
#isWritable |
|
1295 | 54 |
|
1404 | 55 |
Peekable & Positionable streams should (at least) implement: |
2332 | 56 |
#peek |
57 |
#position |
|
58 |
#position: |
|
1404 | 59 |
|
60 |
||
1295 | 61 |
[Class variables:] |
2332 | 62 |
StreamErrorSignal <Signal> parent of all stream errors |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
63 |
|
2332 | 64 |
PositionErrorSignal <Signal> position attemted on a stream |
65 |
which does not support positioning |
|
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
66 |
|
2332 | 67 |
ReadErrorSignal <Signal> raised on read errors |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
68 |
|
2332 | 69 |
WriteErrorSignal <Signal> raised on write errors |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
70 |
|
3106 | 71 |
EndOfStreamSignal <Signal> raised at end of stream if signalAtEnd |
72 |
is enabled. |
|
73 |
||
74 |
EndOfStreamQuerySignal <QuerySignal> raised at end of stream if signalAtEnd |
|
75 |
is defaulted (nil). |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
76 |
|
1295 | 77 |
[author:] |
2332 | 78 |
Claus Gittinger |
88 | 79 |
" |
80 |
! ! |
|
1 | 81 |
|
1949 | 82 |
!Stream class methodsFor:'initialization'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
83 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
84 |
initialize |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
85 |
StreamErrorSignal isNil ifTrue:[ |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
86 |
StreamErrorSignal := ErrorSignal newSignalMayProceed:false. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
87 |
StreamErrorSignal nameClass:self message:#streamErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
88 |
StreamErrorSignal notifierString:'Stream error'. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
89 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
90 |
PositionErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
91 |
PositionErrorSignal nameClass:self message:#positionErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
92 |
PositionErrorSignal notifierString:'stream as no concept of a position'. |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
93 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
94 |
ReadErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
95 |
ReadErrorSignal nameClass:self message:#readErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
96 |
ReadErrorSignal notifierString:'read error'. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
97 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
98 |
WriteErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
99 |
WriteErrorSignal nameClass:self message:#writeErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
100 |
WriteErrorSignal notifierString:'write error'. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
101 |
|
3106 | 102 |
EndOfStreamSignal := StreamErrorSignal newSignalMayProceed:true. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
103 |
EndOfStreamSignal nameClass:self message:#endOfStreamSignal. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
104 |
EndOfStreamSignal notifierString:'end of stream'. |
3106 | 105 |
|
106 |
EndOfStreamQuerySignal := QuerySignal new defaultAnswer:nil. |
|
107 |
EndOfStreamQuerySignal parent:EndOfStreamSignal. |
|
108 |
EndOfStreamQuerySignal nameClass:self message:#endOfStreamQuerySignal. |
|
109 |
EndOfStreamQuerySignal notifierString:'end of stream'. |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
110 |
] |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
111 |
! ! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
112 |
|
1949 | 113 |
!Stream class methodsFor:'instance creation'! |
611 | 114 |
|
115 |
new |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
116 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
117 |
|
611 | 118 |
"report an error - Streams are created using on:-messages" |
119 |
||
120 |
^ self error:'Streams cannot be created with new' |
|
121 |
! ! |
|
122 |
||
1949 | 123 |
!Stream class methodsFor:'Signal constants'! |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
124 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
125 |
endOfStreamQuerySignal |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
126 |
"return the query signal raised if read past end of stream is attemted" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
127 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
128 |
^ EndOfStreamQuerySignal |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
129 |
! |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
130 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
131 |
endOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
132 |
"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
|
133 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
134 |
^ EndOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
135 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
136 |
|
611 | 137 |
positionErrorSignal |
138 |
"return the signal raised if positioning is requested for |
|
139 |
a stream which does not support that kind of operation" |
|
140 |
||
141 |
^ PositionErrorSignal |
|
142 |
! |
|
143 |
||
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
144 |
readErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
145 |
"return the signal raised on read errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
146 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
147 |
^ ReadErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
148 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
149 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
150 |
streamErrorSignal |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
151 |
"return the parent of all stream errors; |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
152 |
handling this one also handles all other errors. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
153 |
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
|
154 |
operations, such as failed ioctls in externalStream etc." |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
155 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
156 |
^ StreamErrorSignal |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
157 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
158 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
159 |
writeErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
160 |
"return the signal raised on write errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
161 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
162 |
^ WriteErrorSignal |
1 | 163 |
! ! |
164 |
||
165 |
!Stream methodsFor:'accessing'! |
|
166 |
||
167 |
contents |
|
62 | 168 |
"return the entire contents of the stream |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
169 |
- we do not know here how to do it, it must be redefined in subclasses." |
1 | 170 |
|
171 |
^ self subclassResponsibility |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
172 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
173 |
"Modified: 15.5.1996 / 17:36:29 / cg" |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
174 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
175 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
176 |
signalAtEnd |
3105 | 177 |
"return the signalAtEnd flag setting. |
178 |
If true, reading past the end will always raise an EndOfStream exception. |
|
179 |
If false, no exception is raised and nil is returned from all reading messages. |
|
180 |
If nil (default), the exception is raised if there is a handler; otherwise, nil is returned. |
|
181 |
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
|
182 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
183 |
^ signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
184 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
185 |
"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
|
186 |
"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
|
187 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
188 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
189 |
signalAtEnd:aBoolean |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
190 |
"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
|
191 |
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
|
192 |
raised and nil is returned from all reading messages. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
193 |
The default is (currently) to NOT raise a signal." |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
194 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
195 |
signalAtEnd := aBoolean. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
196 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
197 |
"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
|
198 |
"Modified: 15.5.1996 / 17:36:12 / cg" |
1 | 199 |
! ! |
200 |
||
611 | 201 |
!Stream methodsFor:'closing'! |
202 |
||
203 |
close |
|
204 |
"close the stream - nothing done here. |
|
205 |
Added for compatibility with external streams." |
|
206 |
||
207 |
^ self |
|
208 |
! ! |
|
209 |
||
1401 | 210 |
!Stream methodsFor:'emphasis'! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
211 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
212 |
bold |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
213 |
"set emphasis to #bold. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
214 |
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
|
215 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
216 |
self emphasis:#bold. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
217 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
218 |
"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
|
219 |
"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
|
220 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
221 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
222 |
boldItalic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
223 |
"set emphasis to #boldItalic |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
224 |
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
|
225 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
226 |
self emphasis:#(bold italic). |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
227 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
228 |
"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
|
229 |
"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
|
230 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
231 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
232 |
emphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
233 |
"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
|
234 |
text streams" |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
235 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
236 |
^ nil |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
237 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
238 |
"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
|
239 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
240 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
241 |
emphasis:anEmphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
242 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
243 |
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
|
244 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
245 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
246 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
247 |
"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
|
248 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
249 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
250 |
italic |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
251 |
"set emphasis to #italic. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
252 |
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
|
253 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
254 |
self emphasis:#italic. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
255 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
256 |
"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
|
257 |
"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
|
258 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
259 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
260 |
normal |
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
261 |
"set emphasis to #normal. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
262 |
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
|
263 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
264 |
self emphasis:nil |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
265 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
266 |
"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
|
267 |
"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
|
268 |
! |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
269 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
270 |
strikeout |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
271 |
"set emphasis to #strikeout. |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
272 |
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
|
273 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
274 |
self emphasis:#strikeout. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
275 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
276 |
"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
|
277 |
"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
|
278 |
! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
279 |
|
1448
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
280 |
underline |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
281 |
"set emphasis to #underline. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
282 |
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
|
283 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
284 |
self emphasis:#underline. |
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
285 |
|
0d59ce5c4915
reduce all emphasis change messages to single #emphasis:
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
286 |
"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
|
287 |
"Modified: 3.6.1996 / 17:15:38 / cg" |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
288 |
! ! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
289 |
|
1401 | 290 |
!Stream methodsFor:'enumerating'! |
291 |
||
292 |
do:aBlock |
|
293 |
"evaluate the argument, aBlock for all remaining elements, |
|
294 |
up to the end of the stream" |
|
295 |
||
296 |
[self atEnd] whileFalse:[ |
|
297 |
aBlock value:(self next) |
|
298 |
] |
|
299 |
||
300 |
" |
|
301 |
|s| |
|
302 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
303 |
s next. |
|
304 |
s next. |
|
1422 | 305 |
s do:[:element | Transcript showCR:element] |
1401 | 306 |
" |
307 |
! ! |
|
308 |
||
309 |
!Stream methodsFor:'error handling'! |
|
310 |
||
311 |
pastEnd |
|
312 |
"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
|
313 |
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
|
314 |
Otherwise raise the signal, but only if handled; otherwise return nil." |
1401 | 315 |
|
316 |
signalAtEnd == true ifTrue:[ |
|
3106 | 317 |
"/ always raise ... |
3154 | 318 |
^ EndOfStreamSignal raiseIn:thisContext sender |
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
319 |
]. |
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
320 |
signalAtEnd == false ifTrue:[ |
3106 | 321 |
"/ never raise ... |
3154 | 322 |
^ nil |
1401 | 323 |
]. |
324 |
||
3106 | 325 |
^ EndOfStreamQuerySignal raiseRequestFrom:self |
3104
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
326 |
|
4b817b05cde0
vw compatible readPastEnd: only raise the signal if its handled;
Claus Gittinger <cg@exept.de>
parents:
3084
diff
changeset
|
327 |
"Modified: / 11.11.1997 / 16:14:41 / cg" |
1401 | 328 |
! ! |
329 |
||
611 | 330 |
!Stream methodsFor:'misc'! |
331 |
||
332 |
binary |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
333 |
"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
|
334 |
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
|
335 |
byte-valued integers respectively. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
336 |
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
|
337 |
with externalStreams." |
611 | 338 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
339 |
"Modified: 15.5.1996 / 17:38:36 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
340 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
341 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
342 |
text |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
343 |
"switch to text mode. |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
344 |
Ignored here, but added to make internalStreams protocol compatible |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
345 |
with externalStreams." |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
346 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
347 |
"Modified: 15.5.1996 / 17:38:36 / cg" |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
348 |
"Created: 13.9.1996 / 18:33:26 / cg" |
611 | 349 |
! ! |
350 |
||
351 |
!Stream methodsFor:'non homogenous reading'! |
|
352 |
||
2714 | 353 |
nextBytes:count |
354 |
"read the next count bytes and return it either as a byteArray (binary mode) |
|
355 |
or as a string (text mode). |
|
356 |
If EOF is encountered while reading, a truncated byteArry or short string |
|
357 |
is returned. If EOF is already reached before the first byte can be read, |
|
358 |
nil is returned." |
|
359 |
||
360 |
|data n| |
|
361 |
||
362 |
self binary ifTrue:[ |
|
3154 | 363 |
data := ByteArray new:count |
2714 | 364 |
] ifFalse:[ |
3154 | 365 |
data := String new:count |
2714 | 366 |
]. |
367 |
n := self nextBytes:count into:data startingAt:1. |
|
368 |
n ~~ count ifTrue:[ |
|
3154 | 369 |
n == 0 ifTrue:[ |
370 |
^ nil |
|
371 |
]. |
|
372 |
data := data copyTo:n |
|
2714 | 373 |
]. |
374 |
||
375 |
^ data |
|
376 |
||
377 |
"Created: 21.6.1997 / 11:18:57 / cg" |
|
378 |
! |
|
379 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
380 |
nextBytes:count into:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
381 |
"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
|
382 |
bytes read. On EOF, 0 is returned. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
383 |
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
|
384 |
is raised if the connection is broken. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
385 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
386 |
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
|
387 |
a ByteArray, String, Float- or DoubleArray). |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
391 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
395 |
^ self nextBytes:count into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
396 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
397 |
"Modified: 22.4.1997 / 10:41:39 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
398 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
399 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
400 |
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
|
401 |
"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
|
402 |
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
|
403 |
collection. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
404 |
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
|
405 |
The receiver must support reading of binary bytes. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
406 |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
407 |
Notice: this method is privided here for protocol completeness |
3154 | 408 |
with externalStreams - it is normally not used with other |
409 |
streams." |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
410 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
411 |
|n "{Class: SmallInteger }" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
412 |
dstIndex| |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
413 |
|
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
414 |
dstIndex := initialIndex. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
415 |
n := 0. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
416 |
[self atEnd] whileFalse:[ |
3154 | 417 |
n == numBytes ifTrue:[ |
418 |
^ n |
|
419 |
]. |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
420 |
|
3154 | 421 |
aCollection byteAt:dstIndex put:(self nextByte). |
422 |
dstIndex := dstIndex + 1. |
|
423 |
n := n + 1. |
|
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
424 |
]. |
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
425 |
^ n |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
426 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
427 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
428 |
|s n buffer| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
429 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
430 |
buffer := ByteArray new:10. |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
431 |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
432 |
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
|
433 |
s next:3. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
434 |
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
|
435 |
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
|
436 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
437 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
438 |
"Modified: 22.4.1997 / 10:43:08 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
439 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
440 |
|
2587 | 441 |
nextBytes:numBytes into:aCollection startingAt:initialIndex blockSize:blockSize |
442 |
"like nextBytes:into:startingAt:, but read in blocks of the given size. |
|
443 |
This leads to better beahvior when reading large chunks from a slow device, |
|
444 |
such as a cdrom drive (since a single unix-read is not interruptable)." |
|
445 |
||
446 |
|nR oR n| |
|
447 |
||
448 |
nR := numBytes. |
|
449 |
oR := initialIndex. |
|
450 |
[nR > 0] whileTrue:[ |
|
3154 | 451 |
n := nR. |
452 |
n > blockSize ifTrue:[n := blockSize]. |
|
453 |
n := self nextBytes:n into:aCollection startingAt:oR. |
|
454 |
n == 0 ifTrue:[ |
|
455 |
^ numBytes - nR |
|
456 |
]. |
|
457 |
oR := oR + n. |
|
458 |
nR := nR - n |
|
2587 | 459 |
]. |
460 |
^ numBytes |
|
461 |
||
462 |
"Created: 24.4.1997 / 21:09:34 / cg" |
|
463 |
"Modified: 24.4.1997 / 21:19:50 / cg" |
|
464 |
! |
|
465 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
466 |
nextBytesInto:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
467 |
"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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
is raised if the connection is broken. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
472 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
473 |
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
|
474 |
(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
|
475 |
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
|
476 |
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
|
477 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
478 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
479 |
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
|
480 |
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
|
481 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
482 |
^ self nextBytes:(anObject byteSize) into:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
483 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
484 |
" to read 100 bytes from a stream: |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
485 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
486 |
|b aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
487 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
488 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
489 |
b := ByteArray new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
490 |
aStream nextBytesInto:b. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
491 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
492 |
b inspect |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
493 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
494 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
495 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
496 |
|s aStream| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
497 |
aStream := 'smalltalk.rc' asFilename readStream. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
498 |
s := String new:100. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
499 |
aStream nextBytesInto:s. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
500 |
aStream close. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
501 |
s inspect |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
502 |
" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
503 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
504 |
"Modified: 22.4.1997 / 10:42:02 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
505 |
"Created: 22.4.1997 / 10:42:26 / cg" |
1665
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
506 |
! |
928e9a308cea
added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents:
1548
diff
changeset
|
507 |
|
611 | 508 |
nextLongMSB:msbFlag |
509 |
"return a signed long (4 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
510 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
511 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
512 |
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
|
513 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
514 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
515 |
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
|
516 |
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
|
517 |
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
|
518 |
network byte order." |
611 | 519 |
|
3176 | 520 |
|high uval "{ Class: SmallInteger }" val| |
611 | 521 |
|
522 |
msbFlag ifTrue:[ |
|
2332 | 523 |
"most significant first" |
3176 | 524 |
uval := self next. |
525 |
uval := (uval bitShift:8) bitOr:self next. |
|
526 |
uval := (uval bitShift:8) bitOr:self next. |
|
527 |
val := (uval bitShift:8) bitOr:self next. |
|
611 | 528 |
] ifFalse:[ |
2332 | 529 |
"least significant first" |
530 |
uval := self next. |
|
531 |
uval := uval bitOr:(self next bitShift:8). |
|
532 |
uval := uval bitOr:(self next bitShift:16). |
|
3176 | 533 |
val := uval bitOr:(self next bitShift:24). |
611 | 534 |
]. |
535 |
"change from unsigned 0..FFFFFFFF to signed -80000000..7FFFFFFF" |
|
536 |
||
3176 | 537 |
val >= 16r80000000 ifTrue:[ |
538 |
^ val - 16r100000000 |
|
539 |
]. |
|
540 |
^ val |
|
541 |
||
542 |
" |
|
543 |
|bytes s| |
|
544 |
||
545 |
bytes := #[16rFF 16rFF 16rFF 16rFF]. |
|
546 |
s := bytes readStream. |
|
547 |
Transcript showCR:(s nextLongMSB:true). |
|
548 |
s reset. |
|
549 |
Transcript showCR:(s nextLongMSB:false). |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
550 |
|
3176 | 551 |
bytes := #[16r12 16r34 16r56 16r78]. |
552 |
s := bytes readStream. |
|
553 |
Transcript showCR:(s nextLongMSB:true). |
|
554 |
s reset. |
|
555 |
Transcript showCR:(s nextLongMSB:false). |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
556 |
|
3176 | 557 |
bytes := #[16r89 16rab 16rcd 16ref]. |
558 |
s := bytes readStream. |
|
559 |
Transcript showCR:(s nextLongMSB:true). |
|
560 |
s reset. |
|
561 |
Transcript showCR:(s nextLongMSB:false). |
|
562 |
" |
|
563 |
||
564 |
"Modified: / 14.1.1998 / 15:40:41 / cg" |
|
611 | 565 |
! |
566 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
567 |
nextLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
568 |
"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
|
569 |
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
|
570 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
571 |
^ self nextLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
572 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
573 |
"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
|
574 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
575 |
|
611 | 576 |
nextNumber:n |
577 |
"Return the next n bytes as a positive Integer; bytes are taken msb-first." |
|
578 |
||
579 |
|s |
|
580 |
val "{ Class: SmallInteger }" |
|
581 |
rep "{ Class: SmallInteger }"| |
|
582 |
||
583 |
"claus: this method is central in binaryStorage - |
|
584 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
585 |
||
586 |
n == 1 ifTrue:[ |
|
587 |
^ self next |
|
588 |
]. |
|
589 |
n == 2 ifTrue:[ |
|
590 |
val := self next. |
|
591 |
val := (val bitShift:8) + self next. |
|
592 |
^ val |
|
593 |
]. |
|
594 |
n == 3 ifTrue:[ |
|
595 |
val := self next. |
|
596 |
val := (val bitShift:8) + self next. |
|
597 |
val := (val bitShift:8) + self next. |
|
598 |
^ val |
|
599 |
]. |
|
600 |
n == 4 ifTrue:[ |
|
601 |
val := self next. |
|
602 |
val <= 16r3F ifTrue:[ |
|
603 |
val := (val bitShift:8) + self next. |
|
604 |
val := (val bitShift:8) + self next. |
|
605 |
val := (val bitShift:8) + self next. |
|
606 |
^ val |
|
607 |
]. |
|
608 |
"sorry, but need a largeInteger" |
|
3176 | 609 |
val := (val bitShift:8) + self next. |
611 | 610 |
s := (val bitShift:8) + self next. |
611 |
s := (s * 256) + self next. |
|
612 |
^ s |
|
613 |
]. |
|
614 |
||
615 |
" |
|
616 |
arbitrary long |
|
617 |
" |
|
618 |
s := 0. |
|
619 |
rep := n. |
|
620 |
rep timesRepeat:[ |
|
621 |
s := s * 256 + self next |
|
622 |
]. |
|
623 |
^ s truncated |
|
624 |
! |
|
625 |
||
626 |
nextShortMSB:msbFlag |
|
627 |
"return a signed short (2 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
628 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
629 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
630 |
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
|
631 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
632 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
633 |
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
|
634 |
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
|
635 |
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
|
636 |
network byte order." |
611 | 637 |
|
638 |
|uval "{ Class: SmallInteger }"| |
|
639 |
||
640 |
msbFlag ifTrue:[ |
|
2332 | 641 |
"most significant first" |
642 |
uval := self next bitShift:8. |
|
643 |
uval := uval bitOr:(self next). |
|
611 | 644 |
] ifFalse:[ |
2332 | 645 |
"least significant first" |
646 |
uval := self next. |
|
647 |
uval := uval bitOr:(self next bitShift:8). |
|
611 | 648 |
]. |
649 |
"change from unsigned 0..FFFF to signed -8000..7FFF" |
|
650 |
uval >= 16r8000 ifTrue:[ |
|
2332 | 651 |
^ uval - 16r10000 |
611 | 652 |
]. |
653 |
^ uval |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
654 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
655 |
"Modified: 11.7.1996 / 10:07:04 / cg" |
611 | 656 |
! |
657 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
658 |
nextShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
659 |
"return a signed short (2 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
|
660 |
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
|
661 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
662 |
^ self nextShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
663 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
664 |
"Modified: 10.1.1996 / 19:48:50 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
665 |
"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
|
666 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
667 |
|
611 | 668 |
nextUnsignedLongMSB:msbFlag |
669 |
"return an unsigned long (4 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
670 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
671 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
672 |
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
|
673 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
674 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
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
|
678 |
network byte order." |
611 | 679 |
|
680 |
|val| |
|
681 |
||
682 |
msbFlag ifTrue:[ |
|
2332 | 683 |
val := self next. |
684 |
val := (val bitShift:8) bitOr:(self next). |
|
685 |
val := (val bitShift:8) bitOr:(self next). |
|
686 |
val := (val * 256) + (self next). |
|
687 |
^ val |
|
611 | 688 |
]. |
689 |
val := self next. |
|
690 |
^ (val bitShift:24) |
|
691 |
+ (self next bitShift:16) |
|
692 |
+ (self next bitShift:8) |
|
693 |
+ self next |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
694 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
695 |
"Modified: 11.7.1996 / 10:07:13 / cg" |
611 | 696 |
! |
697 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
698 |
nextUnsignedLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
699 |
"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
|
700 |
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
|
701 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
702 |
^ self nextUnsignedLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
703 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
704 |
"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
|
705 |
"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
|
706 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
707 |
|
611 | 708 |
nextUnsignedShortMSB:msbFlag |
709 |
"return an unsigned short (2 bytes) from the stream. |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
710 |
The receiver must support reading of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
711 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
712 |
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
|
713 |
most-significant-byte-first (true) or least-first (false). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
714 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
715 |
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
|
716 |
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
|
717 |
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
|
718 |
network byte order." |
611 | 719 |
|
720 |
msbFlag ifTrue:[ |
|
2332 | 721 |
^ (self next bitShift:8) bitOr:(self next) |
611 | 722 |
]. |
723 |
^ (self next) bitOr:(self next bitShift:8) |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
724 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
725 |
"Modified: 11.7.1996 / 10:07:20 / cg" |
611 | 726 |
! |
727 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
728 |
nextUnsignedShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
729 |
"return an unsigned short (2 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
|
730 |
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
|
731 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
732 |
^ self nextUnsignedShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
733 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
734 |
"Created: 10.1.1996 / 19:50:02 / cg" |
611 | 735 |
! ! |
736 |
||
737 |
!Stream methodsFor:'non homogenous writing'! |
|
738 |
||
739 |
nextLongPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
740 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
741 |
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
|
742 |
The most significant byte is sent first." |
611 | 743 |
|
744 |
^ self nextPutLong:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
745 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
746 |
"Modified: 10.1.1996 / 19:38:54 / cg" |
611 | 747 |
! |
748 |
||
749 |
nextNumber:n put:v |
|
750 |
"Append to the receiver the argument, v, which is a positive Integer, |
|
751 |
as the next n bytes. Bytes are written msb first. |
|
752 |
Possibly pad with leading zeros. |
|
753 |
The receiver must support writing of binary bytes." |
|
754 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
755 |
|vlen "{ Class: SmallInteger }" |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
756 |
i "{ Class: SmallInteger }"| |
611 | 757 |
|
758 |
"claus: this method is central in binaryStorage - |
|
759 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
760 |
||
761 |
v class == SmallInteger ifTrue:[ "- this is a hint to stc" |
|
762 |
n == 1 ifTrue:[ |
|
763 |
(v between:0 and:16rFF) ifTrue:[ |
|
764 |
self nextPut:v. |
|
765 |
^ self |
|
766 |
]. |
|
767 |
]. |
|
768 |
n == 2 ifTrue:[ |
|
769 |
(v between:0 and:16rFFFF) ifTrue:[ |
|
2332 | 770 |
self nextPut:(v bitShift:-8); nextPut:(v bitAnd:16rFF). |
611 | 771 |
^ self |
772 |
]. |
|
773 |
]. |
|
774 |
n == 3 ifTrue:[ |
|
775 |
(v between:0 and:16rFFFFFF) ifTrue:[ |
|
776 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
777 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
778 |
self nextPut:(v bitAnd:16rFF). |
|
779 |
^ self |
|
780 |
]. |
|
781 |
]. |
|
782 |
n == 4 ifTrue:[ |
|
783 |
(v >= 0) ifTrue:[ |
|
784 |
self nextPut:((v bitShift:-24) bitAnd:16rFF). |
|
785 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
786 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
787 |
self nextPut:(v bitAnd:16rFF). |
|
788 |
^ self |
|
789 |
]. |
|
790 |
]. |
|
791 |
]. |
|
792 |
||
793 |
" |
|
794 |
arbitrary long |
|
795 |
" |
|
796 |
n < (vlen := v digitLength) ifTrue: [ |
|
797 |
" |
|
798 |
the number is too big to be repesented in n bytes |
|
799 |
" |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
800 |
self error:'number too big' |
611 | 801 |
]. |
802 |
||
803 |
"pad with leading zeros" |
|
804 |
i := n. |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
805 |
[i > vlen] whileTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
806 |
self nextPut:0. |
611 | 807 |
i := i - 1 |
808 |
]. |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
809 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
810 |
i == 1 ifTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
811 |
^ self nextPut:v |
611 | 812 |
]. |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
813 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
814 |
[i > 0] whileTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
815 |
self nextPut:(v digitAt:i). |
611 | 816 |
i := i - 1 |
817 |
] |
|
818 |
! |
|
819 |
||
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
820 |
nextPutByte:aByteValue |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
821 |
"write a byte. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
822 |
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
|
823 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
824 |
self nextPut:aByteValue |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
825 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
826 |
"Modified: 22.4.1997 / 09:05:26 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
827 |
"Created: 22.4.1997 / 10:43:55 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
828 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
829 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
830 |
nextPutBytes:count from:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
831 |
"write count bytes from an object. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
832 |
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
|
833 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
834 |
(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
|
835 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
836 |
Warning: in general, you cannot use this method to pass data to other |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
837 |
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
|
838 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
839 |
^ self nextPutBytes:count from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
840 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
841 |
"Created: 22.4.1997 / 10:43:59 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
842 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
843 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
844 |
nextPutBytes:count from:anObject startingAt:start |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
845 |
"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
|
846 |
Return the number of bytes written. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
847 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
848 |
(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
|
849 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
850 |
This is provided for compatibility with externalStream; |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
851 |
to support binary storage" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
852 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
853 |
|idx| |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
854 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
855 |
idx := start. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
856 |
1 to:count do:[:i | |
3154 | 857 |
self nextPutByte:(anObject byteAt:idx). |
858 |
idx := idx + 1 |
|
2576
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
859 |
]. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
860 |
^ count |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
861 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
862 |
"Created: 22.4.1997 / 10:44:09 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
863 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
864 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
865 |
nextPutBytesFrom:anObject |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
866 |
"write bytes from an object; the number of bytes is defined by |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
867 |
the objects size. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
868 |
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
|
869 |
The object must have non-pointer indexed instvars |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
870 |
(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
|
871 |
Use with care - non object oriented i/o. |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
872 |
Warning: in general, you cannot use this method to pass data to other |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
873 |
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
|
874 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
875 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
876 |
|
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
877 |
"Created: 22.4.1997 / 10:44:18 / cg" |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
878 |
! |
9985af974304
added non-homogenous read/write stuff;
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
879 |
|
611 | 880 |
nextPutLong:aNumber MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
881 |
"Write the argument, aNumber as a long (four bytes). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
882 |
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
|
883 |
otherwise least first. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
884 |
Returns the receiver on ok, nil on error. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
885 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
886 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
887 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
network byte order." |
611 | 892 |
|
2332 | 893 |
|hi lo w1 w2| |
894 |
||
895 |
hi := (aNumber // 16r10000). |
|
896 |
lo := (aNumber \\ 16r10000). |
|
897 |
||
611 | 898 |
msbFlag ifTrue:[ |
3154 | 899 |
"high word first" |
900 |
w1 := hi. |
|
901 |
w2 := lo. |
|
2332 | 902 |
] ifFalse:[ |
3154 | 903 |
"low word first" |
904 |
w1 := lo. |
|
905 |
w2 := hi. |
|
611 | 906 |
]. |
3084 | 907 |
self nextPutShort:w1 MSB:false; nextPutShort:w2 MSB:false. |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
908 |
|
3084 | 909 |
"Modified: / 1.11.1997 / 18:30:52 / cg" |
611 | 910 |
! |
911 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
912 |
nextPutLongNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
913 |
"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
|
914 |
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
|
915 |
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
|
916 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
917 |
^ self nextPutLong:aNumber MSB:(Socket networkLongOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
918 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
919 |
"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
|
920 |
"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
|
921 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
922 |
|
611 | 923 |
nextPutShort:aNumber MSB:msbFlag |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
924 |
"Write the argument, aNumber as a short (two bytes). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
925 |
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
|
926 |
otherwise least first. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
927 |
Returns the receiver on ok, nil on error. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
928 |
The receiver must support writing of binary bytes. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
929 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
930 |
This interface is provided to allow talking to external programs, |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
931 |
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
|
932 |
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
|
933 |
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
|
934 |
network byte order." |
611 | 935 |
|
2332 | 936 |
|iNum "{ Class: SmallInteger }" hi lo b1 b2| |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
937 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
938 |
iNum := aNumber. |
2332 | 939 |
hi := (iNum bitShift:-8). |
940 |
lo := (iNum bitAnd:16rFF). |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
941 |
|
611 | 942 |
msbFlag ifTrue:[ |
2332 | 943 |
"high byte first" |
944 |
b1 := hi. |
|
945 |
b2 := lo. |
|
946 |
] ifFalse:[ |
|
947 |
"low byte first" |
|
948 |
b1 := lo. |
|
949 |
b2 := hi. |
|
611 | 950 |
]. |
2332 | 951 |
self nextPut:b1. self nextPut:b2. |
611 | 952 |
! |
953 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
954 |
nextPutShortNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
955 |
"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
|
956 |
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
|
957 |
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
|
958 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
959 |
^ self nextPutLong:aNumber MSB:(Socket networkShortOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
960 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
961 |
"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
|
962 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
963 |
|
611 | 964 |
nextPutWord:aNumber |
965 |
"write the argument, aNumber as a signed short (two bytes); |
|
966 |
write msb-first for compatibility with other smalltalks. |
|
967 |
The receiver must support writing of binary bytes. |
|
968 |
I dont know if it should be named nextPutWord: or nextWordPut:; |
|
969 |
one of them will vanish ..." |
|
970 |
||
971 |
^ self nextPutShort:aNumber MSB:true |
|
972 |
! |
|
973 |
||
974 |
nextShortPut:aNumber MSB:msbFlag |
|
3084 | 975 |
"for backward compatibility - this will vanish" |
611 | 976 |
|
977 |
^ self nextPutShort:aNumber MSB:msbFlag |
|
3084 | 978 |
|
979 |
"Modified: / 1.11.1997 / 18:31:05 / cg" |
|
611 | 980 |
! |
981 |
||
982 |
nextWordPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
983 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
984 |
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
|
985 |
The most significant byte is sent first." |
611 | 986 |
|
987 |
^ self nextPutShort:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
988 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
989 |
"Modified: 10.1.1996 / 19:39:19 / cg" |
611 | 990 |
! ! |
991 |
||
992 |
!Stream methodsFor:'private'! |
|
993 |
||
994 |
contentsSpecies |
|
995 |
"this should return the class of which an instance is |
|
1403 | 996 |
returned by the #contents method. Here, Array is returned, |
997 |
since the abstract Stream-class has no idea of the underlying |
|
998 |
collection class. |
|
999 |
It is redefined in some subclasses - for example, to return String." |
|
611 | 1000 |
|
1001 |
^ Array |
|
1403 | 1002 |
|
1003 |
"Modified: 15.5.1996 / 17:53:31 / cg" |
|
611 | 1004 |
! ! |
1005 |
||
1006 |
!Stream methodsFor:'queries'! |
|
1007 |
||
1008 |
isBinary |
|
1403 | 1009 |
"return true, if in binary mode. Always returns false here, |
1010 |
to make internalStreams protocol compatible with externalStreams." |
|
611 | 1011 |
|
1012 |
^ false |
|
1403 | 1013 |
|
1014 |
"Modified: 15.5.1996 / 17:53:51 / cg" |
|
611 | 1015 |
! |
1016 |
||
1017 |
isPositionable |
|
1403 | 1018 |
"return true, if the stream supports positioning (some do not). |
1019 |
Since this is an abstract class, false is returned here - just to make certain." |
|
611 | 1020 |
|
1021 |
^ false |
|
1403 | 1022 |
|
1023 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
611 | 1024 |
! |
1025 |
||
1447 | 1026 |
isPrinterStream |
1027 |
"return true, if this is a printerStream. |
|
1028 |
Since this is an abstract class, false is returned here." |
|
1029 |
||
1030 |
^ false |
|
1031 |
||
1032 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
1033 |
"Created: 3.6.1996 / 12:05:35 / cg" |
|
1034 |
! |
|
1035 |
||
611 | 1036 |
isReadable |
1037 |
"return true, if reading is supported by the recevier. |
|
1403 | 1038 |
This has to be redefined in concrete subclasses." |
611 | 1039 |
|
1040 |
^ self subclassResponsibility |
|
1403 | 1041 |
|
1042 |
"Modified: 15.5.1996 / 17:54:31 / cg" |
|
611 | 1043 |
! |
1044 |
||
1045 |
isStream |
|
1403 | 1046 |
"return true, if the receiver is some kind of Stream. Always return true here." |
611 | 1047 |
|
1048 |
^ true |
|
1403 | 1049 |
|
1050 |
"Modified: 15.5.1996 / 17:54:48 / cg" |
|
611 | 1051 |
! |
1052 |
||
1053 |
isWritable |
|
1054 |
"return true, if writing is supported by the recevier. |
|
1403 | 1055 |
This has to be redefined in concrete subclasses." |
611 | 1056 |
|
1057 |
^ self subclassResponsibility |
|
1403 | 1058 |
|
1059 |
"Modified: 15.5.1996 / 17:54:54 / cg" |
|
611 | 1060 |
! |
1061 |
||
1062 |
lineLength |
|
1403 | 1063 |
"return the lineLength which `looks good' when pretty printed |
1064 |
text is sent to this stream. |
|
1065 |
This has NO meaning whatsoever to regular streams; |
|
1066 |
however, it may be used as a layout hint for prettyprinting functions |
|
1067 |
- for compatibility with TextCollectors, which returns its views actual |
|
1068 |
line length, and allows the prettyprinter to wrap at that position." |
|
611 | 1069 |
|
1070 |
^ 80 |
|
1403 | 1071 |
|
1072 |
"Modified: 15.5.1996 / 17:57:01 / cg" |
|
611 | 1073 |
! ! |
1074 |
||
62 | 1075 |
!Stream methodsFor:'reading'! |
1 | 1076 |
|
1077 |
next |
|
1078 |
"return the next element of the stream |
|
1079 |
- we do not know here how to do it, it must be redefined in subclass" |
|
1080 |
||
1081 |
^ self subclassResponsibility |
|
1082 |
! |
|
1083 |
||
1084 |
next:count |
|
1403 | 1085 |
"return the next count elements of the stream as aCollection, |
1086 |
which depends on the streams type - (see #contentsSpecies)." |
|
1 | 1087 |
|
329 | 1088 |
|answerStream |
285 | 1089 |
cnt "{ Class: SmallInteger }" | |
1 | 1090 |
|
329 | 1091 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 1092 |
cnt := count. |
1093 |
1 to:cnt do:[:index | |
|
2332 | 1094 |
answerStream nextPut:(self next) |
1 | 1095 |
]. |
329 | 1096 |
^ answerStream contents |
1 | 1097 |
|
275 | 1098 |
" |
1099 |
(ReadStream on:#(1 2 3 4 5)) next:3 |
|
1100 |
(ReadStream on:'hello') next:3 |
|
1101 |
" |
|
1403 | 1102 |
|
1103 |
"Modified: 15.5.1996 / 17:57:58 / cg" |
|
1 | 1104 |
! |
1105 |
||
285 | 1106 |
nextAvailable:count |
1403 | 1107 |
"return the next count elements of the stream as aCollection. |
285 | 1108 |
If the stream reaches the end before count elements have been read, |
1403 | 1109 |
return what is available. (i.e. a shorter collection). |
1110 |
The type of collection is speciefied in #contentsSpecies." |
|
285 | 1111 |
|
345 | 1112 |
|answerStream |
285 | 1113 |
cnt "{ Class: SmallInteger }"| |
1114 |
||
329 | 1115 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 1116 |
cnt := count. |
1117 |
1 to:cnt do:[:index | |
|
2332 | 1118 |
self atEnd ifTrue:[ |
1119 |
^ answerStream contents |
|
1120 |
]. |
|
1121 |
answerStream nextPut:(self next) |
|
285 | 1122 |
]. |
329 | 1123 |
^ answerStream contents |
285 | 1124 |
|
1125 |
" |
|
1126 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
1127 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
1128 |
(ReadStream on:'hello') nextAvailable:3 |
|
1129 |
(ReadStream on:'hello') nextAvailable:10 |
|
1130 |
" |
|
1403 | 1131 |
|
1132 |
"Modified: 15.5.1996 / 17:58:42 / cg" |
|
285 | 1133 |
! |
1134 |
||
1 | 1135 |
nextMatchFor:anObject |
62 | 1136 |
"read an element from the receiver, return true if it was equal to |
1403 | 1137 |
the argument, anObject; false otherwise." |
62 | 1138 |
|
1139 |
^ (self next = anObject) |
|
1140 |
||
1141 |
" |
|
1142 |
|s| |
|
1143 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1144 |
s nextMatchFor:2 |
|
1145 |
" |
|
1146 |
" |
|
1147 |
|s| |
|
1148 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1149 |
s nextMatchFor:2. |
|
1150 |
s nextMatchFor:2 |
|
1151 |
" |
|
1403 | 1152 |
|
1153 |
"Modified: 15.5.1996 / 17:58:57 / cg" |
|
62 | 1154 |
! |
1155 |
||
2253
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1156 |
nextUpTo:anObject |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1157 |
"read a collection of all objects up-to anObject and return these |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1158 |
elements, but excluding anObject. |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1159 |
The next read operation will return anObject. |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1160 |
If anObject is not encountered, all elements up to the end are read |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1161 |
and returned, and the stream is positioned at the end. |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1162 |
Compare this with #upTo: which positions behind anObject" |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1163 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1164 |
|answerStream element| |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1165 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1166 |
answerStream := WriteStream on:(self contentsSpecies new). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1167 |
[self atEnd] whileFalse:[ |
2332 | 1168 |
element := self peek. |
1169 |
(element = anObject) ifTrue: [ |
|
1170 |
^ answerStream contents |
|
1171 |
]. |
|
1172 |
answerStream nextPut:element. |
|
1173 |
self next. |
|
2253
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1174 |
]. |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1175 |
^ answerStream contents |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1176 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1177 |
" |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1178 |
|s| |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1179 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1180 |
Transcript showCR:(s nextUpTo:4). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1181 |
Transcript showCR:s next |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1182 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1183 |
|s| |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1184 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1185 |
Transcript showCR:(s upTo:4). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1186 |
Transcript showCR:s next |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1187 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1188 |
|s| |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1189 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1190 |
Transcript showCR:(s nextUpTo:9). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1191 |
Transcript showCR:s next |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1192 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1193 |
|s| |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1194 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1195 |
Transcript showCR:(s upTo:9). |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1196 |
Transcript showCR:s next |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1197 |
" |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1198 |
|
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1199 |
"Created: 24.1.1997 / 14:08:35 / cg" |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1200 |
"Modified: 24.1.1997 / 14:09:49 / cg" |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1201 |
! |
2ba9ca59f25d
added #nextUpTo: - occasionally, you want to read the separator
Claus Gittinger <cg@exept.de>
parents:
2152
diff
changeset
|
1202 |
|
62 | 1203 |
skip:count |
1204 |
"skip count objects, return the receiver" |
|
1205 |
||
345 | 1206 |
|n "{ Class: SmallInteger }"| |
1207 |
||
1208 |
n := count. |
|
1209 |
||
62 | 1210 |
"dont know how to unread ..." |
345 | 1211 |
n < 0 ifTrue:[ |
2332 | 1212 |
self error:'stream is not positionable'. |
1213 |
^ self |
|
62 | 1214 |
]. |
345 | 1215 |
n timesRepeat:self next |
62 | 1216 |
|
1217 |
" |
|
1218 |
|s| |
|
1219 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1220 |
s skip:4. |
|
1221 |
s next |
|
1222 |
" |
|
1223 |
! |
|
1224 |
||
1225 |
skipFor:anObject |
|
1403 | 1226 |
"skip all objects up-to and including anObject; |
1227 |
return the element after anObject." |
|
62 | 1228 |
|
1229 |
(self skipThrough:anObject) notNil ifTrue:[ |
|
2332 | 1230 |
^ self next |
62 | 1231 |
]. |
1232 |
^ nil |
|
1233 |
||
1234 |
" |
|
1235 |
|s| |
|
1236 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1237 |
s skipFor:4. |
|
1238 |
" |
|
1403 | 1239 |
|
1240 |
"Modified: 15.5.1996 / 17:59:23 / cg" |
|
62 | 1241 |
! |
1242 |
||
1243 |
skipThrough:anObject |
|
77 | 1244 |
"skip all objects up-to and including anObject. Return the receiver if |
671 | 1245 |
skip was successful, otherwise (i.e. if not found) return nil. |
62 | 1246 |
The next read operation will return the element after anObject." |
1 | 1247 |
|
1248 |
|nextElement| |
|
1249 |
||
1250 |
[self atEnd] whileFalse:[ |
|
216 | 1251 |
nextElement := self next. |
1252 |
(nextElement = anObject) ifTrue: [ ^ self ] |
|
1 | 1253 |
]. |
1254 |
^ nil |
|
2 | 1255 |
|
62 | 1256 |
" |
1257 |
|s| |
|
1258 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1259 |
s skipThrough:4. |
|
1260 |
s next |
|
1261 |
" |
|
77 | 1262 |
! |
1263 |
||
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1264 |
skipThroughAll:aCollection |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1265 |
"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
|
1266 |
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
|
1267 |
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
|
1268 |
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
|
1269 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1270 |
|buffer l first idx| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1271 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1272 |
l := aCollection size. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1273 |
first := aCollection at:1. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1274 |
[self atEnd] whileFalse:[ |
2332 | 1275 |
buffer isNil ifTrue:[ |
1276 |
buffer := self nextAvailable:l. |
|
1277 |
]. |
|
1278 |
buffer = aCollection ifTrue:[ |
|
1279 |
^ self |
|
1280 |
]. |
|
1281 |
idx := buffer indexOf:first startingAt:2. |
|
1282 |
idx == 0 ifTrue:[ |
|
1283 |
buffer := nil |
|
1284 |
] ifFalse:[ |
|
1285 |
buffer := (buffer copyFrom:idx) , (self nextAvailable:(idx - 1)) |
|
1286 |
] |
|
2152
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1287 |
]. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1288 |
^ nil |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1289 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1290 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1291 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1292 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1293 |
s skipThroughAll:'901'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1294 |
s upToEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1295 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1296 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1297 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1298 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1299 |
s skipThroughAll:'1234'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1300 |
s upToEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1301 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1302 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1303 |
|s| |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1304 |
s := ReadStream on:'12345678901234567890'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1305 |
s skipThroughAll:'999'. |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1306 |
s atEnd |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1307 |
" |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1308 |
|
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1309 |
"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
|
1310 |
"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
|
1311 |
! |
6a42beaf7cc5
added a skipThroughAll:, which does not depend on being positionable.
Claus Gittinger <cg@exept.de>
parents:
1949
diff
changeset
|
1312 |
|
611 | 1313 |
through:anObject |
1314 |
"read a collection of all objects up-to anObject and return these |
|
1315 |
elements, including anObject. |
|
1316 |
The next read operation will return the element after anObject. |
|
1409 | 1317 |
If anObject is not encountered, all elements up to the end are read |
1318 |
and returned. |
|
611 | 1319 |
Compare this with #upTo: which also reads up to some object |
1320 |
and also positions behind it, but does not include it in the returned |
|
1321 |
value." |
|
1322 |
||
1323 |
|answerStream element| |
|
1324 |
||
1325 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1326 |
[self atEnd] whileFalse:[ |
|
2332 | 1327 |
element := self next. |
1328 |
answerStream nextPut:element. |
|
1329 |
(element = anObject) ifTrue: [ |
|
1330 |
^ answerStream contents |
|
1331 |
] |
|
611 | 1332 |
]. |
1333 |
^ answerStream contents |
|
1334 |
||
1335 |
" |
|
1336 |
|s| |
|
1337 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 1338 |
Transcript showCR:(s through:4). |
1339 |
Transcript showCR:s next |
|
1409 | 1340 |
|
1341 |
|s| |
|
1342 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 1343 |
Transcript showCR:(s through:9). |
1344 |
Transcript showCR:s next |
|
1409 | 1345 |
|
611 | 1346 |
|s| |
1347 |
s := ReadStream on:'hello world'. |
|
1422 | 1348 |
Transcript showCR:(s through:Character space). |
1349 |
Transcript showCR:(s upToEnd) |
|
611 | 1350 |
" |
1409 | 1351 |
|
1352 |
"Modified: 17.5.1996 / 08:51:40 / cg" |
|
611 | 1353 |
! |
1354 |
||
1548 | 1355 |
throughAll:aCollection |
1356 |
"read & return a collection of all objects up-to and including |
|
1357 |
a subcollection given by aCollection. |
|
1358 |
(i.e. read until a ``substring'' is encountered.) |
|
1359 |
The next read operation will return the element after aCollection. |
|
1360 |
If aCollection is not encountered, all elements up to the end are read |
|
1361 |
and returned." |
|
1362 |
||
1363 |
|answerStream element last rslt| |
|
1364 |
||
1365 |
last := aCollection last. |
|
1366 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1367 |
[self atEnd] whileFalse:[ |
|
2332 | 1368 |
element := self next. |
1369 |
answerStream nextPut:element. |
|
1370 |
element == last ifTrue:[ |
|
1371 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
|
1372 |
^ rslt |
|
1373 |
] |
|
1374 |
]. |
|
1548 | 1375 |
]. |
1376 |
^ answerStream contents |
|
1377 |
||
1378 |
" |
|
1379 |
|s| |
|
1380 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1381 |
Transcript showCR:(s throughAll:#(4 4 4)). |
|
1382 |
Transcript showCR:s next |
|
1383 |
||
1384 |
|s| |
|
1385 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1386 |
Transcript showCR:(s throughAll:#(4 5 6)). |
|
1387 |
Transcript showCR:s next |
|
1388 |
||
1389 |
|s| |
|
1390 |
s := ReadStream on:'hello world, this is some text'. |
|
1391 |
Transcript showCR:(s throughAll:'world'). |
|
1392 |
Transcript showCR:(s throughAll:'some'). |
|
1393 |
Transcript showCR:s upToEnd. |
|
1394 |
" |
|
1395 |
||
1396 |
"Modified: 15.7.1996 / 09:08:07 / cg" |
|
1397 |
! |
|
1398 |
||
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1399 |
throughAny:aCollection |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1400 |
"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
|
1401 |
an element contained in aCollection. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1402 |
(i.e. read until any from aCollection is encountered.) |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1403 |
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
|
1404 |
and returned." |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1405 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1406 |
|answerStream element last| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1407 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1408 |
last := aCollection last. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1409 |
answerStream := WriteStream on:(self contentsSpecies new). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1410 |
[self atEnd] whileFalse:[ |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1411 |
element := self next. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1412 |
answerStream nextPut:element. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1413 |
(aCollection includes:element) ifTrue:[ |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1414 |
^ answerStream contents |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1415 |
]. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1416 |
]. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1417 |
^ answerStream contents |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1418 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1419 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1420 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1421 |
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
|
1422 |
Transcript showCR:(s throughAny:#(3 4 5)). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1423 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1424 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1425 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1426 |
s := ReadStream on:'hello world, this is some text'. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1427 |
Transcript showCR:(s throughAny:'wt'). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1428 |
Transcript showCR:(s throughAny:'wt'). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1429 |
Transcript showCR:s upToEnd. |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1430 |
" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1431 |
|
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1432 |
"Modified: / 11.1.1998 / 15:28:04 / cg" |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1433 |
! |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1434 |
|
427 | 1435 |
upTo:anObject |
1436 |
"read a collection of all objects up-to anObject and return these |
|
1437 |
elements, but excluding anObject. |
|
1438 |
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
|
1439 |
(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
|
1440 |
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
|
1441 |
returned collection. |
1409 | 1442 |
If anObject is not encountered, all elements up to the end are read |
1443 |
and returned. |
|
427 | 1444 |
Compare this with #through: which also reads up to some object |
1445 |
and also positions behind it, but DOES include it in the returned |
|
1446 |
value." |
|
1447 |
||
1448 |
|answerStream element| |
|
1449 |
||
1450 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1451 |
[self atEnd] whileFalse:[ |
|
3176 | 1452 |
element := self next. |
1453 |
(element = anObject) ifTrue: [ |
|
1454 |
^ answerStream contents |
|
1455 |
]. |
|
1456 |
answerStream nextPut:element. |
|
427 | 1457 |
]. |
1458 |
^ answerStream contents |
|
1459 |
||
1460 |
" |
|
1461 |
|s| |
|
1462 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1422 | 1463 |
Transcript showCR:(s upTo:4). |
1464 |
Transcript showCR:s next |
|
427 | 1465 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1466 |
compare the above to: |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1467 |
|s| |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1468 |
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
|
1469 |
Transcript showCR:(s through:4). |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1470 |
Transcript showCR:s next |
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1471 |
|
427 | 1472 |
|s| |
1409 | 1473 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
1422 | 1474 |
Transcript showCR:(s upTo:9). |
1475 |
Transcript showCR:s next |
|
1409 | 1476 |
|
1477 |
|s| |
|
427 | 1478 |
s := ReadStream on:'hello world'. |
1422 | 1479 |
Transcript showCR:(s upTo:Character space). |
1480 |
Transcript showCR:(s upToEnd) |
|
427 | 1481 |
|
1482 |
(ReadStream on:'12345678905') upTo:$5; upTo:$5 |
|
1483 |
||
1484 |
(ReadStream on:'123456') upTo:$7 |
|
1485 |
||
1486 |
(ReadStream on:#(1 2 3 4 5 6)) upTo:4 |
|
1487 |
||
1488 |
(ReadStream on:'line 1 |
|
3176 | 1489 |
line 2') upTo:Character cr |
427 | 1490 |
|
1491 |
'Makefile' asFilename readStream upTo:Character cr;upTo:Character cr |
|
1492 |
" |
|
1409 | 1493 |
|
3169
cef3b9a6de2c
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3154
diff
changeset
|
1494 |
"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
|
1495 |
"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
|
1496 |
! |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1497 |
|
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1498 |
upToAll:aCollection |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1499 |
"read until a subcollection consisisting of the elements in aCollection |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1500 |
is encountered. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1501 |
Return everything read excluding the elements in aCollection. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1502 |
The next read operation will return the element after aCollection. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1503 |
(i.e. aCollection is considered a separator, which is skipped) |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1504 |
Similar to #throughAll:, but the matching object is not included in the |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1505 |
returned collection. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1506 |
If no such subcollection is encountered, all elements up to the end |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1507 |
are read and returned. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1508 |
Compare this with #throughAll: which also reads up to aCollection |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1509 |
but positions behind it and DOES include it in the returned |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1510 |
collection." |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1511 |
|
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1512 |
|answerStream element last rslt| |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1513 |
|
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1514 |
last := aCollection last. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1515 |
answerStream := WriteStream on:(self contentsSpecies new). |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1516 |
[self atEnd] whileFalse:[ |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1517 |
element := self next. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1518 |
answerStream nextPut:element. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1519 |
element == last ifTrue:[ |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1520 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1521 |
^ rslt copyWithoutLast:aCollection size |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1522 |
] |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1523 |
]. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1524 |
]. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1525 |
^ answerStream contents |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1526 |
|
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1527 |
" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1528 |
|s| |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1529 |
s := ReadStream on:'hello world'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1530 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1531 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1532 |
" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1533 |
" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1534 |
|s| |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1535 |
s := ReadStream on:'hello world'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1536 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1537 |
Transcript showCR:s atEnd. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1538 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1539 |
" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1540 |
|
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1541 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1542 |
"Created: / 15.1.1998 / 23:28:20 / stefan" |
f73912c49864
Implement #upToAll: consistent with #upTo: and #upToAny: in Stream.
Stefan Vogel <sv@exept.de>
parents:
3169
diff
changeset
|
1543 |
"Modified: / 15.1.1998 / 23:29:26 / stefan" |
2894 | 1544 |
! |
1545 |
||
1546 |
upToAny:aCollectionOfObjects |
|
2420 | 1547 |
"read a collection of all objects up-to a element which is contained in |
1548 |
aCollectionOfObjects and return these elements, but excluding the matching one. |
|
1549 |
The next read operation will return the element after anObject. |
|
1550 |
If no such element is encountered, all elements up to the end are read |
|
1551 |
and returned. |
|
1552 |
Compare this with #throughAll: which also reads up to some object |
|
1553 |
and also positions behind it, but DOES include it in the returned |
|
1554 |
value." |
|
1555 |
||
1556 |
|answerStream element| |
|
1557 |
||
1558 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1559 |
[self atEnd] whileFalse:[ |
|
3154 | 1560 |
element := self next. |
1561 |
(aCollectionOfObjects includes:element) ifTrue: [ |
|
1562 |
^ answerStream contents |
|
1563 |
]. |
|
1564 |
answerStream nextPut:element. |
|
2420 | 1565 |
]. |
1566 |
^ answerStream contents |
|
1567 |
||
1568 |
" |
|
1569 |
|s| |
|
1570 |
s := ReadStream on:'hello world'. |
|
3154 | 1571 |
Transcript showCR:(s upToAny:(Array with:Character space)). |
2420 | 1572 |
Transcript showCR:(s upToEnd) |
1573 |
||
3154 | 1574 |
'Makefile' asFilename readStream upToAny:($A to:$Z) |
1575 |
" |
|
2420 | 1576 |
|
3154 | 1577 |
"Created: / 30.8.1997 / 03:02:05 / cg" |
1578 |
"Modified: / 11.1.1998 / 15:19:18 / cg" |
|
2420 | 1579 |
! |
1580 |
||
77 | 1581 |
upToEnd |
1582 |
"return a collection of the elements up-to the end. |
|
1403 | 1583 |
Return an empty collection, if the stream-end is already at the end." |
77 | 1584 |
|
1585 |
|answerStream| |
|
1586 |
||
1587 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1588 |
[self atEnd] whileFalse:[ |
|
2332 | 1589 |
answerStream nextPut:(self next) |
77 | 1590 |
]. |
1591 |
^ answerStream contents |
|
1592 |
||
275 | 1593 |
" |
1594 |
(ReadStream on:'1234567890') upToEnd |
|
1595 |
('123456' readStream) next; next; upToEnd |
|
427 | 1596 |
('1 23456' readStream) upTo:Character space; upToEnd |
1403 | 1597 |
('12' readStream) next; next; upToEnd |
275 | 1598 |
" |
1403 | 1599 |
|
1600 |
"Modified: 15.5.1996 / 18:00:39 / cg" |
|
611 | 1601 |
! ! |
77 | 1602 |
|
3084 | 1603 |
!Stream methodsFor:'reading - strings'! |
1604 |
||
1605 |
nextAlphaNumericWord |
|
1606 |
"read the next word (i.e. up to non letter-or-digit). |
|
1607 |
Return a string containing those characters. |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1608 |
Any leading non-alphaNumeric chars are skipped." |
3084 | 1609 |
|
1610 |
|s c| |
|
1611 |
||
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1612 |
[self atEnd |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1613 |
or:[(c := self peek) isAlphaNumeric]] whileFalse:[ |
3084 | 1614 |
self next |
1615 |
]. |
|
1616 |
||
1617 |
self atEnd ifTrue:[^ nil]. |
|
1618 |
||
1619 |
s := ''. |
|
1620 |
||
1621 |
[self atEnd not |
|
1622 |
and:[(c := self peek) isLetterOrDigit]] whileTrue:[ |
|
1623 |
s := s copyWith:c. |
|
1624 |
self next |
|
1625 |
]. |
|
1626 |
||
1627 |
s size == 0 ifTrue:[^ nil]. |
|
1628 |
^ s. |
|
1629 |
||
1630 |
" |
|
1631 |
|s| |
|
1632 |
||
1633 |
s := 'hello world 1234 foo1 foo2' readStream. |
|
1634 |
[s atEnd] whileFalse:[ |
|
1635 |
Transcript showCR:(s nextAlphaNumericWord). |
|
1636 |
]. |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1637 |
" |
3084 | 1638 |
|
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1639 |
" |
3084 | 1640 |
|s| |
1641 |
||
3112
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1642 |
s := 'hello +++ #world ###123###abc### 1234 foo1 foo2' readStream. |
ccf7121ddae8
nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents:
3106
diff
changeset
|
1643 |
[s atEnd] whileFalse:[ |
3084 | 1644 |
Transcript showCR:(s nextAlphaNumericWord). |
1645 |
]. |
|
1646 |
" |
|
1647 |
||
1648 |
"Modified: 15.5.1996 / 17:51:42 / cg" |
|
1649 |
! |
|
1650 |
||
1651 |
nextLine |
|
1652 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
1653 |
character (i.e. read a single line of text). |
|
1654 |
Added for protocol compatibility with externalStreams." |
|
1655 |
||
1656 |
^ self upTo:Character cr. |
|
1657 |
||
1658 |
"Modified: 11.7.1996 / 10:03:56 / cg" |
|
1659 |
! |
|
1660 |
||
1661 |
nextWord |
|
1662 |
"return the next characters which form an alphanumeric word |
|
1663 |
(i.e. everything upTo (but excluding) the next non alphanumeric |
|
1664 |
element)" |
|
1665 |
||
1666 |
^ self nextAlphaNumericWord |
|
1667 |
||
1668 |
"Modified: 15.5.1996 / 17:39:32 / cg" |
|
1669 |
! ! |
|
1670 |
||
611 | 1671 |
!Stream methodsFor:'testing'! |
77 | 1672 |
|
611 | 1673 |
atEnd |
1674 |
"return true if the end of the stream has been reached; |
|
1675 |
- we do not know here how to do it, it must be redefined in subclass" |
|
77 | 1676 |
|
611 | 1677 |
^ self subclassResponsibility |
1 | 1678 |
! ! |
1679 |
||
62 | 1680 |
!Stream methodsFor:'writing'! |
1 | 1681 |
|
339 | 1682 |
commit |
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1683 |
"alias for flush -- ST80 compatibility" |
339 | 1684 |
|
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1685 |
^ self flush |
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1686 |
|
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1687 |
"Modified: 7.5.1996 / 23:55:39 / stefan" |
339 | 1688 |
! |
1689 |
||
611 | 1690 |
cr |
1403 | 1691 |
"append a carriage-return to the stream. |
1692 |
This is only allowed, if the receiver supports writing." |
|
611 | 1693 |
|
1694 |
self nextPut:(Character cr) |
|
1403 | 1695 |
|
1696 |
"Modified: 15.5.1996 / 18:01:21 / cg" |
|
611 | 1697 |
! |
1698 |
||
1699 |
crTab |
|
1700 |
"append a carriage-return followed by a tab to the stream. |
|
1403 | 1701 |
Same as crtab for ST/X backward compatibility. |
1702 |
This is only allowed, if the receiver supports writing." |
|
611 | 1703 |
|
1704 |
self obsoleteMethodWarning:'use crTab'. |
|
1705 |
self crtab |
|
1403 | 1706 |
|
1707 |
"Modified: 15.5.1996 / 18:01:28 / cg" |
|
611 | 1708 |
! |
1709 |
||
1710 |
crtab |
|
1403 | 1711 |
"append a carriage-return followed by a tab to the stream. |
1712 |
This is only allowed, if the receiver supports writing." |
|
1 | 1713 |
|
611 | 1714 |
self crtab:1 |
1403 | 1715 |
|
1716 |
"Modified: 15.5.1996 / 18:01:35 / cg" |
|
611 | 1717 |
! |
1718 |
||
1719 |
crtab:n |
|
1403 | 1720 |
"append a carriage-return followed by n tabs to the stream. |
1721 |
This is only allowed, if the receiver supports writing." |
|
611 | 1722 |
|
1723 |
self nextPut:(Character cr). |
|
1724 |
self next:n put:(Character tab) |
|
1403 | 1725 |
|
1726 |
"Modified: 15.5.1996 / 18:01:39 / cg" |
|
611 | 1727 |
! |
1728 |
||
1729 |
endEntry |
|
1730 |
"ignored here - for compatibility with Transcript" |
|
1731 |
||
1732 |
^ self |
|
1733 |
! |
|
1734 |
||
1735 |
ff |
|
1403 | 1736 |
"append a form-feed (new-pagee) to the receiver-stream. |
1737 |
This is only allowed, if the receiver supports writing." |
|
611 | 1738 |
|
1739 |
self nextPut:(Character ff) |
|
1403 | 1740 |
|
1741 |
"Modified: 15.5.1996 / 18:01:47 / cg" |
|
1 | 1742 |
! |
1743 |
||
701 | 1744 |
flush |
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1745 |
"write out all unbuffered data - ignored here, but added |
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1746 |
to make internalStreams protocol compatible with externalStreams" |
701 | 1747 |
|
1462
7196fe152248
Cleanup #flush and #commit handling.
Stefan Vogel <sv@exept.de>
parents:
1448
diff
changeset
|
1748 |
"Modified: 7.5.1996 / 23:54:53 / stefan" |
701 | 1749 |
! |
1750 |
||
1 | 1751 |
next:count put:anObject |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1752 |
"put the argument, anObject count times onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1753 |
This is only allowed, if the receiver supports writing." |
1 | 1754 |
|
345 | 1755 |
|n "{ Class: SmallInteger }"| |
1756 |
||
1757 |
n := count. |
|
1758 |
n timesRepeat:[self nextPut:anObject]. |
|
1 | 1759 |
^ anObject |
62 | 1760 |
|
1761 |
" |
|
1762 |
|s| |
|
1763 |
||
1764 |
s := WriteStream on:#(). |
|
1765 |
s nextPut:1. |
|
1766 |
s next:5 put:2. |
|
1767 |
s nextPut:3. |
|
1768 |
s contents |
|
1769 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1770 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1771 |
"Modified: 11.7.1996 / 10:00:13 / cg" |
1 | 1772 |
! |
1773 |
||
611 | 1774 |
nextPut:anObject |
1775 |
"put the argument, anObject onto the receiver |
|
1776 |
- we do not know here how to do it, it must be redefined in subclass" |
|
1777 |
||
1778 |
^ self subclassResponsibility |
|
1779 |
! |
|
1780 |
||
1 | 1781 |
nextPutAll:aCollection |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1782 |
"put all elements of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1783 |
This is only allowed, if the receiver supports writing." |
1 | 1784 |
|
1785 |
aCollection do:[:element | |
|
2332 | 1786 |
self nextPut:element |
1 | 1787 |
]. |
1788 |
^ aCollection |
|
62 | 1789 |
|
1790 |
" |
|
1791 |
|s| |
|
1792 |
||
1793 |
s := WriteStream on:#(). |
|
1794 |
s nextPutAll:(1 to:5). |
|
1795 |
s nextPutAll:#('one' 'two' 'three'). |
|
1796 |
s contents |
|
1797 |
" |
|
1798 |
" |
|
1799 |
|s| |
|
1800 |
||
1801 |
s := WriteStream on:(String new). |
|
1802 |
s nextPutAll:($a to:$f). |
|
1803 |
s nextPutAll:'one '; |
|
1804 |
nextPutAll:'two '; |
|
1805 |
nextPutAll:'three'. |
|
1806 |
s contents |
|
1807 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1808 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1809 |
"Modified: 11.7.1996 / 10:00:21 / cg" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1810 |
! |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1811 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1812 |
nextPutAll:aCollection startingAt:first |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1813 |
"append the elements starting with index to the end |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1814 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1815 |
This is only allowed, if the receiver supports writing." |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1816 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1817 |
self nextPutAll:aCollection startingAt:first to:(aCollection size). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1818 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1819 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1820 |
|s| |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1821 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1822 |
s := WriteStream on:#(). |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1823 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1824 |
s contents |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1825 |
" |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1826 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1827 |
"Modified: 11.7.1996 / 10:00:28 / cg" |
1 | 1828 |
! |
1829 |
||
1830 |
nextPutAll:aCollection startingAt:first to:last |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1831 |
"append the elements with index from first to last |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1832 |
of the argument, aCollection onto the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1833 |
This is only allowed, if the receiver supports writing." |
1 | 1834 |
|
1835 |
aCollection from:first to:last do:[:element | |
|
2332 | 1836 |
self nextPut:element |
1 | 1837 |
]. |
1838 |
^ aCollection |
|
62 | 1839 |
|
1840 |
" |
|
1841 |
|s| |
|
1842 |
||
1843 |
s := WriteStream on:#(). |
|
1844 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4. |
|
1845 |
s contents |
|
1846 |
" |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1847 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1848 |
"Modified: 11.7.1996 / 10:00:32 / cg" |
1 | 1849 |
! |
1850 |
||
743 | 1851 |
nextPutLine:aCollection |
1852 |
"put all elements of the argument, aCollection onto the receiver, |
|
1949 | 1853 |
and append a cr (carriage return). |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1854 |
This is only useful with character streams in textMode, |
1949 | 1855 |
and only allowed, if the receiver supports writing." |
743 | 1856 |
|
1857 |
self nextPutAll:aCollection. |
|
1858 |
self cr. |
|
1859 |
||
1860 |
"Created: 13.12.1995 / 10:49:17 / cg" |
|
1949 | 1861 |
"Modified: 8.11.1996 / 23:53:41 / cg" |
743 | 1862 |
! |
1863 |
||
611 | 1864 |
print:anObject |
1865 |
"append a printed representation of anObject to the receiver. |
|
1403 | 1866 |
Same as 'anObject printOn:self'; Added for ST-80 compatibility." |
2 | 1867 |
|
611 | 1868 |
anObject printOn:self |
1403 | 1869 |
|
1870 |
" |
|
1871 |
|s| |
|
1872 |
||
1873 |
s := WriteStream on:''. |
|
1874 |
s nextPutAll:'one '; |
|
1875 |
print:1; |
|
1876 |
nextPutAll:' two '; |
|
1877 |
print:2. |
|
1878 |
||
1879 |
s contents |
|
1880 |
" |
|
1881 |
||
1882 |
"Modified: 15.5.1996 / 18:06:06 / cg" |
|
2 | 1883 |
! |
1884 |
||
1403 | 1885 |
show:something |
1886 |
"append a printed representation of the argument to the stream. |
|
1887 |
This makes streams somewhat compatible to TextCollectors and |
|
1888 |
allows you to say: |
|
2332 | 1889 |
Smalltalk at:#Transcript put:Stdout |
1422 | 1890 |
or to use #show:/#showCR: with internal or external streams." |
1 | 1891 |
|
1403 | 1892 |
^ self nextPutAll:something printString |
1893 |
||
1894 |
"Modified: 15.5.1996 / 18:04:48 / cg" |
|
1 | 1895 |
! |
1896 |
||
1414 | 1897 |
showCR:aString |
1403 | 1898 |
"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
|
1899 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1900 |
This makes streams somewhat compatible to TextCollectors and |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1901 |
allows you to say: |
2332 | 1902 |
Smalltalk at:#Transcript put:Stdout |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1903 |
or to use #show:/#showCR: with internal or external streams." |
1 | 1904 |
|
1905 |
self show:aString. |
|
1906 |
self cr |
|
1403 | 1907 |
|
1414 | 1908 |
"Created: 18.5.1996 / 15:34:17 / cg" |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1909 |
"Modified: 11.7.1996 / 10:01:27 / cg" |
1414 | 1910 |
! |
1911 |
||
1912 |
showCr:aString |
|
1913 |
"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
|
1914 |
and append a newline character. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1915 |
This is obsolete ST/X backward compatibility; use #showCR:" |
1414 | 1916 |
|
1917 |
self obsoleteMethodWarning:'use #showCR:'. |
|
1918 |
self showCR:aString. |
|
1919 |
||
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1920 |
"Modified: 11.7.1996 / 10:01:50 / cg" |
62 | 1921 |
! |
1922 |
||
1923 |
space |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1924 |
"append a space character to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1925 |
This is only allowed, if the receiver supports writing." |
62 | 1926 |
|
1927 |
self nextPut:(Character space) |
|
1403 | 1928 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1929 |
"Modified: 11.7.1996 / 10:02:06 / cg" |
62 | 1930 |
! |
1931 |
||
1932 |
spaces:count |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1933 |
"append count space-characters to the receiver. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1934 |
This is only allowed, if the receiver supports writing." |
62 | 1935 |
|
1936 |
self next:count put:(Character space) |
|
1403 | 1937 |
|
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1938 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
62 | 1939 |
! |
1940 |
||
611 | 1941 |
store:anObject |
1942 |
"append a printed representation of anObject to the receiver, |
|
1403 | 1943 |
from which the receiver can be reconstructed (i.e. its storeString). |
1944 |
Same as 'anObject storeOn:self'; Added for ST-80 compatibility." |
|
77 | 1945 |
|
611 | 1946 |
anObject storeOn:self |
1403 | 1947 |
|
1948 |
"Modified: 15.5.1996 / 18:05:55 / cg" |
|
77 | 1949 |
! |
1950 |
||
611 | 1951 |
tab |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1952 |
"append a tab-character to the stream. |
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1953 |
This is only allowed, if the receiver supports writing." |
77 | 1954 |
|
611 | 1955 |
self nextPut:(Character tab) |
1538
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1956 |
|
b62f12073403
commentary; added #nextPutAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
1462
diff
changeset
|
1957 |
"Modified: 11.7.1996 / 10:02:20 / cg" |
2443 | 1958 |
! |
1959 |
||
1960 |
tab:count |
|
1961 |
"append count tab-characters to the receiver. |
|
1962 |
This is only allowed, if the receiver supports writing." |
|
1963 |
||
1964 |
self next:count put:(Character tab) |
|
1965 |
||
1966 |
"Modified: 11.7.1996 / 10:02:10 / cg" |
|
77 | 1967 |
! ! |
1968 |
||
1949 | 1969 |
!Stream class methodsFor:'documentation'! |
701 | 1970 |
|
1971 |
version |
|
3176 | 1972 |
^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.70 1998-01-16 14:54:52 cg Exp $' |
701 | 1973 |
! ! |
611 | 1974 |
Stream initialize! |