author | Martin Kobetic |
Sun, 17 Nov 2013 00:22:31 -0500 | |
changeset 144 | e193a6772be4 |
parent 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
9 | 1 |
"{ Package: 'stx:goodies/xtreams/terminals' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
ReadStream subclass:#SequenceableCollectionReadStream |
|
6 |
instanceVariableNames:'position' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
25
02e7c3b6f63c
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
9
diff
changeset
|
9 |
category:'Xtreams-Terminals' |
9 | 10 |
! |
11 |
||
12 |
SequenceableCollectionReadStream comment:'Read stream on a sequenceable collection. |
|
13 |
{{{ |
|
14 |
(1 to: 10000) reading ++ 1000; read: 5 |
|
15 |
}}} |
|
16 |
||
17 |
Instance Variables |
|
109 | 18 |
position <Integer> current position of the stream |
9 | 19 |
|
20 |
' |
|
21 |
! |
|
22 |
||
23 |
||
24 |
!SequenceableCollectionReadStream methodsFor:'accessing'! |
|
25 |
||
26 |
get |
|
27 |
position = source size ifTrue: [Incomplete zero raise]. |
|
28 |
position := position + 1. |
|
29 |
^source at: position |
|
30 |
! |
|
31 |
||
32 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
33 |
| count | |
|
34 |
count := anInteger min: self available. |
|
35 |
aSequenceableCollection replaceFrom: startIndex to: startIndex + count - 1 with: source startingAt: position + 1. |
|
36 |
position := position + count. |
|
37 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
38 |
^anInteger |
|
39 |
! ! |
|
40 |
||
41 |
!SequenceableCollectionReadStream methodsFor:'initialize-release'! |
|
42 |
||
43 |
close |
|
44 |
! |
|
45 |
||
46 |
contentsSpecies |
|
47 |
^source species |
|
48 |
! |
|
49 |
||
50 |
on: aSequenceableCollection |
|
51 |
super on: aSequenceableCollection. |
|
52 |
position := 0 |
|
53 |
! ! |
|
54 |
||
55 |
!SequenceableCollectionReadStream methodsFor:'printing'! |
|
56 |
||
57 |
streamingPrintOn: aStream |
|
58 |
| tail head | |
|
59 |
super streamingPrintOn: aStream. |
|
60 |
tail := position min: 5. |
|
61 |
head := (source size - position) min: (10 - tail). |
|
62 |
aStream |
|
63 |
write: ' position: '; |
|
64 |
print: position; |
|
65 |
write: ' size: '; |
|
66 |
print: source size; |
|
67 |
cr; tab; |
|
68 |
write: (position > 5 ifTrue: ['...'] ifFalse: ['']); |
|
69 |
print: (source copyFrom: position + 1 - tail to: position); |
|
70 |
write: ' | '; |
|
71 |
print: (source copyFrom: position + 1 to: position + head); |
|
72 |
write: (source size - position > (10 - tail) ifTrue: ['...'] ifFalse: ['']) |
|
73 |
! ! |
|
74 |
||
75 |
!SequenceableCollectionReadStream methodsFor:'private'! |
|
76 |
||
77 |
streamingInsert: anInteger into: aWriteStream |
|
78 |
| count | |
|
79 |
anInteger isZero ifTrue: [^self]. |
|
80 |
count := anInteger min: self available. |
|
81 |
aWriteStream insert: count from: source at: position + 1. |
|
82 |
position := position + count. |
|
83 |
count >= anInteger ifTrue: [^self]. |
|
84 |
(Incomplete on: source count: count at: position - count + 1) raise |
|
85 |
! |
|
86 |
||
87 |
streamingInsertInto: aWriteStream |
|
88 |
| count | |
|
89 |
(count := self available) isZero ifTrue: [Incomplete zero raise]. |
|
90 |
self streamingInsert: count into: aWriteStream. |
|
91 |
^count |
|
92 |
! |
|
93 |
||
94 |
streamingWrite: anInteger into: aWriteStream |
|
95 |
| count | |
|
96 |
anInteger isZero ifTrue: [^0]. |
|
97 |
count := anInteger min: self available. |
|
98 |
aWriteStream write: count from: source at: position + 1. |
|
99 |
position := position + count. |
|
100 |
count = anInteger ifTrue: [^anInteger]. |
|
101 |
(Incomplete on: source count: count at: position - count + 1) raise |
|
102 |
! |
|
103 |
||
104 |
streamingWriteInto: aWriteStream |
|
105 |
| count | |
|
106 |
(count := self available) isZero ifTrue: [^self]. |
|
107 |
self streamingWrite: count into: aWriteStream. |
|
108 |
^count |
|
109 |
! ! |
|
110 |
||
111 |
!SequenceableCollectionReadStream methodsFor:'seeking'! |
|
112 |
||
113 |
++ anInteger |
|
114 |
| count | |
|
115 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ]. |
|
116 |
count := self available min: anInteger. |
|
117 |
position := position + count. |
|
118 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
119 |
^anInteger |
|
120 |
! |
|
121 |
||
122 |
-- anInteger |
|
123 |
| count | |
|
124 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ]. |
|
125 |
count := position min: anInteger. |
|
126 |
position := position - count. |
|
127 |
count = anInteger ifTrue: [^anInteger]. |
|
128 |
(Incomplete count: count) raise |
|
129 |
! |
|
130 |
||
131 |
length |
|
132 |
^source size |
|
133 |
! |
|
134 |
||
135 |
position |
|
136 |
" Return a bookmark for the current stream state. " |
|
137 |
||
138 |
^position |
|
139 |
! |
|
140 |
||
141 |
position: aPosition |
|
142 |
||
143 |
aPosition < 0 ifTrue: [ Incomplete zero raise ]. |
|
144 |
position := aPosition min: self length. |
|
145 |
position = aPosition ifTrue: [^aPosition ]. |
|
146 |
(Incomplete count: position) raise |
|
147 |
! ! |
|
148 |
||
149 |
!SequenceableCollectionReadStream methodsFor:'testing'! |
|
150 |
||
151 |
isPositionable |
|
152 |
^true |
|
153 |
! ! |
|
154 |
||
155 |
!SequenceableCollectionReadStream class methodsFor:'documentation'! |
|
156 |
||
109 | 157 |
version_HG |
158 |
||
159 |
^ '$Changeset: <not expanded> $' |
|
9 | 160 |
! ! |
109 | 161 |