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