substreams/Xtreams__ReadSubstream.st
author Martin Kobetic
Sun, 17 Nov 2013 00:02:08 -0500
changeset 131 871b930fcf3d
parent 109 9587e2df7029
permissions -rw-r--r--
- stx_goodies_xtreams_support class: stx_goodies_xtreams_support added: #legalCopyright

"{ Package: 'stx:goodies/xtreams/substreams' }"

"{ NameSpace: Xtreams }"

ReadStream subclass:#ReadSubstream
	instanceVariableNames:'sourceAtEnd closeBlock substreamClosed'
	classVariableNames:''
	poolDictionaries:''
	category:'Xtreams-Substreams'
!

ReadSubstream comment:'This is abstract superclass of all substreams. Substreams normally don''t close their underlying source, their closing behavior is customized via closeBlock.

Instance Variables
	sourceAtEnd     <Boolean> flags end of the source
	closeBlock      <BlockClosure> unary block invoked in response to #close, allows customizing closing behavior
	substreamClosed <Boolean> flags the end of the receiver

'
!


!ReadSubstream class methodsFor:'private'!

slice: sliceBlock close: closeBlock
	| substream |
	substream := nil.
	^[substream == nil ifFalse:
		[substream substreamClosed ifFalse: [substream close].
		substream subseekend.
		substream sourceAtEnd ifTrue: [Incomplete zero raise]].
	substream := sliceBlock value]
		reading
			closeBlock: closeBlock;
			yourself
! !

!ReadSubstream methodsFor:'accessing'!

closeBlock
	^closeBlock
!

closeBlock: anObject
	closeBlock := anObject
!

get
	^[source get] on: Incomplete do: [:incomplete | sourceAtEnd := true. incomplete pass]
!

read: anInteger into: aSequenceableCollection at: startIndex
	^[source read: anInteger into: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete | sourceAtEnd := true. incomplete pass]
! !

!ReadSubstream methodsFor:'initialize-release'!

close
	closeBlock cull: self.
	substreamClosed := true
!

contentsSpecies
	^source contentsSpecies
!

on: aSource
	super on: aSource.
	closeBlock := [].
	sourceAtEnd := false.
	substreamClosed := false
!

subseekend
! !

!ReadSubstream methodsFor:'testing'!

sourceAtEnd
	^sourceAtEnd
!

substreamClosed
	^substreamClosed
! !

!ReadSubstream class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !