"{ Package: 'stx:goodies/xtreams/terminals' }"
"{ NameSpace: Xtreams }"
ReadStream subclass:#BufferReadStream
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Xtreams-Terminals'
!
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_HG
^ '$Changeset: <not expanded> $'
! !