author | joe |
Fri, 15 Mar 2013 19:54:41 -0400 | |
changeset 113 | c0df9d2ad5d3 |
parent 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/xtreams/substreams' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
PositionReadSubstream subclass:#LimitReadSubstream |
|
6 |
instanceVariableNames:'limit' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
22
e0653bbdbe61
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
4
diff
changeset
|
9 |
category:'Xtreams-Substreams' |
4 | 10 |
! |
11 |
||
12 |
LimitReadSubstream comment:'Limits the number of elements that can be read from the source stream. |
|
13 |
||
14 |
Instance Variables |
|
109 | 15 |
limit <Integer> maximum number of elements that can be read from this stream |
16 |
position <Integer> number of elements already read from the stream |
|
4 | 17 |
|
18 |
' |
|
19 |
! |
|
20 |
||
21 |
||
22 |
!LimitReadSubstream class methodsFor:'instance creation'! |
|
23 |
||
24 |
on: aSource limit: anInteger |
|
25 |
^self new on: aSource limit: anInteger |
|
26 |
! ! |
|
27 |
||
28 |
!LimitReadSubstream methodsFor:'accessing'! |
|
29 |
||
30 |
get |
|
31 |
position = limit ifTrue: [Incomplete zero raise]. |
|
32 |
^super get |
|
33 |
! |
|
34 |
||
35 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
36 |
| count | |
|
37 |
count := anInteger min: self available. |
|
38 |
super read: count into: aSequenceableCollection at: startIndex. |
|
39 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
40 |
^anInteger |
|
41 |
! ! |
|
42 |
||
43 |
!LimitReadSubstream methodsFor:'initialize-release'! |
|
44 |
||
45 |
on: aSource limit: anInteger |
|
46 |
self on: aSource. |
|
47 |
limit := anInteger |
|
48 |
! |
|
49 |
||
50 |
subseekend |
|
51 |
self isPositionable ifFalse: [^self]. |
|
52 |
self -= 0 |
|
53 |
! ! |
|
54 |
||
55 |
!LimitReadSubstream methodsFor:'seeking'! |
|
56 |
||
57 |
-= anInteger |
|
58 |
| available | |
|
59 |
anInteger < 0 ifTrue: [Incomplete zero raise]. |
|
60 |
available := anInteger min: limit. |
|
61 |
source ++ (limit - position - available). |
|
62 |
position := limit - available. |
|
63 |
available = anInteger ifTrue: [^anInteger]. |
|
64 |
^(Incomplete count: available) raise |
|
65 |
! |
|
66 |
||
67 |
length |
|
68 |
^limit |
|
69 |
! ! |
|
70 |
||
71 |
!LimitReadSubstream class methodsFor:'documentation'! |
|
72 |
||
109 | 73 |
version_HG |
74 |
||
75 |
^ '$Changeset: <not expanded> $' |
|
4 | 76 |
! ! |
109 | 77 |