--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/terminals/Xtreams__BufferReadStream.st Mon Aug 22 16:04:00 2011 +0000
@@ -0,0 +1,93 @@
+"{ Package: 'stx:goodies/xtreams/terminals' }"
+
+"{ NameSpace: Xtreams }"
+
+ReadStream subclass:#BufferReadStream
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'My Classes'
+!
+
+BufferReadStream comment:'Read stream on a Buffer. Usually used in tandem with a write stream to access buffer contents conveniently.
+{{{
+ buffer := ElasticBuffer on: String new.
+ bufferIn := buffer writing.
+ bufferOut := buffer reading.
+ 100000 timesRepeat: [ bufferIn write: ''Hello World''. bufferOut read: 11 ].
+ buffer cacheSize
+}}}
+'
+!
+
+
+!BufferReadStream methodsFor:'accessing'!
+
+get
+ ^source get
+!
+
+read: anInteger into: aSequenceableCollection at: startIndex
+ source read: anInteger into: aSequenceableCollection at: startIndex.
+ ^anInteger
+! !
+
+!BufferReadStream methodsFor:'initialize-release'!
+
+close
+!
+
+contentsSpecies
+ ^source contentsSpecies
+! !
+
+!BufferReadStream methodsFor:'seeking'!
+
+++ anInteger
+ | count |
+ anInteger < 0 ifTrue: [ ^self -- anInteger negated ].
+ count := source readSkip: anInteger.
+ count < anInteger ifTrue: [(Incomplete count: count) raise].
+ ^anInteger
+!
+
+-- anInteger
+ | count |
+ anInteger < 0 ifTrue: [ ^self ++ anInteger negated ].
+ count := (source readSkip: anInteger negated) negated.
+ count = anInteger ifTrue: [^anInteger].
+ (Incomplete count: count) raise
+!
+
+available
+ ^source readSize
+!
+
+length
+ ^source activeSize
+!
+
+position
+ ^source readPosition
+!
+
+position: aPosition
+ | available |
+ aPosition < 0 ifTrue: [ Incomplete zero raise ].
+ available := aPosition min: source activeSize.
+ source readPosition: available.
+ available = aPosition ifTrue: [^aPosition ].
+ (Incomplete count: available) raise
+! !
+
+!BufferReadStream methodsFor:'testing'!
+
+isPositionable
+ ^true
+! !
+
+!BufferReadStream class methodsFor:'documentation'!
+
+version_SVN
+ ^ '$Id$'
+! !