author | Martin Kobetic |
Sun, 17 Nov 2013 00:21:39 -0500 | |
changeset 141 | 263190106319 |
parent 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
9 | 1 |
"{ Package: 'stx:goodies/xtreams/terminals' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
ReadStream subclass:#BufferReadStream |
|
6 |
instanceVariableNames:'' |
|
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 |
BufferReadStream comment:'Read stream on a Buffer. Usually used in tandem with a write stream to access buffer contents conveniently. |
|
13 |
{{{ |
|
14 |
buffer := ElasticBuffer on: String new. |
|
15 |
bufferIn := buffer writing. |
|
16 |
bufferOut := buffer reading. |
|
17 |
100000 timesRepeat: [ bufferIn write: ''Hello World''. bufferOut read: 11 ]. |
|
109 | 18 |
buffer cacheSize |
9 | 19 |
}}} |
20 |
' |
|
21 |
! |
|
22 |
||
23 |
||
24 |
!BufferReadStream methodsFor:'accessing'! |
|
25 |
||
26 |
get |
|
27 |
^source get |
|
28 |
! |
|
29 |
||
30 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
31 |
source read: anInteger into: aSequenceableCollection at: startIndex. |
|
32 |
^anInteger |
|
33 |
! ! |
|
34 |
||
35 |
!BufferReadStream methodsFor:'initialize-release'! |
|
36 |
||
37 |
close |
|
38 |
! |
|
39 |
||
40 |
contentsSpecies |
|
41 |
^source contentsSpecies |
|
42 |
! ! |
|
43 |
||
44 |
!BufferReadStream methodsFor:'seeking'! |
|
45 |
||
46 |
++ anInteger |
|
47 |
| count | |
|
48 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ]. |
|
49 |
count := source readSkip: anInteger. |
|
50 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
51 |
^anInteger |
|
52 |
! |
|
53 |
||
54 |
-- anInteger |
|
55 |
| count | |
|
56 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ]. |
|
57 |
count := (source readSkip: anInteger negated) negated. |
|
58 |
count = anInteger ifTrue: [^anInteger]. |
|
59 |
(Incomplete count: count) raise |
|
60 |
! |
|
61 |
||
62 |
available |
|
63 |
^source readSize |
|
64 |
! |
|
65 |
||
66 |
length |
|
67 |
^source activeSize |
|
68 |
! |
|
69 |
||
70 |
position |
|
71 |
^source readPosition |
|
72 |
! |
|
73 |
||
74 |
position: aPosition |
|
75 |
| available | |
|
76 |
aPosition < 0 ifTrue: [ Incomplete zero raise ]. |
|
77 |
available := aPosition min: source activeSize. |
|
78 |
source readPosition: available. |
|
79 |
available = aPosition ifTrue: [^aPosition ]. |
|
80 |
(Incomplete count: available) raise |
|
81 |
! ! |
|
82 |
||
83 |
!BufferReadStream methodsFor:'testing'! |
|
84 |
||
85 |
isPositionable |
|
86 |
^true |
|
87 |
! ! |
|
88 |
||
89 |
!BufferReadStream class methodsFor:'documentation'! |
|
90 |
||
109 | 91 |
version_HG |
92 |
||
93 |
^ '$Changeset: <not expanded> $' |
|
9 | 94 |
! ! |
109 | 95 |