author | Claus Gittinger <cg@exept.de> |
Thu, 21 Mar 1996 16:33:40 +0100 | |
changeset 1113 | 840b03d131d7 |
parent 970 | 3b59c9b38dbb |
child 1117 | f64e35e18e65 |
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 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
13 |
'From Smalltalk/X, Version:2.10.8 on 6-feb-1996 at 15:31:21' ! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
14 |
|
1 | 15 |
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
|
16 |
instanceVariableNames:'signalAtEnd' |
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
17 |
classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
18 |
WriteErrorSignal EndOfStreamSignal' |
743 | 19 |
poolDictionaries:'' |
20 |
category:'Streams' |
|
1 | 21 |
! |
22 |
||
88 | 23 |
!Stream class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
216 | 28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
An abstract class defining common behavior for all stream-like objects. |
|
42 |
See concrete subclasses for more detail. |
|
345 | 43 |
|
44 |
Subclasses should (at least) implement: |
|
45 |
#next (if readable) |
|
46 |
#nextPut: (if writable) |
|
47 |
#contents |
|
48 |
#atEnd |
|
49 |
#isReadable |
|
50 |
#isWritable |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
51 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
52 |
Class variables: |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
53 |
StreamErrorSignal <Signal> parent of all stream errors |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
54 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
55 |
PositionErrorSignal <Signal> position attemted on a stream |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
56 |
which does not support positioning |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
57 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
58 |
ReadErrorSignal <Signal> raised on read errors |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
59 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
60 |
WriteErrorSignal <Signal> raised on write errors |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
61 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
62 |
EndOfStreamSignal <Signal> raised at end of stream |
88 | 63 |
" |
64 |
! ! |
|
1 | 65 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
66 |
!Stream class methodsFor:'initialization'! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
67 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
68 |
initialize |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
69 |
StreamErrorSignal isNil ifTrue:[ |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
70 |
StreamErrorSignal := ErrorSignal newSignalMayProceed:false. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
71 |
StreamErrorSignal nameClass:self message:#streamErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
72 |
StreamErrorSignal notifierString:'Stream error'. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
73 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
74 |
PositionErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
75 |
PositionErrorSignal nameClass:self message:#positionErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
76 |
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
|
77 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
78 |
ReadErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
79 |
ReadErrorSignal nameClass:self message:#readErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
80 |
ReadErrorSignal notifierString:'read error'. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
81 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
82 |
WriteErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
83 |
WriteErrorSignal nameClass:self message:#writeErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
84 |
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
|
85 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
86 |
EndOfStreamSignal := StreamErrorSignal newSignalMayProceed:false. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
87 |
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
|
88 |
EndOfStreamSignal notifierString:'end of stream'. |
593
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 |
! ! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
91 |
|
611 | 92 |
!Stream class methodsFor:'instance creation'! |
93 |
||
94 |
new |
|
95 |
"report an error - Streams are created using on:-messages" |
|
96 |
||
97 |
^ self error:'Streams cannot be created with new' |
|
98 |
! ! |
|
99 |
||
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
100 |
!Stream class methodsFor:'Signal constants'! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
101 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
102 |
endOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
103 |
"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
|
104 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
105 |
^ EndOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
106 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
107 |
|
611 | 108 |
positionErrorSignal |
109 |
"return the signal raised if positioning is requested for |
|
110 |
a stream which does not support that kind of operation" |
|
111 |
||
112 |
^ PositionErrorSignal |
|
113 |
! |
|
114 |
||
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
115 |
readErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
116 |
"return the signal raised on read errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
117 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
118 |
^ ReadErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
119 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
120 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
121 |
streamErrorSignal |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
122 |
"return the parent of all stream errors; |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
123 |
handling this one also handles all other errors. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
124 |
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
|
125 |
operations, such as failed ioctls in externalStream etc." |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
126 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
127 |
^ StreamErrorSignal |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
128 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
129 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
130 |
writeErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
131 |
"return the signal raised on write errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
132 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
133 |
^ WriteErrorSignal |
1 | 134 |
! ! |
135 |
||
136 |
!Stream methodsFor:'accessing'! |
|
137 |
||
138 |
contents |
|
62 | 139 |
"return the entire contents of the stream |
1 | 140 |
- we do not know here how to do it, it must be redefined in subclass" |
141 |
||
142 |
^ self subclassResponsibility |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
143 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
144 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
145 |
signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
146 |
"return signalAtEnd" |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
147 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
148 |
^ signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
149 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
150 |
"Created: 5.2.1996 / 18:24:53 / stefan" |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
151 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
152 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
153 |
signalAtEnd:something |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
154 |
"set signalAtEnd" |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
155 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
156 |
signalAtEnd := something. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
157 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
158 |
"Created: 5.2.1996 / 18:24:53 / stefan" |
1 | 159 |
! ! |
160 |
||
611 | 161 |
!Stream methodsFor:'closing'! |
162 |
||
163 |
close |
|
164 |
"close the stream - nothing done here. |
|
165 |
Added for compatibility with external streams." |
|
166 |
||
167 |
^ self |
|
168 |
! ! |
|
169 |
||
170 |
!Stream methodsFor:'enumerating'! |
|
171 |
||
172 |
do:aBlock |
|
173 |
"evaluate the argument, aBlock for all remaining elements, |
|
174 |
up to the end of the stream" |
|
175 |
||
176 |
[self atEnd] whileFalse:[ |
|
177 |
aBlock value:(self next) |
|
178 |
] |
|
179 |
||
180 |
" |
|
181 |
|s| |
|
182 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
183 |
s next. |
|
184 |
s next. |
|
185 |
s do:[:element | Transcript showCr:element] |
|
186 |
" |
|
187 |
! ! |
|
188 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
189 |
!Stream methodsFor:'error handling'! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
190 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
191 |
pastEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
192 |
"someone tried to read after the end of the stream. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
193 |
if signalAtEnd == true, raise a signal. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
194 |
Otherwise return nil." |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
195 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
196 |
signalAtEnd == true ifTrue:[ |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
197 |
^ EndOfStreamSignal raiseIn:thisContext sender |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
198 |
]. |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
199 |
^ nil |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
200 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
201 |
"Created: 5.2.1996 / 21:56:08 / stefan" |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
202 |
! ! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
203 |
|
611 | 204 |
!Stream methodsFor:'misc'! |
205 |
||
206 |
binary |
|
207 |
"switch to binary mode. ignored here, but added to make |
|
208 |
internalStreams protocol compatible with externStreams." |
|
209 |
||
210 |
! ! |
|
211 |
||
212 |
!Stream methodsFor:'non homogenous reading'! |
|
213 |
||
214 |
nextLine |
|
215 |
"for compatibility with externalStreams" |
|
216 |
||
217 |
^ self upTo:Character cr. |
|
218 |
! |
|
219 |
||
220 |
nextLongMSB:msbFlag |
|
221 |
"return a signed long (4 bytes) from the stream. |
|
222 |
The receiver must support reading of binary bytes." |
|
223 |
||
224 |
|high uval "{ Class: SmallInteger }"| |
|
225 |
||
226 |
msbFlag ifTrue:[ |
|
227 |
"most significant first" |
|
228 |
high := self next. |
|
229 |
uval := self next bitShift:16. |
|
230 |
uval := uval bitOr:(self next bitShift:8). |
|
231 |
uval := uval bitOr:(self next). |
|
232 |
uval := uval bitOr:(high bitShift:24). |
|
233 |
] ifFalse:[ |
|
234 |
"least significant first" |
|
235 |
uval := self next. |
|
236 |
uval := uval bitOr:(self next bitShift:8). |
|
237 |
uval := uval bitOr:(self next bitShift:16). |
|
238 |
uval := uval bitOr:(self next bitShift:24). |
|
239 |
]. |
|
240 |
"change from unsigned 0..FFFFFFFF to signed -80000000..7FFFFFFF" |
|
241 |
||
242 |
"sorry- for now, stc cannot compile LargeInteger constants |
|
243 |
uval >= 16r80000000 ifTrue:[ |
|
244 |
^ uval - 16r100000000 |
|
245 |
]. |
|
246 |
the following kludges around this" |
|
247 |
(uval bitShift:-16) >= 16r8000 ifTrue:[ |
|
248 |
^ uval - (16r10000000 bitShift:8) |
|
249 |
]. |
|
250 |
^ uval |
|
251 |
! |
|
252 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
253 |
nextLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
254 |
"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
|
255 |
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
|
256 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
257 |
^ self nextLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
258 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
259 |
"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
|
260 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
261 |
|
611 | 262 |
nextNumber:n |
263 |
"Return the next n bytes as a positive Integer; bytes are taken msb-first." |
|
264 |
||
265 |
|s |
|
266 |
val "{ Class: SmallInteger }" |
|
267 |
rep "{ Class: SmallInteger }"| |
|
268 |
||
269 |
"claus: this method is central in binaryStorage - |
|
270 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
271 |
||
272 |
n == 1 ifTrue:[ |
|
273 |
^ self next |
|
274 |
]. |
|
275 |
n == 2 ifTrue:[ |
|
276 |
val := self next. |
|
277 |
val := (val bitShift:8) + self next. |
|
278 |
^ val |
|
279 |
]. |
|
280 |
n == 3 ifTrue:[ |
|
281 |
val := self next. |
|
282 |
val := (val bitShift:8) + self next. |
|
283 |
val := (val bitShift:8) + self next. |
|
284 |
^ val |
|
285 |
]. |
|
286 |
n == 4 ifTrue:[ |
|
287 |
val := self next. |
|
288 |
val <= 16r3F ifTrue:[ |
|
289 |
val := (val bitShift:8) + self next. |
|
290 |
val := (val bitShift:8) + self next. |
|
291 |
val := (val bitShift:8) + self next. |
|
292 |
^ val |
|
293 |
]. |
|
294 |
"sorry, but need a largeInteger" |
|
295 |
s := (val bitShift:8) + self next. |
|
296 |
s := (s bitShift:8) + self next. |
|
297 |
"the multiplication below is a temporary workaround for the |
|
298 |
inability of smallintegers to handle shifts out of the 32bit range ..." |
|
299 |
s := (s * 256) + self next. |
|
300 |
^ s |
|
301 |
]. |
|
302 |
||
303 |
" |
|
304 |
arbitrary long |
|
305 |
" |
|
306 |
s := 0. |
|
307 |
rep := n. |
|
308 |
rep timesRepeat:[ |
|
309 |
s := s * 256 + self next |
|
310 |
]. |
|
311 |
^ s truncated |
|
312 |
! |
|
313 |
||
314 |
nextShortMSB:msbFlag |
|
315 |
"return a signed short (2 bytes) from the stream. |
|
316 |
The receiver must support reading of binary bytes." |
|
317 |
||
318 |
|uval "{ Class: SmallInteger }"| |
|
319 |
||
320 |
msbFlag ifTrue:[ |
|
321 |
"most significant first" |
|
322 |
uval := self next bitShift:8. |
|
323 |
uval := uval bitOr:(self next). |
|
324 |
] ifFalse:[ |
|
325 |
"least significant first" |
|
326 |
uval := self next. |
|
327 |
uval := uval bitOr:(self next bitShift:8). |
|
328 |
]. |
|
329 |
"change from unsigned 0..FFFF to signed -8000..7FFF" |
|
330 |
uval >= 16r8000 ifTrue:[ |
|
331 |
^ uval - 16r10000 |
|
332 |
]. |
|
333 |
^ uval |
|
334 |
! |
|
335 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
336 |
nextShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
337 |
"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
|
338 |
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
|
339 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
340 |
^ self nextShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
341 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
342 |
"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
|
343 |
"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
|
344 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
345 |
|
611 | 346 |
nextUnsignedLongMSB:msbFlag |
347 |
"return an unsigned long (4 bytes) from the stream. |
|
348 |
The receiver must support reading of binary bytes." |
|
349 |
||
350 |
|val| |
|
351 |
||
352 |
msbFlag ifTrue:[ |
|
353 |
val := self next. |
|
354 |
val := (val bitShift:8) bitOr:(self next). |
|
355 |
val := (val bitShift:8) bitOr:(self next). |
|
356 |
val := (val * 256) + (self next). |
|
357 |
^ val |
|
358 |
]. |
|
359 |
val := self next. |
|
360 |
^ (val bitShift:24) |
|
361 |
+ (self next bitShift:16) |
|
362 |
+ (self next bitShift:8) |
|
363 |
+ self next |
|
364 |
! |
|
365 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
366 |
nextUnsignedLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
367 |
"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
|
368 |
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
|
369 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
370 |
^ self nextUnsignedLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
371 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
372 |
"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
|
373 |
"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
|
374 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
375 |
|
611 | 376 |
nextUnsignedShortMSB:msbFlag |
377 |
"return an unsigned short (2 bytes) from the stream. |
|
378 |
The receiver must support reading of binary bytes." |
|
379 |
||
380 |
msbFlag ifTrue:[ |
|
381 |
^ (self next bitShift:8) bitOr:(self next) |
|
382 |
]. |
|
383 |
^ (self next) bitOr:(self next bitShift:8) |
|
384 |
! |
|
385 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
386 |
nextUnsignedShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
387 |
"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
|
388 |
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
|
389 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
390 |
^ self nextUnsignedShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
391 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
392 |
"Created: 10.1.1996 / 19:50:02 / cg" |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
393 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
394 |
|
611 | 395 |
nextWord |
396 |
^ self nextAlphaNumericWord |
|
397 |
! ! |
|
398 |
||
399 |
!Stream methodsFor:'non homogenous writing'! |
|
400 |
||
401 |
nextLongPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
402 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
403 |
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
|
404 |
The most significant byte is sent first." |
611 | 405 |
|
406 |
^ self nextPutLong:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
407 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
408 |
"Modified: 10.1.1996 / 19:38:54 / cg" |
611 | 409 |
! |
410 |
||
411 |
nextNumber:n put:v |
|
412 |
"Append to the receiver the argument, v, which is a positive Integer, |
|
413 |
as the next n bytes. Bytes are written msb first. |
|
414 |
Possibly pad with leading zeros. |
|
415 |
The receiver must support writing of binary bytes." |
|
416 |
||
417 |
|vlen i| |
|
418 |
||
419 |
"claus: this method is central in binaryStorage - |
|
420 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
421 |
||
422 |
v class == SmallInteger ifTrue:[ "- this is a hint to stc" |
|
423 |
n == 1 ifTrue:[ |
|
424 |
(v between:0 and:16rFF) ifTrue:[ |
|
425 |
self nextPut:v. |
|
426 |
^ self |
|
427 |
]. |
|
428 |
]. |
|
429 |
n == 2 ifTrue:[ |
|
430 |
(v between:0 and:16rFFFF) ifTrue:[ |
|
431 |
self nextPut:(v bitShift:-8). |
|
432 |
self nextPut:(v bitAnd:16rFF). |
|
433 |
^ self |
|
434 |
]. |
|
435 |
]. |
|
436 |
n == 3 ifTrue:[ |
|
437 |
(v between:0 and:16rFFFFFF) ifTrue:[ |
|
438 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
439 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
440 |
self nextPut:(v bitAnd:16rFF). |
|
441 |
^ self |
|
442 |
]. |
|
443 |
]. |
|
444 |
n == 4 ifTrue:[ |
|
445 |
(v >= 0) ifTrue:[ |
|
446 |
self nextPut:((v bitShift:-24) bitAnd:16rFF). |
|
447 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
448 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
449 |
self nextPut:(v bitAnd:16rFF). |
|
450 |
^ self |
|
451 |
]. |
|
452 |
]. |
|
453 |
]. |
|
454 |
||
455 |
" |
|
456 |
arbitrary long |
|
457 |
" |
|
458 |
n < (vlen := v digitLength) ifTrue: [ |
|
459 |
" |
|
460 |
the number is too big to be repesented in n bytes |
|
461 |
" |
|
462 |
self error: 'number too big' |
|
463 |
]. |
|
464 |
||
465 |
"pad with leading zeros" |
|
466 |
i := n. |
|
467 |
[i > vlen] whileTrue: [ |
|
468 |
self nextPut: 0. |
|
469 |
i := i - 1 |
|
470 |
]. |
|
471 |
i = 1 ifTrue: [ |
|
472 |
^ self nextPut: v |
|
473 |
]. |
|
474 |
[i > 0] whileTrue: [ |
|
475 |
self nextPut: (v digitAt: i). |
|
476 |
i := i - 1 |
|
477 |
] |
|
478 |
! |
|
479 |
||
480 |
nextPutLong:aNumber MSB:msbFlag |
|
481 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
482 |
true, data is written most-significant byte first; otherwise least |
|
483 |
first. Returns the receiver on ok, nil on error. |
|
484 |
The receiver must support writing of binary bytes." |
|
485 |
||
486 |
msbFlag ifTrue:[ |
|
487 |
"high word first" |
|
488 |
self nextShortPut:(aNumber // 16r10000) MSB:true. |
|
489 |
^ self nextShortPut:(aNumber \\ 16r10000) MSB:true |
|
490 |
]. |
|
491 |
"low word first" |
|
492 |
self nextShortPut:(aNumber \\ 16r10000) MSB:false. |
|
493 |
^ self nextShortPut:(aNumber // 16r10000) MSB:false. |
|
494 |
! |
|
495 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
496 |
nextPutLongNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
497 |
"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
|
498 |
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
|
499 |
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
|
500 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
501 |
^ self nextPutLong:aNumber MSB:(Socket networkLongOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
502 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
503 |
"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
|
504 |
"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
|
505 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
506 |
|
611 | 507 |
nextPutShort:aNumber MSB:msbFlag |
508 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
509 |
true, data is written most-significant byte first; otherwise least |
|
510 |
first. Returns the receiver on ok, nil on error. |
|
511 |
The receiver must support writing of binary bytes." |
|
512 |
||
513 |
msbFlag ifTrue:[ |
|
514 |
"most significant first" |
|
515 |
self nextPut:(aNumber bitShift:-8). |
|
516 |
^ self nextPut:(aNumber bitAnd:16rFF). |
|
517 |
]. |
|
518 |
"least significant first" |
|
519 |
self nextPut:(aNumber bitAnd:16rFF). |
|
520 |
self nextPut:(aNumber bitShift:-8). |
|
521 |
! |
|
522 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
523 |
nextPutShortNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
524 |
"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
|
525 |
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
|
526 |
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
|
527 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
528 |
^ self nextPutLong:aNumber MSB:(Socket networkShortOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
529 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
530 |
"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
|
531 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
532 |
|
611 | 533 |
nextPutWord:aNumber |
534 |
"write the argument, aNumber as a signed short (two bytes); |
|
535 |
write msb-first for compatibility with other smalltalks. |
|
536 |
The receiver must support writing of binary bytes. |
|
537 |
I dont know if it should be named nextPutWord: or nextWordPut:; |
|
538 |
one of them will vanish ..." |
|
539 |
||
540 |
^ self nextPutShort:aNumber MSB:true |
|
541 |
! |
|
542 |
||
543 |
nextShortPut:aNumber MSB:msbFlag |
|
544 |
"for compatibility - this will vanish" |
|
545 |
||
546 |
^ self nextPutShort:aNumber MSB:msbFlag |
|
547 |
! |
|
548 |
||
549 |
nextWordPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
550 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
551 |
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
|
552 |
The most significant byte is sent first." |
611 | 553 |
|
554 |
^ self nextPutShort:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
555 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
556 |
"Modified: 10.1.1996 / 19:39:19 / cg" |
611 | 557 |
! ! |
558 |
||
559 |
!Stream methodsFor:'private'! |
|
560 |
||
561 |
contentsSpecies |
|
562 |
"this should return the class of which an instance is |
|
563 |
returned by the #contents method. It is redefinable in subclasses" |
|
564 |
||
565 |
"return Array here - since the abstract Stream has no idea |
|
566 |
of the underlying collection class" |
|
567 |
||
568 |
^ Array |
|
569 |
! ! |
|
570 |
||
571 |
!Stream methodsFor:'queries'! |
|
572 |
||
573 |
isBinary |
|
574 |
"return true, if in binary mode. Returns false here, |
|
575 |
to make internalStreams protocol compatible with externStreams." |
|
576 |
||
577 |
^ false |
|
578 |
! |
|
579 |
||
580 |
isPositionable |
|
581 |
"return true, if the stream supports positioning (some do not)" |
|
582 |
||
583 |
^ false |
|
584 |
! |
|
585 |
||
586 |
isReadable |
|
587 |
"return true, if reading is supported by the recevier. |
|
588 |
Assume yes here." |
|
589 |
||
590 |
^ self subclassResponsibility |
|
591 |
! |
|
592 |
||
593 |
isStream |
|
594 |
"return true, if the receiver is some kind of Stream." |
|
595 |
||
596 |
^ true |
|
597 |
! |
|
598 |
||
599 |
isWritable |
|
600 |
"return true, if writing is supported by the recevier. |
|
601 |
Assume yes here." |
|
602 |
||
603 |
^ self subclassResponsibility |
|
604 |
! |
|
605 |
||
606 |
lineLength |
|
607 |
"this is just a layout hint for prettyprinting functions |
|
608 |
- for compatibility with TextCollectors" |
|
609 |
||
610 |
^ 80 |
|
611 |
! ! |
|
612 |
||
62 | 613 |
!Stream methodsFor:'reading'! |
1 | 614 |
|
615 |
next |
|
616 |
"return the next element of the stream |
|
617 |
- we do not know here how to do it, it must be redefined in subclass" |
|
618 |
||
619 |
^ self subclassResponsibility |
|
620 |
! |
|
621 |
||
622 |
next:count |
|
62 | 623 |
"return the next count elements of the stream as a Collection." |
1 | 624 |
|
329 | 625 |
|answerStream |
285 | 626 |
cnt "{ Class: SmallInteger }" | |
1 | 627 |
|
329 | 628 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 629 |
cnt := count. |
630 |
1 to:cnt do:[:index | |
|
329 | 631 |
answerStream nextPut:(self next) |
1 | 632 |
]. |
329 | 633 |
^ answerStream contents |
1 | 634 |
|
275 | 635 |
" |
636 |
(ReadStream on:#(1 2 3 4 5)) next:3 |
|
637 |
(ReadStream on:'hello') next:3 |
|
638 |
" |
|
1 | 639 |
! |
640 |
||
285 | 641 |
nextAvailable:count |
642 |
"return the next count elements of the stream as a Collection. |
|
643 |
If the stream reaches the end before count elements have been read, |
|
644 |
return what is available. (i.e. a shorter collection)" |
|
645 |
||
345 | 646 |
|answerStream |
285 | 647 |
cnt "{ Class: SmallInteger }"| |
648 |
||
329 | 649 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 650 |
cnt := count. |
651 |
1 to:cnt do:[:index | |
|
652 |
self atEnd ifTrue:[ |
|
329 | 653 |
^ answerStream contents |
285 | 654 |
]. |
329 | 655 |
answerStream nextPut:(self next) |
285 | 656 |
]. |
329 | 657 |
^ answerStream contents |
285 | 658 |
|
659 |
" |
|
660 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
661 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
662 |
(ReadStream on:'hello') nextAvailable:3 |
|
663 |
(ReadStream on:'hello') nextAvailable:10 |
|
664 |
" |
|
665 |
! |
|
666 |
||
1 | 667 |
nextMatchFor:anObject |
62 | 668 |
"read an element from the receiver, return true if it was equal to |
669 |
the argument, anObject" |
|
670 |
||
671 |
^ (self next = anObject) |
|
672 |
||
673 |
" |
|
674 |
|s| |
|
675 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
676 |
s nextMatchFor:2 |
|
677 |
" |
|
678 |
" |
|
679 |
|s| |
|
680 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
681 |
s nextMatchFor:2. |
|
682 |
s nextMatchFor:2 |
|
683 |
" |
|
684 |
! |
|
685 |
||
686 |
skip:count |
|
687 |
"skip count objects, return the receiver" |
|
688 |
||
345 | 689 |
|n "{ Class: SmallInteger }"| |
690 |
||
691 |
n := count. |
|
692 |
||
62 | 693 |
"dont know how to unread ..." |
345 | 694 |
n < 0 ifTrue:[ |
216 | 695 |
^ self error:'stream is not positionable' |
62 | 696 |
]. |
345 | 697 |
n timesRepeat:self next |
62 | 698 |
|
699 |
" |
|
700 |
|s| |
|
701 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
702 |
s skip:4. |
|
703 |
s next |
|
704 |
" |
|
705 |
! |
|
706 |
||
707 |
skipFor:anObject |
|
708 |
"skip all objects up-to and including anObject; return the element after anObject." |
|
709 |
||
710 |
(self skipThrough:anObject) notNil ifTrue:[ |
|
216 | 711 |
^ self next |
62 | 712 |
]. |
713 |
^ nil |
|
714 |
||
715 |
" |
|
716 |
|s| |
|
717 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
718 |
s skipFor:4. |
|
719 |
" |
|
720 |
! |
|
721 |
||
722 |
skipThrough:anObject |
|
77 | 723 |
"skip all objects up-to and including anObject. Return the receiver if |
671 | 724 |
skip was successful, otherwise (i.e. if not found) return nil. |
62 | 725 |
The next read operation will return the element after anObject." |
1 | 726 |
|
727 |
|nextElement| |
|
728 |
||
729 |
[self atEnd] whileFalse:[ |
|
216 | 730 |
nextElement := self next. |
731 |
(nextElement = anObject) ifTrue: [ ^ self ] |
|
1 | 732 |
]. |
733 |
^ nil |
|
2 | 734 |
|
62 | 735 |
" |
736 |
|s| |
|
737 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
738 |
s skipThrough:4. |
|
739 |
s next |
|
740 |
" |
|
77 | 741 |
! |
742 |
||
611 | 743 |
through:anObject |
744 |
"read a collection of all objects up-to anObject and return these |
|
745 |
elements, including anObject. |
|
746 |
The next read operation will return the element after anObject. |
|
747 |
Compare this with #upTo: which also reads up to some object |
|
748 |
and also positions behind it, but does not include it in the returned |
|
749 |
value." |
|
750 |
||
751 |
|answerStream element| |
|
752 |
||
753 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
754 |
[self atEnd] whileFalse:[ |
|
755 |
element := self next. |
|
756 |
answerStream nextPut:element. |
|
757 |
(element = anObject) ifTrue: [ |
|
758 |
^ answerStream contents |
|
759 |
] |
|
760 |
]. |
|
761 |
^ answerStream contents |
|
762 |
||
763 |
" |
|
764 |
|s| |
|
765 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
766 |
Transcript showCr:(s through:4). |
|
767 |
Transcript showCr:s next |
|
768 |
" |
|
769 |
" |
|
770 |
|s| |
|
771 |
s := ReadStream on:'hello world'. |
|
772 |
Transcript showCr:(s through:Character space). |
|
773 |
Transcript showCr:(s upToEnd) |
|
774 |
" |
|
775 |
! |
|
776 |
||
427 | 777 |
upTo:anObject |
778 |
"read a collection of all objects up-to anObject and return these |
|
779 |
elements, but excluding anObject. |
|
780 |
The next read operation will return the element after anObject. |
|
781 |
Compare this with #through: which also reads up to some object |
|
782 |
and also positions behind it, but DOES include it in the returned |
|
783 |
value." |
|
784 |
||
785 |
|answerStream element| |
|
786 |
||
787 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
788 |
[self atEnd] whileFalse:[ |
|
789 |
element := self next. |
|
790 |
(element = anObject) ifTrue: [ |
|
791 |
^ answerStream contents |
|
792 |
]. |
|
793 |
answerStream nextPut: element. |
|
794 |
]. |
|
795 |
^ answerStream contents |
|
796 |
||
797 |
" |
|
798 |
|s| |
|
799 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
800 |
Transcript showCr:(s upTo:4). |
|
801 |
Transcript showCr:s next |
|
802 |
||
803 |
|s| |
|
804 |
s := ReadStream on:'hello world'. |
|
805 |
Transcript showCr:(s upTo:Character space). |
|
806 |
Transcript showCr:(s upToEnd) |
|
807 |
||
808 |
(ReadStream on:'12345678905') upTo:$5; upTo:$5 |
|
809 |
||
810 |
(ReadStream on:'123456') upTo:$7 |
|
811 |
||
812 |
(ReadStream on:#(1 2 3 4 5 6)) upTo:4 |
|
813 |
||
814 |
(ReadStream on:'line 1 |
|
815 |
line 2') upTo:Character cr |
|
816 |
||
817 |
'Makefile' asFilename readStream upTo:Character cr;upTo:Character cr |
|
818 |
" |
|
819 |
! |
|
820 |
||
77 | 821 |
upToEnd |
822 |
"return a collection of the elements up-to the end. |
|
823 |
Return nil if the stream-end is reached before." |
|
824 |
||
825 |
|answerStream| |
|
826 |
||
827 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
828 |
[self atEnd] whileFalse:[ |
|
216 | 829 |
answerStream nextPut:(self next) |
77 | 830 |
]. |
831 |
^ answerStream contents |
|
832 |
||
275 | 833 |
" |
834 |
(ReadStream on:'1234567890') upToEnd |
|
835 |
('123456' readStream) next; next; upToEnd |
|
427 | 836 |
('1 23456' readStream) upTo:Character space; upToEnd |
275 | 837 |
" |
611 | 838 |
! ! |
77 | 839 |
|
611 | 840 |
!Stream methodsFor:'testing'! |
77 | 841 |
|
611 | 842 |
atEnd |
843 |
"return true if the end of the stream has been reached; |
|
844 |
- we do not know here how to do it, it must be redefined in subclass" |
|
77 | 845 |
|
611 | 846 |
^ self subclassResponsibility |
1 | 847 |
! ! |
848 |
||
62 | 849 |
!Stream methodsFor:'writing'! |
1 | 850 |
|
339 | 851 |
commit |
852 |
"write out all unbuffered data - ignored here, but added |
|
853 |
to make internalStreams protocol compatible with externalStreams" |
|
854 |
||
855 |
! |
|
856 |
||
611 | 857 |
cr |
858 |
"append a carriage-return to the stream" |
|
859 |
||
860 |
self nextPut:(Character cr) |
|
861 |
! |
|
862 |
||
863 |
crTab |
|
864 |
"append a carriage-return followed by a tab to the stream. |
|
865 |
Same as crtab for ST/X backward compatibility" |
|
866 |
||
867 |
self obsoleteMethodWarning:'use crTab'. |
|
868 |
self crtab |
|
869 |
! |
|
870 |
||
871 |
crtab |
|
872 |
"append a carriage-return followed by a tab to the stream." |
|
1 | 873 |
|
611 | 874 |
self crtab:1 |
875 |
! |
|
876 |
||
877 |
crtab:n |
|
878 |
"append a carriage-return followed by n tabs to the stream." |
|
879 |
||
880 |
self nextPut:(Character cr). |
|
881 |
self next:n put:(Character tab) |
|
882 |
! |
|
883 |
||
884 |
endEntry |
|
885 |
"ignored here - for compatibility with Transcript" |
|
886 |
||
887 |
^ self |
|
888 |
! |
|
889 |
||
890 |
ff |
|
891 |
"append a form-feed (new-pagee) to the receiver-stream" |
|
892 |
||
893 |
self nextPut:(Character ff) |
|
1 | 894 |
! |
895 |
||
701 | 896 |
flush |
897 |
"write out all unbuffered data - for ST-80 compatibility" |
|
898 |
||
899 |
self commit |
|
900 |
||
901 |
"Created: 27.11.1995 / 12:00:35 / cg" |
|
902 |
! |
|
903 |
||
1 | 904 |
next:count put:anObject |
905 |
"put the argument, anObject count times onto the receiver" |
|
906 |
||
345 | 907 |
|n "{ Class: SmallInteger }"| |
908 |
||
909 |
n := count. |
|
910 |
n timesRepeat:[self nextPut:anObject]. |
|
1 | 911 |
^ anObject |
62 | 912 |
|
913 |
" |
|
914 |
|s| |
|
915 |
||
916 |
s := WriteStream on:#(). |
|
917 |
s nextPut:1. |
|
918 |
s next:5 put:2. |
|
919 |
s nextPut:3. |
|
920 |
s contents |
|
921 |
" |
|
1 | 922 |
! |
923 |
||
611 | 924 |
nextPut:anObject |
925 |
"put the argument, anObject onto the receiver |
|
926 |
- we do not know here how to do it, it must be redefined in subclass" |
|
927 |
||
928 |
^ self subclassResponsibility |
|
929 |
! |
|
930 |
||
1 | 931 |
nextPutAll:aCollection |
932 |
"put all elements of the argument, aCollection onto the receiver" |
|
933 |
||
934 |
aCollection do:[:element | |
|
216 | 935 |
self nextPut:element |
1 | 936 |
]. |
937 |
^ aCollection |
|
62 | 938 |
|
939 |
" |
|
940 |
|s| |
|
941 |
||
942 |
s := WriteStream on:#(). |
|
943 |
s nextPutAll:(1 to:5). |
|
944 |
s nextPutAll:#('one' 'two' 'three'). |
|
945 |
s contents |
|
946 |
" |
|
947 |
" |
|
948 |
|s| |
|
949 |
||
950 |
s := WriteStream on:(String new). |
|
951 |
s nextPutAll:($a to:$f). |
|
952 |
s nextPutAll:'one '; |
|
953 |
nextPutAll:'two '; |
|
954 |
nextPutAll:'three'. |
|
955 |
s contents |
|
956 |
" |
|
1 | 957 |
! |
958 |
||
959 |
nextPutAll:aCollection startingAt:first to:last |
|
960 |
"put the elements with index from first to last |
|
961 |
of the argument, aCollection onto the receiver" |
|
962 |
||
963 |
aCollection from:first to:last do:[:element | |
|
216 | 964 |
self nextPut:element |
1 | 965 |
]. |
966 |
^ aCollection |
|
62 | 967 |
|
968 |
" |
|
969 |
|s| |
|
970 |
||
971 |
s := WriteStream on:#(). |
|
972 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4. |
|
973 |
s contents |
|
974 |
" |
|
1 | 975 |
! |
976 |
||
743 | 977 |
nextPutLine:aCollection |
978 |
"put all elements of the argument, aCollection onto the receiver, |
|
979 |
and append a cr. This is only useful with character streams in textMode." |
|
980 |
||
981 |
self nextPutAll:aCollection. |
|
982 |
self cr. |
|
983 |
||
984 |
"Created: 13.12.1995 / 10:49:17 / cg" |
|
985 |
! |
|
986 |
||
611 | 987 |
print:anObject |
988 |
"append a printed representation of anObject to the receiver. |
|
989 |
Same as anObject printOn:self; For ST-80 compatibility." |
|
2 | 990 |
|
611 | 991 |
anObject printOn:self |
2 | 992 |
! |
993 |
||
1 | 994 |
show:aString |
995 |
"put all elements of the argument, aString onto the receiver; |
|
996 |
this makes streams somewhat compatible to TextCollectors and |
|
997 |
allows you to say: Smalltalk at:#Transcript put:Stdout" |
|
998 |
||
999 |
^ self nextPutAll:aString printString |
|
1000 |
! |
|
1001 |
||
1002 |
showCr:aString |
|
1003 |
"put all elements of the argument, aString onto the receiver; |
|
1004 |
and append a newline. |
|
62 | 1005 |
For compatibility with TextCollectors" |
1 | 1006 |
|
1007 |
self show:aString. |
|
1008 |
self cr |
|
62 | 1009 |
! |
1010 |
||
1011 |
space |
|
1012 |
"append a space character to the receiver-stream" |
|
1013 |
||
1014 |
self nextPut:(Character space) |
|
1015 |
! |
|
1016 |
||
1017 |
spaces:count |
|
1018 |
"append count space-characters to the receiver-stream" |
|
1019 |
||
1020 |
self next:count put:(Character space) |
|
1021 |
! |
|
1022 |
||
611 | 1023 |
store:anObject |
1024 |
"append a printed representation of anObject to the receiver, |
|
1025 |
from which the receiver can be reconstructed. |
|
1026 |
Same as anObject storeOn:self; For ST-80 compatibility." |
|
77 | 1027 |
|
611 | 1028 |
anObject storeOn:self |
77 | 1029 |
! |
1030 |
||
611 | 1031 |
tab |
1032 |
"append a tab-character to the stream" |
|
77 | 1033 |
|
611 | 1034 |
self nextPut:(Character tab) |
77 | 1035 |
! ! |
1036 |
||
701 | 1037 |
!Stream class methodsFor:'documentation'! |
1038 |
||
1039 |
version |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
1040 |
^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.33 1996-02-19 15:07:24 stefan Exp $' |
701 | 1041 |
! ! |
611 | 1042 |
Stream initialize! |