author | Claus Gittinger <cg@exept.de> |
Wed, 26 Jun 2019 22:06:12 +0200 | |
changeset 24369 | e796791ea838 |
parent 23895 | d49a46365ed5 |
child 24744 | 2d27b0eb2d4a |
permissions | -rw-r--r-- |
23895 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5393
7e2230bd4bad
moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents:
5308
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
7e2230bd4bad
moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents:
5308
diff
changeset
|
15 |
|
17559 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
57 | 18 |
PeekableStream subclass:#PositionableStream |
973 | 19 |
instanceVariableNames:'collection position readLimit writeLimit' |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
20 |
classVariableNames:'ZeroPosition InvalidPositionErrorSignal' |
973 | 21 |
poolDictionaries:'' |
22 |
category:'Streams' |
|
1 | 23 |
! |
24 |
||
1897 | 25 |
!PositionableStream class methodsFor:'documentation'! |
88 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 30 |
All Rights Reserved |
1 | 31 |
|
88 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
10 | 40 |
|
88 | 41 |
documentation |
42 |
" |
|
43 |
Instances of PositionableStream allow positioning the read pointer. |
|
44 |
The PositionableStream class also adds methods for source-chunk reading |
|
45 |
and writing, and for filing-in/out of source code. |
|
3249
8401c3e42165
checkin to force re-checkout.
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
46 |
|
88 | 47 |
This is an abstract class. |
1295 | 48 |
|
4405 | 49 |
Compatibility Notice: |
9434 | 50 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
51 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 52 |
|
17559 | 53 |
THIS CERTAINLY IS BAD. |
54 |
||
55 |
Although this is confusing ST/X has been changed to now also uses 0-based stream positioning. |
|
9434 | 56 |
|
17559 | 57 |
[caveat:] |
58 |
Basing capabilities like readability/writability/positionability/peekability on inheritance makes |
|
59 |
the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream |
|
60 |
below PositionableStream or ExternalReadStream under WriteStream) |
|
4405 | 61 |
|
1295 | 62 |
[author:] |
9434 | 63 |
Claus Gittinger |
88 | 64 |
" |
65 |
! ! |
|
1 | 66 |
|
1897 | 67 |
!PositionableStream class methodsFor:'initialization'! |
1 | 68 |
|
10 | 69 |
initialize |
15353 | 70 |
ZeroPosition := 0. "/ changed with stx rel5.1; |
71 |
"/ rel6.2: no longer used (i.e. 0 has now ben hardcoded) |
|
72 |
"/ class variable to be eliminated. |
|
7363 | 73 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
74 |
InvalidPositionErrorSignal isNil ifTrue:[ |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
75 |
InvalidPositionErrorSignal := PositionOutOfBoundsError. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
76 |
InvalidPositionErrorSignal notifierString:'position out of bounds: '. |
10 | 77 |
] |
78 |
! ! |
|
1 | 79 |
|
1897 | 80 |
!PositionableStream class methodsFor:'instance creation'! |
1 | 81 |
|
82 |
on:aCollection |
|
83 |
"return a new PositionableStream streaming on aCollection" |
|
84 |
||
85 |
^ (self basicNew) on:aCollection |
|
86 |
! |
|
87 |
||
88 |
on:aCollection from:first to:last |
|
89 |
"return a new PositionableStream streaming on aCollection |
|
90 |
from first to last" |
|
91 |
||
369 | 92 |
^ (self basicNew) on:aCollection from:first to:last |
57 | 93 |
! |
94 |
||
95 |
with:aCollection |
|
96 |
"return a new PositionableStream streaming on aCollection, |
|
97 |
the stream is positioned to the end of the collection." |
|
98 |
||
362 | 99 |
^ (self basicNew) with:aCollection |
1 | 100 |
! ! |
101 |
||
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
102 |
!PositionableStream class methodsFor:'Signal constants'! |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
103 |
|
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
104 |
invalidPositionErrorSignal |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
105 |
"return the signal raised if positioning is attempted to an |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
106 |
invalid position (i.e. before the begin of the stream or after |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
107 |
the end)" |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
108 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
109 |
^ PositionOutOfBoundsError |
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
110 |
! ! |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
111 |
|
1897 | 112 |
!PositionableStream class methodsFor:'constants'! |
1 | 113 |
|
4405 | 114 |
zeroPosition |
115 |
"return the number, which marks the initial position. |
|
116 |
Compatibility Notice: |
|
9434 | 117 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
118 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 119 |
|
9434 | 120 |
Although this is confusing ST/X has been changed to now also use 0-based stream positioning. |
121 |
" |
|
4405 | 122 |
|
15353 | 123 |
^ 0 |
9434 | 124 |
|
125 |
"Modified: / 13-07-2006 / 20:36:54 / cg" |
|
360 | 126 |
! ! |
127 |
||
21034 | 128 |
!PositionableStream class methodsFor:'testing'! |
129 |
||
130 |
isAbstract |
|
131 |
^ self == PositionableStream |
|
132 |
! ! |
|
133 |
||
23895 | 134 |
|
7261 | 135 |
!PositionableStream methodsFor:'Compatibility-Dolphin'! |
6413 | 136 |
|
137 |
endChunk |
|
138 |
self nextPutChunkSeparator |
|
139 |
! ! |
|
140 |
||
9284 | 141 |
!PositionableStream methodsFor:'Compatibility-ST/V'! |
142 |
||
143 |
skipTo:anElement |
|
144 |
"ST/V compatibility: |
|
145 |
skip for the element given by the argument, anElement; |
|
146 |
return nil if not found, self otherwise. |
|
147 |
On a successful match, the next read will return the element after anElement." |
|
148 |
||
149 |
^ self skipThrough:anElement |
|
150 |
||
151 |
" |
|
152 |
|s| |
|
153 |
s := ReadStream on:'12345678901234567890'. |
|
154 |
s skipTo:$5. |
|
155 |
s copyFrom:1 to:(s position). |
|
156 |
s upToEnd |
|
157 |
" |
|
158 |
! ! |
|
159 |
||
16876
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
160 |
!PositionableStream methodsFor:'Compatibility-Squeak'! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
161 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
162 |
back |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
163 |
"Go back one element and return it." |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
164 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
165 |
self position = 0 ifTrue: [self positionError]. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
166 |
self skip: -1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
167 |
^ self peek |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
168 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
169 |
"Created: / 03-10-2014 / 03:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
170 |
! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
171 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
172 |
peekBack |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
173 |
"Return the element at the previous position, without changing position. Use indirect messages in case self is a StandardFileStream." |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
174 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
175 |
| element | |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
176 |
element := self back. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
177 |
self skip: 1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
178 |
^ element |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
179 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
180 |
"Created: / 03-10-2014 / 03:06:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
181 |
! ! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
182 |
|
1 | 183 |
!PositionableStream methodsFor:'accessing'! |
184 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
185 |
collection |
19591 | 186 |
"return the underlying collection buffer. |
187 |
Notice, that this buffer may become invalid after being retrieved, |
|
188 |
if more data is written to the stream (because a bigger buffer might be |
|
189 |
allocated). Therefore, it should be only used in special situations, |
|
22404 | 190 |
where an already filled buffer needs to be backpatched later |
19591 | 191 |
(eg. before being sent out to some external stream or socket)" |
192 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
193 |
^ collection |
22404 | 194 |
|
195 |
"Modified (comment): / 02-01-2018 / 19:54:37 / stefan" |
|
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
196 |
! |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
197 |
|
1 | 198 |
contents |
199 |
"return the entire contents of the stream" |
|
200 |
||
201 |
^ collection |
|
202 |
! |
|
203 |
||
2432 | 204 |
peekForAll:aCollection |
205 |
"return true and advance if the next elements are the same |
|
206 |
as aCollection. |
|
207 |
otherwise stay and let the position unchanged" |
|
208 |
||
209 |
|oldPos| |
|
210 |
||
211 |
oldPos := self position. |
|
212 |
(self next:(aCollection size)) = aCollection ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
213 |
^ true |
2432 | 214 |
]. |
215 |
self position:oldPos. |
|
216 |
^ false |
|
217 |
||
218 |
"Created: 1.3.1997 / 15:11:25 / cg" |
|
219 |
! |
|
220 |
||
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
221 |
readLimit |
20423 | 222 |
"return the read-limit; that's the position at which EOF is returned" |
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
223 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
224 |
^ readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
225 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
226 |
"Created: / 30.10.1998 / 16:47:04 / cg" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
227 |
! |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
228 |
|
1 | 229 |
readLimit:aNumber |
20423 | 230 |
"set the read-limit; that's the position at which EOF is returned" |
1 | 231 |
|
232 |
readLimit := aNumber |
|
369 | 233 |
! |
234 |
||
14934 | 235 |
setCollection:newCollection |
236 |
collection := newCollection |
|
237 |
! |
|
238 |
||
369 | 239 |
writeLimit:aNumber |
20423 | 240 |
"set the writeLimit; that's the position after which writing is prohibited" |
369 | 241 |
|
242 |
writeLimit := aNumber |
|
10592 | 243 |
|
244 |
" |
|
245 |
|s| |
|
246 |
s := WriteStream on:String new. |
|
247 |
s nextPutAll:'hello world'. |
|
248 |
s contents. |
|
249 |
||
250 |
|s| |
|
251 |
s := WriteStream on:String new. |
|
252 |
s writeLimit:5. |
|
253 |
s nextPutAll:'hello world'. |
|
254 |
s contents. |
|
255 |
||
256 |
" |
|
257 |
||
258 |
"Modified: / 04-06-2007 / 17:21:55 / cg" |
|
1 | 259 |
! ! |
260 |
||
21136 | 261 |
!PositionableStream methodsFor:'non homogenous reading'! |
262 |
||
263 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
264 |
"return the next numBytes from the stream. If the end is |
|
22514 | 265 |
reached before, only that many bytes are copied into the |
21136 | 266 |
collection. |
267 |
Returns the number of bytes that have been actually read. |
|
268 |
The receiver must support reading of binary bytes. |
|
269 |
||
270 |
Notice: this method is provided here for protocol completeness |
|
271 |
with externalStreams - it is normally not used with other |
|
272 |
streams." |
|
273 |
||
274 |
|max| |
|
275 |
||
22514 | 276 |
(collection isSingleByteCollection |
22235 | 277 |
and:[aCollection class == collection class or:[aCollection isSingleByteCollection]] |
278 |
) ifTrue:[ |
|
21136 | 279 |
"do it the fast way" |
280 |
max := (readLimit - position) min: numBytes. |
|
281 |
aCollection |
|
22514 | 282 |
replaceBytesFrom:initialIndex |
21136 | 283 |
to:(initialIndex + max - 1) |
22514 | 284 |
with:collection |
21136 | 285 |
startingAt:position+1. |
286 |
position := position + max. |
|
287 |
^ max |
|
288 |
]. |
|
289 |
"do it the hard way" |
|
290 |
^ super nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
291 |
||
292 |
" |
|
293 |
|s n buffer| |
|
294 |
||
295 |
buffer := ByteArray new:10. |
|
296 |
||
297 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
298 |
s next:3. |
|
299 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
300 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
301 |
" |
|
22514 | 302 |
|
303 |
"Modified (comment): / 29-01-2018 / 14:44:20 / mawalch" |
|
21136 | 304 |
! ! |
305 |
||
611 | 306 |
!PositionableStream methodsFor:'positioning'! |
307 |
||
308 |
backStep |
|
309 |
"move backward read position by one" |
|
310 |
||
4405 | 311 |
self position:(self position - 1) |
611 | 312 |
! |
313 |
||
16188 | 314 |
match: subCollection |
315 |
"Set the access position of the receiver to be past the next occurrence of the subCollection. |
|
316 |
Answer whether subCollection is found. |
|
317 |
No wildcards, and case does matter." |
|
318 |
||
319 |
| pattern startMatch | |
|
320 |
||
321 |
pattern := ReadStream on: subCollection. |
|
322 |
startMatch := nil. |
|
323 |
[pattern atEnd] whileFalse: [ |
|
324 |
self atEnd ifTrue: [^ false]. |
|
325 |
(self next) = (pattern next) |
|
326 |
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]] |
|
327 |
ifFalse: [ |
|
328 |
pattern position: 0. |
|
329 |
startMatch ifNotNil: [ |
|
330 |
self position: startMatch. |
|
331 |
startMatch := nil |
|
332 |
] |
|
333 |
] |
|
334 |
]. |
|
335 |
^ true |
|
336 |
||
337 |
" |
|
338 |
'abc def ghi' readStream match:'def'; upToEnd |
|
339 |
" |
|
340 |
! |
|
341 |
||
611 | 342 |
position |
15615 | 343 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
344 |
|
15348 | 345 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
346 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
347 |
|
15615 | 348 |
position0Based |
349 |
<resource: #obsolete> |
|
350 |
"return the read position 0-based" |
|
351 |
||
352 |
^ self position |
|
353 |
! |
|
354 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
355 |
position0Based:index0Based |
15615 | 356 |
<resource: #obsolete> |
4405 | 357 |
"set the read (or write) position" |
611 | 358 |
|
15615 | 359 |
self position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
360 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
361 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
362 |
position1Based |
15615 | 363 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
364 |
"return the read position 1-based" |
611 | 365 |
|
15615 | 366 |
^ self position + 1 |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
367 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
368 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
369 |
position1Based:index1Based |
15615 | 370 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
371 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
372 |
|
15615 | 373 |
self position:(index1Based - 1) |
4405 | 374 |
|
375 |
" |
|
376 |
|s| |
|
377 |
||
378 |
s := '1234567890' readStream. |
|
379 |
s next:5. |
|
380 |
s position:1. |
|
381 |
s next:7. |
|
382 |
" |
|
383 |
||
384 |
" |
|
385 |
|s| |
|
386 |
||
387 |
s := '' writeStream. |
|
388 |
s nextPutAll:'1234567890'. |
|
389 |
s position:5. |
|
390 |
s nextPutAll:'abcdefg'. |
|
391 |
s contents |
|
392 |
" |
|
393 |
||
394 |
" |
|
395 |
|s| |
|
396 |
||
397 |
s := '' writeStream. |
|
398 |
s nextPutAll:'1234567890'. |
|
399 |
s position:0. |
|
400 |
s nextPutAll:'abcdefg'. |
|
401 |
s contents |
|
402 |
" |
|
611 | 403 |
! |
404 |
||
15615 | 405 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
406 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
407 |
|
15615 | 408 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
409 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
410 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
411 |
|
611 | 412 |
reset |
413 |
"set the read position to the beginning of the collection" |
|
414 |
||
19885 | 415 |
position := 0. |
5308 | 416 |
|
417 |
" |
|
418 |
|s| |
|
419 |
||
420 |
s := 'hello world' readStream. |
|
421 |
Transcript showCR:(s next:5). |
|
422 |
s reset. |
|
423 |
Transcript showCR:(s next:10). |
|
424 |
" |
|
425 |
! |
|
426 |
||
427 |
resetPosition |
|
19885 | 428 |
<resource: #obsolete> |
5308 | 429 |
"set the read position to the beginning of the collection" |
430 |
||
15348 | 431 |
position := 0 |
4405 | 432 |
|
433 |
" |
|
434 |
|s| |
|
435 |
||
436 |
s := 'hello world' readStream. |
|
437 |
Transcript showCR:(s next:5). |
|
438 |
s reset. |
|
439 |
Transcript showCR:(s next:10). |
|
440 |
" |
|
611 | 441 |
! |
442 |
||
443 |
setToEnd |
|
11433 | 444 |
"set the read position to the end of the collection. |
445 |
#next will return EOF, #nextPut: will append to the stream. |
|
446 |
(same Behavior as FileStream." |
|
611 | 447 |
|
15348 | 448 |
position := readLimit |
611 | 449 |
! |
450 |
||
451 |
skip:numberToSkip |
|
452 |
"skip the next numberToSkip elements" |
|
453 |
||
5774 | 454 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
455 |
self position:(self position + numberToSkip) |
5774 | 456 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
457 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
458 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
459 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
460 |
"skip for and through the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
461 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
462 |
On a successful match, the next read will return elements after aCollection; |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
463 |
if no match was found, the receiver will be positioned at the end. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
464 |
This is redefined here, to make use of positioning." |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
465 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
466 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
467 |
|
16186 | 468 |
self isPositionable ifFalse:[ |
469 |
"/ for non-positionable subclasses |
|
470 |
^ super skipThroughAll:aCollection |
|
471 |
]. |
|
472 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
473 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
474 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
475 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
476 |
buffer := self nextAvailable:len. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
477 |
buffer size == len ifTrue:[ |
16209 | 478 |
buffer = aCollection ifTrue:[ |
479 |
^ self |
|
480 |
]. |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
481 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
482 |
idx := buffer indexOf:first startingAt:2. |
16209 | 483 |
idx ~~ 0 ifTrue:[ |
484 |
self skip:(idx - len - 1) |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
485 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
486 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
487 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
488 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
489 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
490 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
491 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
492 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
493 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
494 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
495 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
496 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
497 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
498 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
499 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
500 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
501 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
502 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
503 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
504 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
505 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
506 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
507 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
508 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
509 |
"Created: 26.6.1996 / 09:35:35 / cg" |
2154
89e96599e1e2
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
510 |
"Modified: 11.1.1997 / 19:16:38 / cg" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
511 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
512 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
513 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
514 |
"skip for the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
515 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
516 |
On a successful match, the next read will return elements of aCollection." |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
517 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
518 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
519 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
520 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
521 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
522 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
523 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
524 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
525 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
526 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
527 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
528 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
529 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
530 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
531 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
532 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
533 |
self position:(self position - len + idx - 1) |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
534 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
535 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
536 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
537 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
538 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
539 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
540 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
541 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
542 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
543 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
544 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
545 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
546 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
547 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
548 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
549 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
550 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
551 |
s upToEnd |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
552 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
553 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
554 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
555 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
556 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
557 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
558 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
559 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
560 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
561 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
562 |
s close. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
563 |
] |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
564 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
565 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
566 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
567 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 568 |
! ! |
611 | 569 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
570 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
571 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
572 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
573 |
aStream nextPutAll:self className; nextPutAll:'(on:'; nextPutAll:collection classNameWithArticle; nextPut:$) |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
574 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
575 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
576 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
577 |
'' writeStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
578 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
579 |
! ! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
580 |
|
611 | 581 |
!PositionableStream methodsFor:'private'! |
582 |
||
583 |
contentsSpecies |
|
584 |
"return a class of which instances will be returned, when |
|
585 |
parts of the collection are asked for. |
|
15640 | 586 |
(see upTo-kind of methods in Stream)" |
611 | 587 |
|
588 |
^ collection species |
|
589 |
! |
|
590 |
||
591 |
on:aCollection |
|
592 |
"setup for streaming on aCollection" |
|
593 |
||
594 |
collection := aCollection. |
|
595 |
readLimit := aCollection size. |
|
13379 | 596 |
readLimit == 0 ifTrue:[ |
597 |
self assert:(aCollection isCollection) |
|
598 |
]. |
|
15348 | 599 |
position := 0 |
611 | 600 |
! |
601 |
||
602 |
on:aCollection from:first to:last |
|
603 |
"setup for streaming on aCollection from first to last" |
|
604 |
||
605 |
collection := aCollection. |
|
15348 | 606 |
position := first - 1. |
611 | 607 |
readLimit := last |
608 |
! |
|
609 |
||
610 |
positionError |
|
1998 | 611 |
"{ Pragma: +optSpace }" |
612 |
||
2966 | 613 |
"report an error when positioning past the end |
614 |
or before the beginning." |
|
611 | 615 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
616 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
617 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
618 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 619 |
! |
620 |
||
6314 | 621 |
positionError:badPostition |
622 |
"{ Pragma: +optSpace }" |
|
623 |
||
624 |
"report an error when positioning past the end |
|
625 |
or before the beginning." |
|
626 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
627 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 628 |
! |
629 |
||
611 | 630 |
with:aCollection |
631 |
"setup for streaming to the end of aCollection" |
|
632 |
||
633 |
collection := aCollection. |
|
11434 | 634 |
readLimit := aCollection size. |
611 | 635 |
self setToEnd |
11434 | 636 |
|
637 |
" |
|
638 |
(WriteStream with:#(1 2 3 4 5)) |
|
639 |
nextPut:6; |
|
640 |
contents |
|
641 |
" |
|
611 | 642 |
! ! |
643 |
||
16195 | 644 |
!PositionableStream methodsFor:'queries'! |
645 |
||
16209 | 646 |
endsBeforePositionWith:aSequenceableCollection |
16195 | 647 |
"answer true, if the elements in aSequenceableCollection |
16209 | 648 |
are at the current end of the stream up to position." |
16195 | 649 |
|
16209 | 650 |
|sz pos| |
16195 | 651 |
|
16209 | 652 |
sz := aSequenceableCollection size. |
653 |
pos := self position. |
|
654 |
pos < sz ifTrue:[ |
|
655 |
^ false. |
|
16195 | 656 |
]. |
16209 | 657 |
self contentsSpecies == collection class ifTrue:[ |
658 |
^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1. |
|
659 |
]. |
|
660 |
self position:pos-sz. |
|
661 |
^ (self next:sz) = aSequenceableCollection. |
|
16195 | 662 |
|
663 |
" |
|
16209 | 664 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World' |
665 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World' |
|
666 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx' |
|
667 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla' |
|
668 |
('' writeStream) endsBeforePositionWith:'Bla' |
|
669 |
('' writeStream) endsBeforePositionWith:'' |
|
16195 | 670 |
'' endsWith:'' |
671 |
" |
|
672 |
! ! |
|
673 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
674 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
675 |
|
9003 | 676 |
nextAvailable:count |
22204 | 677 |
"return the next count elements of the stream as aCollection. |
678 |
If the stream reaches the end before count elements have been read, |
|
679 |
return what is available. (i.e. a shorter collection)." |
|
680 |
||
17606 | 681 |
collection notNil ifTrue:[ |
682 |
|end result| |
|
9003 | 683 |
|
17606 | 684 |
end := position + count. |
685 |
end >= readLimit ifTrue:[ |
|
686 |
end := readLimit. |
|
687 |
]. |
|
688 |
||
689 |
result := collection copyFrom:position+1 to:end. |
|
690 |
position := end. |
|
691 |
^ result. |
|
9003 | 692 |
]. |
693 |
||
17606 | 694 |
^ super nextAvailable:count. |
9003 | 695 |
|
696 |
" |
|
697 |
'abc' readStream nextAvailable:1. |
|
698 |
'abc' readStream nextAvailable:2. |
|
699 |
'abc' readStream nextAvailable:3. |
|
700 |
'abc' readStream nextAvailable:4. |
|
701 |
||
702 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
703 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
704 |
" |
|
22204 | 705 |
|
706 |
"Modified (format): / 22-08-2017 / 20:25:54 / cg" |
|
9003 | 707 |
! |
708 |
||
17611 | 709 |
nextAvailable:count into:aCollection startingAt:initialIndex |
710 |
"return the next count objects from the stream. If the end is |
|
22514 | 711 |
reached before, only that many objects are copied into the |
17611 | 712 |
collection. |
713 |
Returns the number of objects that have been actually read." |
|
714 |
||
715 |
| max | |
|
716 |
||
717 |
collection notNil ifTrue:[ |
|
718 |
max := (readLimit - position) min: count. |
|
719 |
aCollection |
|
720 |
replaceFrom: initialIndex |
|
721 |
to: initialIndex+max-1 |
|
722 |
with: collection |
|
723 |
startingAt: position+1. |
|
724 |
position := position + max. |
|
725 |
^ max. |
|
726 |
]. |
|
727 |
||
728 |
^ super nextAvailable:count into:aCollection startingAt:initialIndex. |
|
729 |
||
730 |
" |
|
731 |
|s n buffer| |
|
732 |
||
733 |
buffer := ByteArray new:10. |
|
734 |
||
735 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
736 |
s next:3. |
|
737 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
738 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
739 |
" |
|
22514 | 740 |
|
741 |
"Modified (comment): / 29-01-2018 / 14:43:56 / mawalch" |
|
17611 | 742 |
! |
743 |
||
21136 | 744 |
peek |
745 |
"look ahead for and return the next element" |
|
17611 | 746 |
|
21136 | 747 |
|peekObject| |
20691 | 748 |
|
21136 | 749 |
peekObject := self next. |
750 |
self backStep. |
|
751 |
^ peekObject |
|
20691 | 752 |
! |
753 |
||
22003 | 754 |
peek:n |
755 |
"look ahead n elements and return them after positioning pack to the |
|
756 |
position we had before" |
|
757 |
||
758 |
|posBefore peekObjects| |
|
759 |
||
760 |
posBefore := self position. |
|
761 |
peekObjects := self next:n. |
|
762 |
self position:posBefore. |
|
763 |
^ peekObjects |
|
764 |
||
765 |
" |
|
766 |
|s| |
|
767 |
||
768 |
s := '1234567890' readStream. |
|
769 |
s peek:4. |
|
770 |
s next:5. |
|
771 |
" |
|
772 |
||
773 |
"Created: / 13-07-2017 / 12:32:03 / cg" |
|
774 |
! |
|
775 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
776 |
upToAll:aCollection |
16186 | 777 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
778 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
779 |
The position is left before the collection; i.e. the next |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
780 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
781 |
If no such subcollection is encountered, all elements up to the end |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
782 |
are read and returned. |
6494 | 783 |
See also #throughAll: which also reads up to some objects |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
784 |
but positions behind it and DOES include it in the returned |
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
785 |
collection. |
6494 | 786 |
See also #upToAllExcluding:, which returns the same, but leaves the |
787 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
788 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
789 |
Note: this behavior is inconsistent with the other upTo.. methods, |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
790 |
which position after the found item. We implement the method |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
791 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
792 |
|
17611 | 793 |
"/ in the future, this will have the Squeak semantics, which is upToAllExcluding: |
16189 | 794 |
|
795 |
^ self upToAll_positionBefore:aCollection |
|
796 |
||
797 |
" |
|
798 |
|s| |
|
799 |
s := ReadStream on:'hello world'. |
|
800 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
801 |
Transcript showCR:s atEnd. |
|
802 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
803 |
" |
|
804 |
" |
|
805 |
|s| |
|
806 |
s := ReadStream on:'hello world'. |
|
807 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
808 |
Transcript showCR:s atEnd. |
|
809 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
810 |
" |
|
811 |
" |
|
812 |
|s| |
|
813 |
s := ReadStream on:'hello world'. |
|
814 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
815 |
Transcript showCR:s atEnd. |
|
816 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
817 |
" |
|
818 |
||
819 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
|
820 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
|
821 |
! |
|
822 |
||
823 |
upToAll_positionBefore:aCollection |
|
824 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
|
825 |
Return everything read excluding the elements in aCollection. |
|
826 |
The position is left before the collection; i.e. the next |
|
827 |
read operations will return those elements. |
|
828 |
If no such subcollection is encountered, all elements up to the end |
|
829 |
are read and returned. |
|
830 |
See also #throughAll: which also reads up to some objects |
|
831 |
but positions behind it and DOES include it in the returned |
|
16840 | 832 |
collection." |
16189 | 833 |
|
16209 | 834 |
|answerStream element last| |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
835 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
836 |
last := aCollection last. |
22410 | 837 |
answerStream := self contentsSpecies writeStream. |
16209 | 838 |
[(element := self nextOrNil) notNil] whileTrue:[ |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
839 |
answerStream nextPut:element. |
16209 | 840 |
(element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[ |
841 |
|backStep| |
|
842 |
backStep := aCollection size negated. |
|
843 |
self skip:backStep. |
|
844 |
answerStream skip:backStep. |
|
845 |
^ answerStream contents |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
846 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
847 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
848 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
849 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
850 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
851 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
852 |
s := ReadStream on:'hello world'. |
16209 | 853 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
6494 | 854 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
855 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
856 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
857 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
858 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
859 |
s := ReadStream on:'hello world'. |
16209 | 860 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 861 |
Transcript showCR:s atEnd. |
16209 | 862 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 863 |
" |
864 |
" |
|
865 |
|s| |
|
866 |
s := ReadStream on:'hello world'. |
|
16209 | 867 |
Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
868 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
869 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
870 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
871 |
|
22410 | 872 |
"Created: / 12-01-1998 / 22:07:01 / cg" |
873 |
"Modified: / 10-01-2018 / 18:30:07 / stefan" |
|
20101 | 874 |
! |
875 |
||
876 |
upToEnd |
|
877 |
collection notNil ifTrue:[ |
|
878 |
|result| |
|
879 |
||
880 |
result := collection copyFrom:position+1 to:readLimit. |
|
881 |
position := readLimit. |
|
882 |
^ result. |
|
883 |
]. |
|
884 |
||
885 |
^ super upToEnd. |
|
886 |
||
887 |
" |
|
888 |
'abc' readStream upToEnd. |
|
889 |
" |
|
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
890 |
! ! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
891 |
|
21136 | 892 |
!PositionableStream methodsFor:'reading-strings'! |
893 |
||
894 |
nextLine |
|
895 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
896 |
character (i.e. read a single line of text). |
|
897 |
If the previous-to-last character is a cr, this is also removed, |
|
898 |
so it's possible to read alien (i.e. ms-dos) text as well. |
|
899 |
Added for protocol compatibility with externalStreams." |
|
900 |
||
901 |
|start "{ Class:SmallInteger }" |
|
902 |
end "{ Class:SmallInteger }"| |
|
903 |
||
904 |
collection isString ifTrue:[ |
|
905 |
position == readLimit ifTrue:[ |
|
906 |
^ self pastEndRead |
|
907 |
]. |
|
908 |
start := position+1. |
|
909 |
end := collection indexOf:Character cr startingAt:start. |
|
910 |
||
911 |
(end == 0 or:[end > readLimit]) ifTrue:[ |
|
912 |
end := position := readLimit. |
|
913 |
] ifFalse:[ |
|
914 |
position := end. |
|
915 |
end := end - 1. "skip lf" |
|
916 |
]. |
|
917 |
start > end ifTrue:[ |
|
918 |
^ ''. |
|
919 |
]. |
|
920 |
(collection at:end) == Character return ifTrue:[ |
|
921 |
end := end - 1. "skip return" |
|
922 |
]. |
|
923 |
^ collection copyFrom:start to:end. |
|
924 |
]. |
|
925 |
^ super nextLine. |
|
926 |
||
927 |
" |
|
928 |
'12345678' readStream nextLine |
|
929 |
'12345678' allBold readStream nextLine |
|
930 |
'12\34\56\78' withCRs readStream nextLine |
|
931 |
'12\34\56\78' withCRs readStream nextLine; nextLine |
|
932 |
(ReadStream on:('12\34\56\78' withCRs) from:1 to:4) nextLine; nextLine |
|
933 |
('12\' withCRs, Character return, '34') readStream nextLine; nextLine |
|
934 |
Character cr asString readStream nextLine |
|
935 |
Character return asString readStream nextLine |
|
936 |
(Character return, Character cr) asString readStream nextLine |
|
937 |
Character return asString readStream nextLine; nextLine |
|
938 |
" |
|
939 |
! ! |
|
940 |
||
23895 | 941 |
!PositionableStream methodsFor:'stream-to-stream copy'! |
942 |
||
943 |
copy:numberOfElementsOrNil into:aWriteStream |
|
944 |
"read from the receiver, and write numberOfElementsOrNil data to another aWriteStream. |
|
945 |
If numberOfElementsOrNil is nil, copy until the end of myself. |
|
946 |
Return the number of elements which have been transferred. |
|
947 |
Redefined here to avoid intermediate buffers/garbage." |
|
948 |
||
949 |
|endPosition cnt| |
|
950 |
||
951 |
collection notNil ifTrue:[ |
|
952 |
numberOfElementsOrNil isNil ifTrue:[ |
|
953 |
endPosition := readLimit. "/ read until end |
|
954 |
] ifFalse:[ |
|
955 |
endPosition := (position+numberOfElementsOrNil) min:readLimit. |
|
956 |
]. |
|
957 |
aWriteStream nextPutAll:collection startingAt:position+1 to:endPosition. |
|
958 |
cnt := endPosition - position. |
|
959 |
position := endPosition. |
|
960 |
^ cnt. |
|
961 |
]. |
|
962 |
||
963 |
^ super copy:numberOfElementsOrNil into:aWriteStream. |
|
964 |
||
965 |
||
966 |
" |
|
967 |
'hello world' readStream copy:5 into:'/tmp/mist' asFilename writeStream. |
|
968 |
'hello world' readStream |
|
969 |
copy:5 into:Transcript; |
|
970 |
copy:20 into:Transcript. |
|
971 |
'hello world' readStream copy:5 into:'' writeStream inspect. |
|
972 |
#[1 2 3 4 5 6 7] readStream copy:2 into:'/tmp/mist' asFilename writeStream binary. |
|
973 |
#[1 2 3 4 5 6 7] readStream copy:3 into:#[] writeStream. |
|
974 |
" |
|
975 |
||
976 |
" |
|
977 |
|rs ws cnt| |
|
978 |
||
979 |
ws := #() writeStream. |
|
980 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
981 |
rs next. |
|
982 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
983 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
984 |
" |
|
985 |
||
986 |
"Modified (comment): / 13-03-2019 / 16:59:18 / Stefan Vogel" |
|
987 |
! |
|
988 |
||
989 |
copy:numberOfElementsOrNil into:aWriteStream bufferSize:bufferSize |
|
990 |
"read from the receiver, and write numberOfElementsOrNil to another aWriteStream. |
|
991 |
If numberOfElementsOrNil is nil, copy until the end of myself. |
|
992 |
Return the number of elements which have been transferred. |
|
993 |
Redefined here to avoid intermediate buffers/garbage |
|
994 |
- bufferSize does not matter here." |
|
995 |
||
996 |
collection notNil ifTrue:[ |
|
997 |
^ self copy:numberOfElementsOrNil into:aWriteStream. |
|
998 |
]. |
|
999 |
^ super copy:numberOfElementsOrNil into:aWriteStream bufferSize:bufferSize. |
|
1000 |
||
1001 |
"Modified (comment): / 13-03-2019 / 17:00:11 / Stefan Vogel" |
|
1002 |
! ! |
|
1003 |
||
611 | 1004 |
!PositionableStream methodsFor:'testing'! |
1005 |
||
1006 |
atEnd |
|
1007 |
"return true, if the read-position is at the end" |
|
1008 |
||
15357 | 1009 |
^ position >= readLimit |
611 | 1010 |
! |
1011 |
||
1012 |
isEmpty |
|
1013 |
"return true, if the contents of the stream is empty" |
|
1014 |
||
1015 |
^ readLimit == 0 |
|
9006 | 1016 |
! |
1017 |
||
10577 | 1018 |
isInternalByteStream |
1019 |
"return true, if the stream is an internal stream reading bytes" |
|
1020 |
||
1021 |
^ collection class isBytes |
|
1022 |
||
1023 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
1024 |
! |
|
1025 |
||
9006 | 1026 |
isPositionable |
1027 |
"return true, if the stream supports positioning (this one is)" |
|
1028 |
||
1029 |
^ true |
|
611 | 1030 |
! ! |
1031 |
||
1897 | 1032 |
!PositionableStream class methodsFor:'documentation'! |
701 | 1033 |
|
1034 |
version |
|
19403 | 1035 |
^ '$Header$' |
13379 | 1036 |
! |
1037 |
||
1038 |
version_CVS |
|
19403 | 1039 |
^ '$Header$' |
701 | 1040 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
1041 |
|
14934 | 1042 |
|
611 | 1043 |
PositionableStream initialize! |