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 |
ReadSubstream subclass:#PositionReadSubstream |
|
6 |
instanceVariableNames:'position' |
|
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 |
PositionReadSubstream comment:'This is an abstract substreams that keeps track of its own position and allows positioning if the underlying stream is positionable. |
|
13 |
||
14 |
Instance Variables |
|
109 | 15 |
position <Integer> current position within the substream |
4 | 16 |
|
17 |
' |
|
18 |
! |
|
19 |
||
20 |
||
21 |
!PositionReadSubstream methodsFor:'accessing'! |
|
22 |
||
23 |
get |
|
24 |
| object | |
|
25 |
object := super get. |
|
26 |
position := position + 1. |
|
27 |
^object |
|
28 |
! |
|
29 |
||
30 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
31 |
[source read: anInteger into: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete | |
|
32 |
sourceAtEnd := true. |
|
33 |
position := position + incomplete count. |
|
34 |
incomplete pass]. |
|
35 |
position := position + anInteger. |
|
36 |
^anInteger |
|
37 |
! ! |
|
38 |
||
39 |
!PositionReadSubstream methodsFor:'initialize-release'! |
|
40 |
||
41 |
on: aSource |
|
42 |
super on: aSource. |
|
43 |
position := 0 |
|
44 |
! ! |
|
45 |
||
46 |
!PositionReadSubstream methodsFor:'seeking'! |
|
47 |
||
48 |
++ anInteger |
|
49 |
| count | |
|
50 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ]. |
|
51 |
count := self available min: anInteger. |
|
52 |
count := [source ++ count. count] on: Incomplete do: [ :ex | ex count ]. |
|
53 |
position := position + count. |
|
54 |
count < anInteger ifTrue: [sourceAtEnd := true. (Incomplete count: count) raise]. |
|
55 |
^anInteger |
|
56 |
! |
|
57 |
||
58 |
-- anInteger |
|
59 |
| count | |
|
60 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ]. |
|
61 |
count := anInteger min: position. |
|
62 |
count := [source -- count. count] on: Incomplete do: [ :ex | ex count ]. |
|
63 |
position := position - count. |
|
64 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
65 |
anInteger isZero ifFalse: [sourceAtEnd := false]. |
|
66 |
^anInteger |
|
67 |
! |
|
68 |
||
69 |
-= anInteger |
|
70 |
position := self length - anInteger max: 0. |
|
71 |
^source -= anInteger |
|
72 |
! |
|
73 |
||
74 |
length |
|
75 |
^source available + position |
|
76 |
! |
|
77 |
||
78 |
position |
|
79 |
^position |
|
80 |
! |
|
81 |
||
82 |
position: anInteger |
|
83 |
| delta available | |
|
84 |
self isPositionable ifFalse: [self error: 'This stream is not positionable.']. |
|
85 |
||
86 |
anInteger < 0 ifTrue: [Incomplete zero raise]. |
|
87 |
available := anInteger min: self length. |
|
88 |
delta := available - position. |
|
89 |
[delta positive |
|
109 | 90 |
ifTrue: [source ++ delta] |
91 |
ifFalse: [source -- delta negated]] |
|
4 | 92 |
on: Incomplete do: [sourceAtEnd := true]. |
93 |
position := available. |
|
94 |
available = anInteger ifTrue: [^anInteger]. |
|
95 |
(Incomplete count: available) raise |
|
96 |
! ! |
|
97 |
||
98 |
!PositionReadSubstream methodsFor:'testing'! |
|
99 |
||
100 |
isPositionable |
|
101 |
^source isPositionable |
|
102 |
! ! |
|
103 |
||
104 |
!PositionReadSubstream class methodsFor:'documentation'! |
|
105 |
||
109 | 106 |
version_HG |
107 |
||
108 |
^ '$Changeset: <not expanded> $' |
|
4 | 109 |
! ! |
109 | 110 |