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 |
WriteStream subclass:#BufferedWriteStream |
|
8 |
instanceVariableNames:'buffer' |
|
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 |
BufferedWriteStream comment:'Wraps a stream and buffers output to it based on the size of the ring-buffer it has. This is useful for doing "burst" writing, where you know exactly when you can flush the stream. To force the buffer to the underlying stream, use #flush. |
|
15 |
||
16 |
Instance Variables |
|
17 |
buffer <RingBuffer> a fixed size RingBuffer to buffer up output, released when it is full or #flush/#close is sent. |
|
18 |
||
19 |
' |
|
20 |
! |
|
21 |
||
22 |
||
23 |
!BufferedWriteStream class methodsFor:'instance creation'! |
|
24 |
||
25 |
on: aDestination bufferSize: bufferSize |
|
26 |
^self new on: aDestination bufferSize: bufferSize |
|
27 |
! ! |
|
28 |
||
29 |
!BufferedWriteStream methodsFor:'accessing'! |
|
30 |
||
31 |
write: anInteger from: aSequenceableCollection at: startIndex |
|
32 |
||
33 |
| count amount | |
|
34 |
count := 0. |
|
35 |
[[amount := buffer write: (buffer writeSize min: (anInteger - count)) from: aSequenceableCollection at: startIndex + count. |
|
36 |
count := count + amount. |
|
37 |
count < anInteger] whileTrue: [self flush]] |
|
38 |
on: Incomplete do: [:exception | (Incomplete on: aSequenceableCollection count: count + exception count at: startIndex) raise]. |
|
39 |
^anInteger |
|
40 |
! ! |
|
41 |
||
42 |
!BufferedWriteStream methodsFor:'initialize-release'! |
|
43 |
||
44 |
close |
|
45 |
super close. |
|
46 |
buffer recycle. |
|
47 |
buffer := nil |
|
48 |
! |
|
49 |
||
50 |
contentsSpecies |
|
51 |
^destination contentsSpecies |
|
52 |
! |
|
53 |
||
54 |
flush |
|
55 |
destination write: buffer |
|
56 |
! |
|
57 |
||
58 |
on: aDestination bufferSize: bufferSize |
|
59 |
buffer := RingBuffer new: bufferSize class: aDestination contentsSpecies. |
|
60 |
super on: aDestination |
|
61 |
! ! |
|
62 |
||
63 |
!BufferedWriteStream methodsFor:'printing'! |
|
64 |
||
65 |
streamingPrintOn: aStream |
|
66 |
super streamingPrintOn: aStream. |
|
67 |
aStream |
|
68 |
write: ' buffered: '; |
|
69 |
print: buffer writeSize. |
|
70 |
buffer writeSize isZero ifTrue: [^self]. |
|
71 |
aStream |
|
72 |
cr; tab; |
|
73 |
print: buffer contentsPast |
|
74 |
! ! |
|
75 |
||
76 |
!BufferedWriteStream class methodsFor:'documentation'! |
|
77 |
||
78 |
version_SVN |
|
79 |
^ '$Id$' |
|
80 |
! ! |