9
|
1 |
"{ Package: 'stx:goodies/xtreams/terminals' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Xtreams }"
|
|
4 |
|
|
5 |
WriteStream subclass:#BufferWriteStream
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'My Classes'
|
|
10 |
!
|
|
11 |
|
|
12 |
BufferWriteStream comment:'Write stream on a Buffer. Usually used in tandem with a read 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 ].
|
|
18 |
buffer cacheSize
|
|
19 |
}}}
|
|
20 |
'
|
|
21 |
!
|
|
22 |
|
|
23 |
|
|
24 |
!BufferWriteStream methodsFor:'accessing'!
|
|
25 |
|
|
26 |
insert: anInteger from: aSequenceableCollection at: startIndex
|
|
27 |
^destination insert: anInteger from: aSequenceableCollection at: startIndex
|
|
28 |
!
|
|
29 |
|
|
30 |
put: anObject
|
|
31 |
^destination put: anObject
|
|
32 |
!
|
|
33 |
|
|
34 |
write: anInteger from: aSequenceableCollection at: startIndex
|
|
35 |
^destination write: anInteger from: aSequenceableCollection at: startIndex
|
|
36 |
! !
|
|
37 |
|
|
38 |
!BufferWriteStream methodsFor:'initialize-release'!
|
|
39 |
|
|
40 |
close
|
|
41 |
destination close
|
|
42 |
!
|
|
43 |
|
|
44 |
contentsSpecies
|
|
45 |
^destination contentsSpecies
|
|
46 |
!
|
|
47 |
|
|
48 |
flush
|
|
49 |
! !
|
|
50 |
|
|
51 |
!BufferWriteStream methodsFor:'seeking'!
|
|
52 |
|
|
53 |
++ anInteger
|
|
54 |
| count |
|
|
55 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ].
|
|
56 |
count := destination writeSkip: anInteger.
|
|
57 |
count < anInteger ifTrue: [(Incomplete count: count) raise].
|
|
58 |
^anInteger
|
|
59 |
!
|
|
60 |
|
|
61 |
-- anInteger
|
|
62 |
| count |
|
|
63 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ].
|
|
64 |
count := (destination writeSkip: anInteger negated) negated.
|
|
65 |
count = anInteger ifTrue: [^anInteger].
|
|
66 |
(Incomplete count: count) raise
|
|
67 |
!
|
|
68 |
|
|
69 |
available
|
|
70 |
^destination writeSize
|
|
71 |
!
|
|
72 |
|
|
73 |
length
|
|
74 |
^destination activeSize
|
|
75 |
!
|
|
76 |
|
|
77 |
position
|
|
78 |
^destination writePosition
|
|
79 |
!
|
|
80 |
|
|
81 |
position: aPosition
|
|
82 |
| available |
|
|
83 |
aPosition < 0 ifTrue: [ Incomplete zero raise ].
|
|
84 |
available := aPosition min: destination activeSize.
|
|
85 |
destination writePosition: available.
|
|
86 |
available = aPosition ifTrue: [^aPosition ].
|
|
87 |
(Incomplete count: available) raise
|
|
88 |
!
|
|
89 |
|
|
90 |
skip: anInteger
|
|
91 |
| count |
|
|
92 |
count := destination writeSkip: anInteger.
|
|
93 |
count ~= anInteger ifTrue: [(Incomplete count: count) raise]
|
|
94 |
! !
|
|
95 |
|
|
96 |
!BufferWriteStream methodsFor:'testing'!
|
|
97 |
|
|
98 |
isPositionable
|
|
99 |
^true
|
|
100 |
! !
|
|
101 |
|
|
102 |
!BufferWriteStream class methodsFor:'documentation'!
|
|
103 |
|
|
104 |
version_SVN
|
|
105 |
^ '$Id$'
|
|
106 |
! !
|