author | Claus Gittinger <cg@exept.de> |
Sat, 18 May 1996 15:48:56 +0200 | |
changeset 1414 | 1bbf1ff2fc31 |
parent 1409 | 7197d2f20482 |
child 1422 | 9a0b792f2953 |
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 |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
16 |
WriteErrorSignal EndOfStreamSignal' |
743 | 17 |
poolDictionaries:'' |
18 |
category:'Streams' |
|
1 | 19 |
! |
20 |
||
88 | 21 |
!Stream class methodsFor:'documentation'! |
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: |
1295 | 48 |
#next (if readable) |
49 |
#nextPut: (if writable) |
|
50 |
#contents |
|
51 |
#atEnd |
|
52 |
#isReadable |
|
53 |
#isWritable |
|
54 |
||
1404 | 55 |
Peekable & Positionable streams should (at least) implement: |
56 |
#peek |
|
57 |
#position |
|
58 |
#position: |
|
59 |
||
60 |
||
1295 | 61 |
[Class variables:] |
62 |
StreamErrorSignal <Signal> parent of all stream errors |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
63 |
|
1295 | 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 |
|
1295 | 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 |
|
1295 | 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 |
|
1295 | 71 |
EndOfStreamSignal <Signal> raised at end of stream |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
72 |
|
1295 | 73 |
[author:] |
74 |
Claus Gittinger |
|
88 | 75 |
" |
76 |
! ! |
|
1 | 77 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
78 |
!Stream class methodsFor:'initialization'! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
79 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
80 |
initialize |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
81 |
StreamErrorSignal isNil ifTrue:[ |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
82 |
StreamErrorSignal := ErrorSignal newSignalMayProceed:false. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
83 |
StreamErrorSignal nameClass:self message:#streamErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
84 |
StreamErrorSignal notifierString:'Stream error'. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
85 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
86 |
PositionErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
87 |
PositionErrorSignal nameClass:self message:#positionErrorSignal. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
88 |
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
|
89 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
90 |
ReadErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
91 |
ReadErrorSignal nameClass:self message:#readErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
92 |
ReadErrorSignal notifierString:'read error'. |
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 |
WriteErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
95 |
WriteErrorSignal nameClass:self message:#writeErrorSignal. |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
96 |
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
|
97 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
EndOfStreamSignal notifierString:'end of stream'. |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
101 |
] |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
102 |
! ! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
103 |
|
611 | 104 |
!Stream class methodsFor:'instance creation'! |
105 |
||
106 |
new |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
107 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1117
diff
changeset
|
108 |
|
611 | 109 |
"report an error - Streams are created using on:-messages" |
110 |
||
111 |
^ self error:'Streams cannot be created with new' |
|
112 |
! ! |
|
113 |
||
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
114 |
!Stream class methodsFor:'Signal constants'! |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
115 |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
116 |
endOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
117 |
"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
|
118 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
119 |
^ EndOfStreamSignal |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
120 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
121 |
|
611 | 122 |
positionErrorSignal |
123 |
"return the signal raised if positioning is requested for |
|
124 |
a stream which does not support that kind of operation" |
|
125 |
||
126 |
^ PositionErrorSignal |
|
127 |
! |
|
128 |
||
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
129 |
readErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
130 |
"return the signal raised on read errors" |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
131 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
132 |
^ ReadErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
133 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
134 |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
135 |
streamErrorSignal |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
136 |
"return the parent of all stream errors; |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
137 |
handling this one also handles all other errors. |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
138 |
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
|
139 |
operations, such as failed ioctls in externalStream etc." |
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
140 |
|
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
141 |
^ StreamErrorSignal |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
142 |
! |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
143 |
|
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
144 |
writeErrorSignal |
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
743
diff
changeset
|
145 |
"return the signal raised on write 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 |
^ WriteErrorSignal |
1 | 148 |
! ! |
149 |
||
150 |
!Stream methodsFor:'accessing'! |
|
151 |
||
152 |
contents |
|
62 | 153 |
"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
|
154 |
- we do not know here how to do it, it must be redefined in subclasses." |
1 | 155 |
|
156 |
^ self subclassResponsibility |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
157 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
158 |
"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
|
159 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
160 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
161 |
signalAtEnd |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
162 |
"return 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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
167 |
^ signalAtEnd |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
168 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
169 |
"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
|
170 |
"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
|
171 |
! |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
172 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
173 |
signalAtEnd:aBoolean |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
174 |
"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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
179 |
signalAtEnd := aBoolean. |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
180 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
846
diff
changeset
|
181 |
"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
|
182 |
"Modified: 15.5.1996 / 17:36:12 / cg" |
1 | 183 |
! ! |
184 |
||
611 | 185 |
!Stream methodsFor:'closing'! |
186 |
||
187 |
close |
|
188 |
"close the stream - nothing done here. |
|
189 |
Added for compatibility with external streams." |
|
190 |
||
191 |
^ self |
|
192 |
! ! |
|
193 |
||
1401 | 194 |
!Stream methodsFor:'emphasis'! |
1398
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
195 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
196 |
bold |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
197 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
198 |
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
|
199 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
200 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
201 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
202 |
"Created: 14.5.1996 / 17:37:37 / cg" |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
203 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
204 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
205 |
boldItalic |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
206 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
207 |
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
|
208 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
209 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
210 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
211 |
"Created: 14.5.1996 / 17:37:47 / cg" |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
212 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
213 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
214 |
emphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
215 |
"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
|
216 |
text streams" |
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 |
^ nil |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
219 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
220 |
"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
|
221 |
! |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
222 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
223 |
emphasis:anEmphasis |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
224 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
225 |
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
|
226 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
227 |
^ self |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
228 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
229 |
"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
|
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 |
italic |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
233 |
"ignored here. |
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
234 |
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
|
235 |
|
6c594289c589
emphasis stuff moved up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1371
diff
changeset
|
236 |
^ self |
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:37:55 / 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 |
normal |
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:37:59 / 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 |
|
1401 | 250 |
!Stream methodsFor:'enumerating'! |
251 |
||
252 |
do:aBlock |
|
253 |
"evaluate the argument, aBlock for all remaining elements, |
|
254 |
up to the end of the stream" |
|
255 |
||
256 |
[self atEnd] whileFalse:[ |
|
257 |
aBlock value:(self next) |
|
258 |
] |
|
259 |
||
260 |
" |
|
261 |
|s| |
|
262 |
s := ReadStream on:#(1 2 3 4 5 6 7 8 9). |
|
263 |
s next. |
|
264 |
s next. |
|
265 |
s do:[:element | Transcript showCr:element] |
|
266 |
" |
|
267 |
! ! |
|
268 |
||
269 |
!Stream methodsFor:'error handling'! |
|
270 |
||
271 |
pastEnd |
|
272 |
"someone tried to read after the end of the stream. |
|
273 |
if signalAtEnd == true, raise a signal. |
|
274 |
Otherwise return nil." |
|
275 |
||
276 |
signalAtEnd == true ifTrue:[ |
|
277 |
^ EndOfStreamSignal raiseIn:thisContext sender |
|
278 |
]. |
|
279 |
^ nil |
|
280 |
||
281 |
"Created: 5.2.1996 / 21:56:08 / stefan" |
|
282 |
! ! |
|
283 |
||
611 | 284 |
!Stream methodsFor:'misc'! |
285 |
||
286 |
binary |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
287 |
"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
|
288 |
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
|
289 |
byte-valued integers respectively. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
290 |
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
|
291 |
with externalStreams." |
611 | 292 |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
293 |
"Modified: 15.5.1996 / 17:38:36 / cg" |
611 | 294 |
! ! |
295 |
||
296 |
!Stream methodsFor:'non homogenous reading'! |
|
297 |
||
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
298 |
nextAlphaNumericWord |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
299 |
"read the next word (i.e. up to non letter-or-digit). |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
300 |
Return a string containing those characters. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
301 |
Any leading whitespace is skipped. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
302 |
This method does not advance over any non-alphanumeric characters; |
1403 | 303 |
i.e. it will stick and continue to continue to return nil in this case. |
304 |
Only call for it in a loop, AFTER you have checked for |
|
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
305 |
the next character to really be alphanumeric (using #peek)" |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
306 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
307 |
|s c| |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
308 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
309 |
[self atEnd not |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
310 |
and:[(c := self peek) isSeparator]] whileTrue:[ |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
311 |
self next |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
312 |
]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
313 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
314 |
self atEnd ifTrue:[^ nil]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
315 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
316 |
s := ''. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
317 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
318 |
[self atEnd not |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
319 |
and:[(c := self peek) isLetterOrDigit]] whileTrue:[ |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
320 |
s := s copyWith:c. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
321 |
self next |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
322 |
]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
323 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
324 |
s size == 0 ifTrue:[^ nil]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
325 |
^ s. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
326 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
327 |
" |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
328 |
|s| |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
329 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
330 |
s := 'hello world 1234 foo1 foo2' readStream. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
331 |
[s atEnd] whileFalse:[ |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
332 |
Transcript showCr:(s nextAlphaNumericWord). |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
333 |
]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
334 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
335 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
336 |
notice: streams end never reached this way (sticking at the '+'-character: |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
337 |
|s| |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
338 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
339 |
s := 'hello world 1234 foo1+foo2' readStream. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
340 |
10 timesRepeat:[ |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
341 |
Transcript showCr:(s nextAlphaNumericWord). |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
342 |
]. |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
343 |
" |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
344 |
|
1403 | 345 |
"Modified: 15.5.1996 / 17:51:42 / cg" |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
346 |
! |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
347 |
|
611 | 348 |
nextLine |
1371 | 349 |
"return the characters upTo (but excluding) the next cr character. |
350 |
Added for protocol compatibility with externalStreams." |
|
611 | 351 |
|
352 |
^ self upTo:Character cr. |
|
1371 | 353 |
|
354 |
"Modified: 11.5.1996 / 11:17:01 / cg" |
|
611 | 355 |
! |
356 |
||
357 |
nextLongMSB:msbFlag |
|
358 |
"return a signed long (4 bytes) from the stream. |
|
359 |
The receiver must support reading of binary bytes." |
|
360 |
||
361 |
|high uval "{ Class: SmallInteger }"| |
|
362 |
||
363 |
msbFlag ifTrue:[ |
|
364 |
"most significant first" |
|
365 |
high := self next. |
|
366 |
uval := self next bitShift:16. |
|
367 |
uval := uval bitOr:(self next bitShift:8). |
|
368 |
uval := uval bitOr:(self next). |
|
369 |
uval := uval bitOr:(high bitShift:24). |
|
370 |
] ifFalse:[ |
|
371 |
"least significant first" |
|
372 |
uval := self next. |
|
373 |
uval := uval bitOr:(self next bitShift:8). |
|
374 |
uval := uval bitOr:(self next bitShift:16). |
|
375 |
uval := uval bitOr:(self next bitShift:24). |
|
376 |
]. |
|
377 |
"change from unsigned 0..FFFFFFFF to signed -80000000..7FFFFFFF" |
|
378 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
379 |
"/ sorry- for now (2.7), stc cannot compile LargeInteger constants |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
380 |
"/ uval >= 16r80000000 ifTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
381 |
"/ ^ uval - 16r100000000 |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
382 |
"/ ]. |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
383 |
"/ the following kludges around this |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
384 |
"/ well, new (2.8) can ... |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
385 |
|
611 | 386 |
(uval bitShift:-16) >= 16r8000 ifTrue:[ |
387 |
^ uval - (16r10000000 bitShift:8) |
|
388 |
]. |
|
389 |
^ uval |
|
390 |
! |
|
391 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
392 |
nextLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
393 |
"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
|
394 |
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
|
395 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
396 |
^ self nextLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
397 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
398 |
"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
|
399 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
400 |
|
611 | 401 |
nextNumber:n |
402 |
"Return the next n bytes as a positive Integer; bytes are taken msb-first." |
|
403 |
||
404 |
|s |
|
405 |
val "{ Class: SmallInteger }" |
|
406 |
rep "{ Class: SmallInteger }"| |
|
407 |
||
408 |
"claus: this method is central in binaryStorage - |
|
409 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
410 |
||
411 |
n == 1 ifTrue:[ |
|
412 |
^ self next |
|
413 |
]. |
|
414 |
n == 2 ifTrue:[ |
|
415 |
val := self next. |
|
416 |
val := (val bitShift:8) + self next. |
|
417 |
^ val |
|
418 |
]. |
|
419 |
n == 3 ifTrue:[ |
|
420 |
val := self next. |
|
421 |
val := (val bitShift:8) + self next. |
|
422 |
val := (val bitShift:8) + self next. |
|
423 |
^ val |
|
424 |
]. |
|
425 |
n == 4 ifTrue:[ |
|
426 |
val := self next. |
|
427 |
val <= 16r3F ifTrue:[ |
|
428 |
val := (val bitShift:8) + self next. |
|
429 |
val := (val bitShift:8) + self next. |
|
430 |
val := (val bitShift:8) + self next. |
|
431 |
^ val |
|
432 |
]. |
|
433 |
"sorry, but need a largeInteger" |
|
434 |
s := (val bitShift:8) + self next. |
|
435 |
s := (s bitShift:8) + self next. |
|
436 |
s := (s * 256) + self next. |
|
437 |
^ s |
|
438 |
]. |
|
439 |
||
440 |
" |
|
441 |
arbitrary long |
|
442 |
" |
|
443 |
s := 0. |
|
444 |
rep := n. |
|
445 |
rep timesRepeat:[ |
|
446 |
s := s * 256 + self next |
|
447 |
]. |
|
448 |
^ s truncated |
|
449 |
! |
|
450 |
||
451 |
nextShortMSB:msbFlag |
|
452 |
"return a signed short (2 bytes) from the stream. |
|
453 |
The receiver must support reading of binary bytes." |
|
454 |
||
455 |
|uval "{ Class: SmallInteger }"| |
|
456 |
||
457 |
msbFlag ifTrue:[ |
|
458 |
"most significant first" |
|
459 |
uval := self next bitShift:8. |
|
460 |
uval := uval bitOr:(self next). |
|
461 |
] ifFalse:[ |
|
462 |
"least significant first" |
|
463 |
uval := self next. |
|
464 |
uval := uval bitOr:(self next bitShift:8). |
|
465 |
]. |
|
466 |
"change from unsigned 0..FFFF to signed -8000..7FFF" |
|
467 |
uval >= 16r8000 ifTrue:[ |
|
468 |
^ uval - 16r10000 |
|
469 |
]. |
|
470 |
^ uval |
|
471 |
! |
|
472 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
473 |
nextShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
474 |
"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
|
475 |
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
|
476 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
477 |
^ self nextShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
478 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
479 |
"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
|
480 |
"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
|
481 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
482 |
|
611 | 483 |
nextUnsignedLongMSB:msbFlag |
484 |
"return an unsigned long (4 bytes) from the stream. |
|
485 |
The receiver must support reading of binary bytes." |
|
486 |
||
487 |
|val| |
|
488 |
||
489 |
msbFlag ifTrue:[ |
|
490 |
val := self next. |
|
491 |
val := (val bitShift:8) bitOr:(self next). |
|
492 |
val := (val bitShift:8) bitOr:(self next). |
|
493 |
val := (val * 256) + (self next). |
|
494 |
^ val |
|
495 |
]. |
|
496 |
val := self next. |
|
497 |
^ (val bitShift:24) |
|
498 |
+ (self next bitShift:16) |
|
499 |
+ (self next bitShift:8) |
|
500 |
+ self next |
|
501 |
! |
|
502 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
503 |
nextUnsignedLongNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
504 |
"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
|
505 |
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
|
506 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
507 |
^ self nextUnsignedLongMSB:(Socket networkLongOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
508 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
509 |
"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
|
510 |
"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
|
511 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
512 |
|
611 | 513 |
nextUnsignedShortMSB:msbFlag |
514 |
"return an unsigned short (2 bytes) from the stream. |
|
515 |
The receiver must support reading of binary bytes." |
|
516 |
||
517 |
msbFlag ifTrue:[ |
|
518 |
^ (self next bitShift:8) bitOr:(self next) |
|
519 |
]. |
|
520 |
^ (self next) bitOr:(self next bitShift:8) |
|
521 |
! |
|
522 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
523 |
nextUnsignedShortNet |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
524 |
"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
|
525 |
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
|
526 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
527 |
^ self nextUnsignedShortMSB:(Socket networkShortOrderIsMSB) |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
528 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
529 |
"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
|
530 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
531 |
|
611 | 532 |
nextWord |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
533 |
"return the next characters which form an alphanumeric word |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
534 |
(i.e. everything upTo (but excluding) the next non alphanumeric |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
535 |
element)" |
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
536 |
|
611 | 537 |
^ self nextAlphaNumericWord |
1402
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
538 |
|
82462d153a7d
added #nextAlphaNumericWord (completing the protocol); added comments
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
539 |
"Modified: 15.5.1996 / 17:39:32 / cg" |
611 | 540 |
! ! |
541 |
||
542 |
!Stream methodsFor:'non homogenous writing'! |
|
543 |
||
544 |
nextLongPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
545 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
546 |
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
|
547 |
The most significant byte is sent first." |
611 | 548 |
|
549 |
^ self nextPutLong:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
550 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
551 |
"Modified: 10.1.1996 / 19:38:54 / cg" |
611 | 552 |
! |
553 |
||
554 |
nextNumber:n put:v |
|
555 |
"Append to the receiver the argument, v, which is a positive Integer, |
|
556 |
as the next n bytes. Bytes are written msb first. |
|
557 |
Possibly pad with leading zeros. |
|
558 |
The receiver must support writing of binary bytes." |
|
559 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
560 |
|vlen "{ Class: SmallInteger }" |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
561 |
i "{ Class: SmallInteger }"| |
611 | 562 |
|
563 |
"claus: this method is central in binaryStorage - |
|
564 |
therefore it has been tuned a bit (and needs even more tuning)" |
|
565 |
||
566 |
v class == SmallInteger ifTrue:[ "- this is a hint to stc" |
|
567 |
n == 1 ifTrue:[ |
|
568 |
(v between:0 and:16rFF) ifTrue:[ |
|
569 |
self nextPut:v. |
|
570 |
^ self |
|
571 |
]. |
|
572 |
]. |
|
573 |
n == 2 ifTrue:[ |
|
574 |
(v between:0 and:16rFFFF) ifTrue:[ |
|
575 |
self nextPut:(v bitShift:-8). |
|
576 |
self nextPut:(v bitAnd:16rFF). |
|
577 |
^ self |
|
578 |
]. |
|
579 |
]. |
|
580 |
n == 3 ifTrue:[ |
|
581 |
(v between:0 and:16rFFFFFF) ifTrue:[ |
|
582 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
583 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
584 |
self nextPut:(v bitAnd:16rFF). |
|
585 |
^ self |
|
586 |
]. |
|
587 |
]. |
|
588 |
n == 4 ifTrue:[ |
|
589 |
(v >= 0) ifTrue:[ |
|
590 |
self nextPut:((v bitShift:-24) bitAnd:16rFF). |
|
591 |
self nextPut:((v bitShift:-16) bitAnd:16rFF). |
|
592 |
self nextPut:((v bitShift:-8) bitAnd:16rFF). |
|
593 |
self nextPut:(v bitAnd:16rFF). |
|
594 |
^ self |
|
595 |
]. |
|
596 |
]. |
|
597 |
]. |
|
598 |
||
599 |
" |
|
600 |
arbitrary long |
|
601 |
" |
|
602 |
n < (vlen := v digitLength) ifTrue: [ |
|
603 |
" |
|
604 |
the number is too big to be repesented in n bytes |
|
605 |
" |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
606 |
self error:'number too big' |
611 | 607 |
]. |
608 |
||
609 |
"pad with leading zeros" |
|
610 |
i := n. |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
611 |
[i > vlen] whileTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
612 |
self nextPut:0. |
611 | 613 |
i := i - 1 |
614 |
]. |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
615 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
616 |
i == 1 ifTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
617 |
^ self nextPut:v |
611 | 618 |
]. |
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
619 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
620 |
[i > 0] whileTrue:[ |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
621 |
self nextPut:(v digitAt:i). |
611 | 622 |
i := i - 1 |
623 |
] |
|
624 |
! |
|
625 |
||
626 |
nextPutLong:aNumber MSB:msbFlag |
|
627 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
628 |
true, data is written most-significant byte first; otherwise least |
|
629 |
first. Returns the receiver on ok, nil on error. |
|
630 |
The receiver must support writing of binary bytes." |
|
631 |
||
632 |
msbFlag ifTrue:[ |
|
633 |
"high word first" |
|
634 |
self nextShortPut:(aNumber // 16r10000) MSB:true. |
|
635 |
^ self nextShortPut:(aNumber \\ 16r10000) MSB:true |
|
636 |
]. |
|
637 |
"low word first" |
|
638 |
self nextShortPut:(aNumber \\ 16r10000) MSB:false. |
|
639 |
^ self nextShortPut:(aNumber // 16r10000) MSB:false. |
|
640 |
! |
|
641 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
642 |
nextPutLongNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
643 |
"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
|
644 |
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
|
645 |
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
|
646 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
647 |
^ self nextPutLong:aNumber MSB:(Socket networkLongOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
648 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
649 |
"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
|
650 |
"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
|
651 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
652 |
|
611 | 653 |
nextPutShort:aNumber MSB:msbFlag |
654 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
655 |
true, data is written most-significant byte first; otherwise least |
|
656 |
first. Returns the receiver on ok, nil on error. |
|
657 |
The receiver must support writing of binary bytes." |
|
658 |
||
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
659 |
|iNum "{ Class: SmallInteger }"| |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
660 |
|
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
661 |
iNum := aNumber. |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
662 |
|
611 | 663 |
msbFlag ifTrue:[ |
664 |
"most significant first" |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
665 |
self nextPut:(iNum bitShift:-8). |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
666 |
^ self nextPut:(iNum bitAnd:16rFF). |
611 | 667 |
]. |
668 |
"least significant first" |
|
1117
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
669 |
self nextPut:(iNum bitAnd:16rFF). |
f64e35e18e65
typed variable in nextPutNumber
Claus Gittinger <cg@exept.de>
parents:
970
diff
changeset
|
670 |
self nextPut:(iNum bitShift:-8). |
611 | 671 |
! |
672 |
||
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
673 |
nextPutShortNet:aNumber |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
674 |
"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
|
675 |
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
|
676 |
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
|
677 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
678 |
^ self nextPutLong:aNumber MSB:(Socket networkShortOrderIsMSB). |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
679 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
680 |
"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
|
681 |
! |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
682 |
|
611 | 683 |
nextPutWord:aNumber |
684 |
"write the argument, aNumber as a signed short (two bytes); |
|
685 |
write msb-first for compatibility with other smalltalks. |
|
686 |
The receiver must support writing of binary bytes. |
|
687 |
I dont know if it should be named nextPutWord: or nextWordPut:; |
|
688 |
one of them will vanish ..." |
|
689 |
||
690 |
^ self nextPutShort:aNumber MSB:true |
|
691 |
! |
|
692 |
||
693 |
nextShortPut:aNumber MSB:msbFlag |
|
694 |
"for compatibility - this will vanish" |
|
695 |
||
696 |
^ self nextPutShort:aNumber MSB:msbFlag |
|
697 |
! |
|
698 |
||
699 |
nextWordPut:aNumber |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
700 |
"for ST-80 compatibility: |
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
701 |
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
|
702 |
The most significant byte is sent first." |
611 | 703 |
|
704 |
^ self nextPutShort:aNumber MSB:true |
|
846
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
705 |
|
4117b296633d
network byte order read/write methods added
Claus Gittinger <cg@exept.de>
parents:
820
diff
changeset
|
706 |
"Modified: 10.1.1996 / 19:39:19 / cg" |
611 | 707 |
! ! |
708 |
||
709 |
!Stream methodsFor:'private'! |
|
710 |
||
711 |
contentsSpecies |
|
712 |
"this should return the class of which an instance is |
|
1403 | 713 |
returned by the #contents method. Here, Array is returned, |
714 |
since the abstract Stream-class has no idea of the underlying |
|
715 |
collection class. |
|
716 |
It is redefined in some subclasses - for example, to return String." |
|
611 | 717 |
|
718 |
^ Array |
|
1403 | 719 |
|
720 |
"Modified: 15.5.1996 / 17:53:31 / cg" |
|
611 | 721 |
! ! |
722 |
||
723 |
!Stream methodsFor:'queries'! |
|
724 |
||
725 |
isBinary |
|
1403 | 726 |
"return true, if in binary mode. Always returns false here, |
727 |
to make internalStreams protocol compatible with externalStreams." |
|
611 | 728 |
|
729 |
^ false |
|
1403 | 730 |
|
731 |
"Modified: 15.5.1996 / 17:53:51 / cg" |
|
611 | 732 |
! |
733 |
||
734 |
isPositionable |
|
1403 | 735 |
"return true, if the stream supports positioning (some do not). |
736 |
Since this is an abstract class, false is returned here - just to make certain." |
|
611 | 737 |
|
738 |
^ false |
|
1403 | 739 |
|
740 |
"Modified: 15.5.1996 / 17:54:16 / cg" |
|
611 | 741 |
! |
742 |
||
743 |
isReadable |
|
744 |
"return true, if reading is supported by the recevier. |
|
1403 | 745 |
This has to be redefined in concrete subclasses." |
611 | 746 |
|
747 |
^ self subclassResponsibility |
|
1403 | 748 |
|
749 |
"Modified: 15.5.1996 / 17:54:31 / cg" |
|
611 | 750 |
! |
751 |
||
752 |
isStream |
|
1403 | 753 |
"return true, if the receiver is some kind of Stream. Always return true here." |
611 | 754 |
|
755 |
^ true |
|
1403 | 756 |
|
757 |
"Modified: 15.5.1996 / 17:54:48 / cg" |
|
611 | 758 |
! |
759 |
||
760 |
isWritable |
|
761 |
"return true, if writing is supported by the recevier. |
|
1403 | 762 |
This has to be redefined in concrete subclasses." |
611 | 763 |
|
764 |
^ self subclassResponsibility |
|
1403 | 765 |
|
766 |
"Modified: 15.5.1996 / 17:54:54 / cg" |
|
611 | 767 |
! |
768 |
||
769 |
lineLength |
|
1403 | 770 |
"return the lineLength which `looks good' when pretty printed |
771 |
text is sent to this stream. |
|
772 |
This has NO meaning whatsoever to regular streams; |
|
773 |
however, it may be used as a layout hint for prettyprinting functions |
|
774 |
- for compatibility with TextCollectors, which returns its views actual |
|
775 |
line length, and allows the prettyprinter to wrap at that position." |
|
611 | 776 |
|
777 |
^ 80 |
|
1403 | 778 |
|
779 |
"Modified: 15.5.1996 / 17:57:01 / cg" |
|
611 | 780 |
! ! |
781 |
||
62 | 782 |
!Stream methodsFor:'reading'! |
1 | 783 |
|
784 |
next |
|
785 |
"return the next element of the stream |
|
786 |
- we do not know here how to do it, it must be redefined in subclass" |
|
787 |
||
788 |
^ self subclassResponsibility |
|
789 |
! |
|
790 |
||
791 |
next:count |
|
1403 | 792 |
"return the next count elements of the stream as aCollection, |
793 |
which depends on the streams type - (see #contentsSpecies)." |
|
1 | 794 |
|
329 | 795 |
|answerStream |
285 | 796 |
cnt "{ Class: SmallInteger }" | |
1 | 797 |
|
329 | 798 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 799 |
cnt := count. |
800 |
1 to:cnt do:[:index | |
|
1403 | 801 |
answerStream nextPut:(self next) |
1 | 802 |
]. |
329 | 803 |
^ answerStream contents |
1 | 804 |
|
275 | 805 |
" |
806 |
(ReadStream on:#(1 2 3 4 5)) next:3 |
|
807 |
(ReadStream on:'hello') next:3 |
|
808 |
" |
|
1403 | 809 |
|
810 |
"Modified: 15.5.1996 / 17:57:58 / cg" |
|
1 | 811 |
! |
812 |
||
285 | 813 |
nextAvailable:count |
1403 | 814 |
"return the next count elements of the stream as aCollection. |
285 | 815 |
If the stream reaches the end before count elements have been read, |
1403 | 816 |
return what is available. (i.e. a shorter collection). |
817 |
The type of collection is speciefied in #contentsSpecies." |
|
285 | 818 |
|
345 | 819 |
|answerStream |
285 | 820 |
cnt "{ Class: SmallInteger }"| |
821 |
||
329 | 822 |
answerStream := WriteStream on:(self contentsSpecies new). |
285 | 823 |
cnt := count. |
824 |
1 to:cnt do:[:index | |
|
1403 | 825 |
self atEnd ifTrue:[ |
826 |
^ answerStream contents |
|
827 |
]. |
|
828 |
answerStream nextPut:(self next) |
|
285 | 829 |
]. |
329 | 830 |
^ answerStream contents |
285 | 831 |
|
832 |
" |
|
833 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
834 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
835 |
(ReadStream on:'hello') nextAvailable:3 |
|
836 |
(ReadStream on:'hello') nextAvailable:10 |
|
837 |
" |
|
1403 | 838 |
|
839 |
"Modified: 15.5.1996 / 17:58:42 / cg" |
|
285 | 840 |
! |
841 |
||
1 | 842 |
nextMatchFor:anObject |
62 | 843 |
"read an element from the receiver, return true if it was equal to |
1403 | 844 |
the argument, anObject; false otherwise." |
62 | 845 |
|
846 |
^ (self next = anObject) |
|
847 |
||
848 |
" |
|
849 |
|s| |
|
850 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
851 |
s nextMatchFor:2 |
|
852 |
" |
|
853 |
" |
|
854 |
|s| |
|
855 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
856 |
s nextMatchFor:2. |
|
857 |
s nextMatchFor:2 |
|
858 |
" |
|
1403 | 859 |
|
860 |
"Modified: 15.5.1996 / 17:58:57 / cg" |
|
62 | 861 |
! |
862 |
||
863 |
skip:count |
|
864 |
"skip count objects, return the receiver" |
|
865 |
||
345 | 866 |
|n "{ Class: SmallInteger }"| |
867 |
||
868 |
n := count. |
|
869 |
||
62 | 870 |
"dont know how to unread ..." |
345 | 871 |
n < 0 ifTrue:[ |
216 | 872 |
^ self error:'stream is not positionable' |
62 | 873 |
]. |
345 | 874 |
n timesRepeat:self next |
62 | 875 |
|
876 |
" |
|
877 |
|s| |
|
878 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
879 |
s skip:4. |
|
880 |
s next |
|
881 |
" |
|
882 |
! |
|
883 |
||
884 |
skipFor:anObject |
|
1403 | 885 |
"skip all objects up-to and including anObject; |
886 |
return the element after anObject." |
|
62 | 887 |
|
888 |
(self skipThrough:anObject) notNil ifTrue:[ |
|
1403 | 889 |
^ self next |
62 | 890 |
]. |
891 |
^ nil |
|
892 |
||
893 |
" |
|
894 |
|s| |
|
895 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
896 |
s skipFor:4. |
|
897 |
" |
|
1403 | 898 |
|
899 |
"Modified: 15.5.1996 / 17:59:23 / cg" |
|
62 | 900 |
! |
901 |
||
902 |
skipThrough:anObject |
|
77 | 903 |
"skip all objects up-to and including anObject. Return the receiver if |
671 | 904 |
skip was successful, otherwise (i.e. if not found) return nil. |
62 | 905 |
The next read operation will return the element after anObject." |
1 | 906 |
|
907 |
|nextElement| |
|
908 |
||
909 |
[self atEnd] whileFalse:[ |
|
216 | 910 |
nextElement := self next. |
911 |
(nextElement = anObject) ifTrue: [ ^ self ] |
|
1 | 912 |
]. |
913 |
^ nil |
|
2 | 914 |
|
62 | 915 |
" |
916 |
|s| |
|
917 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
918 |
s skipThrough:4. |
|
919 |
s next |
|
920 |
" |
|
77 | 921 |
! |
922 |
||
611 | 923 |
through:anObject |
924 |
"read a collection of all objects up-to anObject and return these |
|
925 |
elements, including anObject. |
|
926 |
The next read operation will return the element after anObject. |
|
1409 | 927 |
If anObject is not encountered, all elements up to the end are read |
928 |
and returned. |
|
611 | 929 |
Compare this with #upTo: which also reads up to some object |
930 |
and also positions behind it, but does not include it in the returned |
|
931 |
value." |
|
932 |
||
933 |
|answerStream element| |
|
934 |
||
935 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
936 |
[self atEnd] whileFalse:[ |
|
1409 | 937 |
element := self next. |
938 |
answerStream nextPut:element. |
|
939 |
(element = anObject) ifTrue: [ |
|
940 |
^ answerStream contents |
|
941 |
] |
|
611 | 942 |
]. |
943 |
^ answerStream contents |
|
944 |
||
945 |
" |
|
946 |
|s| |
|
947 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
948 |
Transcript showCr:(s through:4). |
|
949 |
Transcript showCr:s next |
|
1409 | 950 |
|
951 |
|s| |
|
952 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
953 |
Transcript showCr:(s through:9). |
|
954 |
Transcript showCr:s next |
|
955 |
||
611 | 956 |
|s| |
957 |
s := ReadStream on:'hello world'. |
|
958 |
Transcript showCr:(s through:Character space). |
|
959 |
Transcript showCr:(s upToEnd) |
|
960 |
" |
|
1409 | 961 |
|
962 |
"Modified: 17.5.1996 / 08:51:40 / cg" |
|
611 | 963 |
! |
964 |
||
427 | 965 |
upTo:anObject |
966 |
"read a collection of all objects up-to anObject and return these |
|
967 |
elements, but excluding anObject. |
|
968 |
The next read operation will return the element after anObject. |
|
1409 | 969 |
If anObject is not encountered, all elements up to the end are read |
970 |
and returned. |
|
427 | 971 |
Compare this with #through: which also reads up to some object |
972 |
and also positions behind it, but DOES include it in the returned |
|
973 |
value." |
|
974 |
||
975 |
|answerStream element| |
|
976 |
||
977 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
978 |
[self atEnd] whileFalse:[ |
|
1409 | 979 |
element := self next. |
980 |
(element = anObject) ifTrue: [ |
|
981 |
^ answerStream contents |
|
982 |
]. |
|
983 |
answerStream nextPut:element. |
|
427 | 984 |
]. |
985 |
^ answerStream contents |
|
986 |
||
987 |
" |
|
988 |
|s| |
|
989 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
990 |
Transcript showCr:(s upTo:4). |
|
991 |
Transcript showCr:s next |
|
992 |
||
993 |
|s| |
|
1409 | 994 |
s := ReadStream on:#(1 2 3 4 5 6 7 8). |
995 |
Transcript showCr:(s upTo:9). |
|
996 |
Transcript showCr:s next |
|
997 |
||
998 |
|s| |
|
427 | 999 |
s := ReadStream on:'hello world'. |
1000 |
Transcript showCr:(s upTo:Character space). |
|
1001 |
Transcript showCr:(s upToEnd) |
|
1002 |
||
1003 |
(ReadStream on:'12345678905') upTo:$5; upTo:$5 |
|
1004 |
||
1005 |
(ReadStream on:'123456') upTo:$7 |
|
1006 |
||
1007 |
(ReadStream on:#(1 2 3 4 5 6)) upTo:4 |
|
1008 |
||
1009 |
(ReadStream on:'line 1 |
|
1409 | 1010 |
line 2') upTo:Character cr |
427 | 1011 |
|
1012 |
'Makefile' asFilename readStream upTo:Character cr;upTo:Character cr |
|
1013 |
" |
|
1409 | 1014 |
|
1015 |
"Modified: 17.5.1996 / 08:51:56 / cg" |
|
427 | 1016 |
! |
1017 |
||
77 | 1018 |
upToEnd |
1019 |
"return a collection of the elements up-to the end. |
|
1403 | 1020 |
Return an empty collection, if the stream-end is already at the end." |
77 | 1021 |
|
1022 |
|answerStream| |
|
1023 |
||
1024 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
1025 |
[self atEnd] whileFalse:[ |
|
1403 | 1026 |
answerStream nextPut:(self next) |
77 | 1027 |
]. |
1028 |
^ answerStream contents |
|
1029 |
||
275 | 1030 |
" |
1031 |
(ReadStream on:'1234567890') upToEnd |
|
1032 |
('123456' readStream) next; next; upToEnd |
|
427 | 1033 |
('1 23456' readStream) upTo:Character space; upToEnd |
1403 | 1034 |
('12' readStream) next; next; upToEnd |
275 | 1035 |
" |
1403 | 1036 |
|
1037 |
"Modified: 15.5.1996 / 18:00:39 / cg" |
|
611 | 1038 |
! ! |
77 | 1039 |
|
611 | 1040 |
!Stream methodsFor:'testing'! |
77 | 1041 |
|
611 | 1042 |
atEnd |
1043 |
"return true if the end of the stream has been reached; |
|
1044 |
- we do not know here how to do it, it must be redefined in subclass" |
|
77 | 1045 |
|
611 | 1046 |
^ self subclassResponsibility |
1 | 1047 |
! ! |
1048 |
||
62 | 1049 |
!Stream methodsFor:'writing'! |
1 | 1050 |
|
339 | 1051 |
commit |
1052 |
"write out all unbuffered data - ignored here, but added |
|
1053 |
to make internalStreams protocol compatible with externalStreams" |
|
1054 |
||
1055 |
! |
|
1056 |
||
611 | 1057 |
cr |
1403 | 1058 |
"append a carriage-return to the stream. |
1059 |
This is only allowed, if the receiver supports writing." |
|
611 | 1060 |
|
1061 |
self nextPut:(Character cr) |
|
1403 | 1062 |
|
1063 |
"Modified: 15.5.1996 / 18:01:21 / cg" |
|
611 | 1064 |
! |
1065 |
||
1066 |
crTab |
|
1067 |
"append a carriage-return followed by a tab to the stream. |
|
1403 | 1068 |
Same as crtab for ST/X backward compatibility. |
1069 |
This is only allowed, if the receiver supports writing." |
|
611 | 1070 |
|
1071 |
self obsoleteMethodWarning:'use crTab'. |
|
1072 |
self crtab |
|
1403 | 1073 |
|
1074 |
"Modified: 15.5.1996 / 18:01:28 / cg" |
|
611 | 1075 |
! |
1076 |
||
1077 |
crtab |
|
1403 | 1078 |
"append a carriage-return followed by a tab to the stream. |
1079 |
This is only allowed, if the receiver supports writing." |
|
1 | 1080 |
|
611 | 1081 |
self crtab:1 |
1403 | 1082 |
|
1083 |
"Modified: 15.5.1996 / 18:01:35 / cg" |
|
611 | 1084 |
! |
1085 |
||
1086 |
crtab:n |
|
1403 | 1087 |
"append a carriage-return followed by n tabs to the stream. |
1088 |
This is only allowed, if the receiver supports writing." |
|
611 | 1089 |
|
1090 |
self nextPut:(Character cr). |
|
1091 |
self next:n put:(Character tab) |
|
1403 | 1092 |
|
1093 |
"Modified: 15.5.1996 / 18:01:39 / cg" |
|
611 | 1094 |
! |
1095 |
||
1096 |
endEntry |
|
1097 |
"ignored here - for compatibility with Transcript" |
|
1098 |
||
1099 |
^ self |
|
1100 |
! |
|
1101 |
||
1102 |
ff |
|
1403 | 1103 |
"append a form-feed (new-pagee) to the receiver-stream. |
1104 |
This is only allowed, if the receiver supports writing." |
|
611 | 1105 |
|
1106 |
self nextPut:(Character ff) |
|
1403 | 1107 |
|
1108 |
"Modified: 15.5.1996 / 18:01:47 / cg" |
|
1 | 1109 |
! |
1110 |
||
701 | 1111 |
flush |
1112 |
"write out all unbuffered data - for ST-80 compatibility" |
|
1113 |
||
1114 |
self commit |
|
1115 |
||
1116 |
"Created: 27.11.1995 / 12:00:35 / cg" |
|
1117 |
! |
|
1118 |
||
1 | 1119 |
next:count put:anObject |
1120 |
"put the argument, anObject count times onto the receiver" |
|
1121 |
||
345 | 1122 |
|n "{ Class: SmallInteger }"| |
1123 |
||
1124 |
n := count. |
|
1125 |
n timesRepeat:[self nextPut:anObject]. |
|
1 | 1126 |
^ anObject |
62 | 1127 |
|
1128 |
" |
|
1129 |
|s| |
|
1130 |
||
1131 |
s := WriteStream on:#(). |
|
1132 |
s nextPut:1. |
|
1133 |
s next:5 put:2. |
|
1134 |
s nextPut:3. |
|
1135 |
s contents |
|
1136 |
" |
|
1 | 1137 |
! |
1138 |
||
611 | 1139 |
nextPut:anObject |
1140 |
"put the argument, anObject onto the receiver |
|
1141 |
- we do not know here how to do it, it must be redefined in subclass" |
|
1142 |
||
1143 |
^ self subclassResponsibility |
|
1144 |
! |
|
1145 |
||
1 | 1146 |
nextPutAll:aCollection |
1147 |
"put all elements of the argument, aCollection onto the receiver" |
|
1148 |
||
1149 |
aCollection do:[:element | |
|
216 | 1150 |
self nextPut:element |
1 | 1151 |
]. |
1152 |
^ aCollection |
|
62 | 1153 |
|
1154 |
" |
|
1155 |
|s| |
|
1156 |
||
1157 |
s := WriteStream on:#(). |
|
1158 |
s nextPutAll:(1 to:5). |
|
1159 |
s nextPutAll:#('one' 'two' 'three'). |
|
1160 |
s contents |
|
1161 |
" |
|
1162 |
" |
|
1163 |
|s| |
|
1164 |
||
1165 |
s := WriteStream on:(String new). |
|
1166 |
s nextPutAll:($a to:$f). |
|
1167 |
s nextPutAll:'one '; |
|
1168 |
nextPutAll:'two '; |
|
1169 |
nextPutAll:'three'. |
|
1170 |
s contents |
|
1171 |
" |
|
1 | 1172 |
! |
1173 |
||
1174 |
nextPutAll:aCollection startingAt:first to:last |
|
1175 |
"put the elements with index from first to last |
|
1176 |
of the argument, aCollection onto the receiver" |
|
1177 |
||
1178 |
aCollection from:first to:last do:[:element | |
|
216 | 1179 |
self nextPut:element |
1 | 1180 |
]. |
1181 |
^ aCollection |
|
62 | 1182 |
|
1183 |
" |
|
1184 |
|s| |
|
1185 |
||
1186 |
s := WriteStream on:#(). |
|
1187 |
s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4. |
|
1188 |
s contents |
|
1189 |
" |
|
1 | 1190 |
! |
1191 |
||
743 | 1192 |
nextPutLine:aCollection |
1193 |
"put all elements of the argument, aCollection onto the receiver, |
|
1194 |
and append a cr. This is only useful with character streams in textMode." |
|
1195 |
||
1196 |
self nextPutAll:aCollection. |
|
1197 |
self cr. |
|
1198 |
||
1199 |
"Created: 13.12.1995 / 10:49:17 / cg" |
|
1200 |
! |
|
1201 |
||
611 | 1202 |
print:anObject |
1203 |
"append a printed representation of anObject to the receiver. |
|
1403 | 1204 |
Same as 'anObject printOn:self'; Added for ST-80 compatibility." |
2 | 1205 |
|
611 | 1206 |
anObject printOn:self |
1403 | 1207 |
|
1208 |
" |
|
1209 |
|s| |
|
1210 |
||
1211 |
s := WriteStream on:''. |
|
1212 |
s nextPutAll:'one '; |
|
1213 |
print:1; |
|
1214 |
nextPutAll:' two '; |
|
1215 |
print:2. |
|
1216 |
||
1217 |
s contents |
|
1218 |
" |
|
1219 |
||
1220 |
"Modified: 15.5.1996 / 18:06:06 / cg" |
|
2 | 1221 |
! |
1222 |
||
1403 | 1223 |
show:something |
1224 |
"append a printed representation of the argument to the stream. |
|
1225 |
This makes streams somewhat compatible to TextCollectors and |
|
1226 |
allows you to say: |
|
1227 |
Smalltalk at:#Transcript put:Stdout |
|
1228 |
or to use #show:/#showCr: with internal or external streams." |
|
1 | 1229 |
|
1403 | 1230 |
^ self nextPutAll:something printString |
1231 |
||
1232 |
"Modified: 15.5.1996 / 18:04:48 / cg" |
|
1 | 1233 |
! |
1234 |
||
1414 | 1235 |
showCR:aString |
1403 | 1236 |
"append a printed representation of the argument to the stream |
1414 | 1237 |
and append a newline character." |
1 | 1238 |
|
1239 |
self show:aString. |
|
1240 |
self cr |
|
1403 | 1241 |
|
1414 | 1242 |
"Created: 18.5.1996 / 15:34:17 / cg" |
1243 |
"Modified: 18.5.1996 / 15:36:31 / cg" |
|
1244 |
! |
|
1245 |
||
1246 |
showCr:aString |
|
1247 |
"append a printed representation of the argument to the stream |
|
1248 |
and append a newline character." |
|
1249 |
||
1250 |
self obsoleteMethodWarning:'use #showCR:'. |
|
1251 |
self showCR:aString. |
|
1252 |
||
1253 |
"Modified: 18.5.1996 / 15:46:01 / cg" |
|
62 | 1254 |
! |
1255 |
||
1256 |
space |
|
1403 | 1257 |
"append a space character to the receiver" |
62 | 1258 |
|
1259 |
self nextPut:(Character space) |
|
1403 | 1260 |
|
1261 |
"Modified: 15.5.1996 / 18:05:13 / cg" |
|
62 | 1262 |
! |
1263 |
||
1264 |
spaces:count |
|
1403 | 1265 |
"append count space-characters to the receiver" |
62 | 1266 |
|
1267 |
self next:count put:(Character space) |
|
1403 | 1268 |
|
1269 |
"Modified: 15.5.1996 / 18:05:17 / cg" |
|
62 | 1270 |
! |
1271 |
||
611 | 1272 |
store:anObject |
1273 |
"append a printed representation of anObject to the receiver, |
|
1403 | 1274 |
from which the receiver can be reconstructed (i.e. its storeString). |
1275 |
Same as 'anObject storeOn:self'; Added for ST-80 compatibility." |
|
77 | 1276 |
|
611 | 1277 |
anObject storeOn:self |
1403 | 1278 |
|
1279 |
"Modified: 15.5.1996 / 18:05:55 / cg" |
|
77 | 1280 |
! |
1281 |
||
611 | 1282 |
tab |
1283 |
"append a tab-character to the stream" |
|
77 | 1284 |
|
611 | 1285 |
self nextPut:(Character tab) |
77 | 1286 |
! ! |
1287 |
||
701 | 1288 |
!Stream class methodsFor:'documentation'! |
1289 |
||
1290 |
version |
|
1414 | 1291 |
^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.44 1996-05-18 13:48:22 cg Exp $' |
701 | 1292 |
! ! |
611 | 1293 |
Stream initialize! |