author | mkobetic |
Sun, 15 Jan 2012 02:18:17 +0000 | |
changeset 39 | 80fdc4602b14 |
parent 25 | 02e7c3b6f63c |
child 43 | b9a077d6ce14 |
permissions | -rw-r--r-- |
39 | 1 |
'From Smalltalk/X, Version:6.2.1 on 14-01-2012 at 09:10:27 PM' ! |
2 |
||
9 | 3 |
"{ Package: 'stx:goodies/xtreams/terminals' }" |
4 |
||
5 |
"{ NameSpace: Xtreams }" |
|
6 |
||
7 |
ReadStream subclass:#BufferReadStream |
|
8 |
instanceVariableNames:'' |
|
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
25
02e7c3b6f63c
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
9
diff
changeset
|
11 |
category:'Xtreams-Terminals' |
9 | 12 |
! |
13 |
||
14 |
BufferReadStream comment:'Read stream on a Buffer. Usually used in tandem with a write stream to access buffer contents conveniently. |
|
15 |
{{{ |
|
16 |
buffer := ElasticBuffer on: String new. |
|
17 |
bufferIn := buffer writing. |
|
18 |
bufferOut := buffer reading. |
|
19 |
100000 timesRepeat: [ bufferIn write: ''Hello World''. bufferOut read: 11 ]. |
|
20 |
buffer cacheSize |
|
21 |
}}} |
|
22 |
' |
|
23 |
! |
|
24 |
||
25 |
||
26 |
!BufferReadStream methodsFor:'accessing'! |
|
27 |
||
28 |
get |
|
29 |
^source get |
|
30 |
! |
|
31 |
||
32 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
33 |
source read: anInteger into: aSequenceableCollection at: startIndex. |
|
34 |
^anInteger |
|
35 |
! ! |
|
36 |
||
37 |
!BufferReadStream methodsFor:'initialize-release'! |
|
38 |
||
39 |
close |
|
40 |
! |
|
41 |
||
42 |
contentsSpecies |
|
43 |
^source contentsSpecies |
|
44 |
! ! |
|
45 |
||
46 |
!BufferReadStream methodsFor:'seeking'! |
|
47 |
||
48 |
++ anInteger |
|
49 |
| count | |
|
50 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ]. |
|
51 |
count := source readSkip: anInteger. |
|
52 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
53 |
^anInteger |
|
54 |
! |
|
55 |
||
56 |
-- anInteger |
|
57 |
| count | |
|
58 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ]. |
|
59 |
count := (source readSkip: anInteger negated) negated. |
|
60 |
count = anInteger ifTrue: [^anInteger]. |
|
61 |
(Incomplete count: count) raise |
|
62 |
! |
|
63 |
||
64 |
available |
|
65 |
^source readSize |
|
66 |
! |
|
67 |
||
68 |
length |
|
69 |
^source activeSize |
|
70 |
! |
|
71 |
||
72 |
position |
|
73 |
^source readPosition |
|
74 |
! |
|
75 |
||
76 |
position: aPosition |
|
77 |
| available | |
|
78 |
aPosition < 0 ifTrue: [ Incomplete zero raise ]. |
|
79 |
available := aPosition min: source activeSize. |
|
80 |
source readPosition: available. |
|
81 |
available = aPosition ifTrue: [^aPosition ]. |
|
82 |
(Incomplete count: available) raise |
|
83 |
! ! |
|
84 |
||
85 |
!BufferReadStream methodsFor:'testing'! |
|
86 |
||
87 |
isPositionable |
|
88 |
^true |
|
89 |
! ! |
|
90 |
||
91 |
!BufferReadStream class methodsFor:'documentation'! |
|
92 |
||
93 |
version_SVN |
|
94 |
^ '$Id$' |
|
95 |
! ! |