substreams/Xtreams__WriteSubstream.st
author joe
Fri, 15 Mar 2013 19:54:41 -0400
changeset 113 c0df9d2ad5d3
parent 109 9587e2df7029
permissions -rw-r--r--
* make InifiniteReadingWritingTests abstract

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

"{ NameSpace: Xtreams }"

WriteStream subclass:#WriteSubstream
	instanceVariableNames:'destinationAtEnd closeBlock substreamClosed'
	classVariableNames:''
	poolDictionaries:''
	category:'Xtreams-Substreams'
!

WriteSubstream 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
	destinationAtEnd        <Boolean> flags end of the destination
	closeBlock      <BlockClosure> unary block invoked in response to #close, allows customizing closing behavior
	substreamClosed <Boolean> flags the end of the receiver

'
!


!WriteSubstream class methodsFor:'private'!

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

!WriteSubstream methodsFor:'accessing'!

closeBlock
	^closeBlock
!

closeBlock: anObject
	closeBlock := anObject
!

insert: anInteger from: aSequenceableCollection at: startIndex
	[destination insert: anInteger from: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete |
		destinationAtEnd := true.
		incomplete pass].
	^anInteger
!

put: anObject
	[destination put: anObject] on: Incomplete do: [:incomplete |
		destinationAtEnd := true.
		incomplete pass]
!

write: anInteger from: aSequenceableCollection at: startIndex
	[destination write: anInteger from: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete |
		destinationAtEnd := true.
		incomplete pass].
	^anInteger
! !

!WriteSubstream methodsFor:'initialize-release'!

close
	closeBlock cull: self.
	substreamClosed := true
!

contentsSpecies
	^destination contentsSpecies
!

on: aDestination
	super on: aDestination.
	closeBlock := [].
	destinationAtEnd := false.
	substreamClosed := false
!

subseekend
! !

!WriteSubstream methodsFor:'testing'!

destinationAtEnd
	^destinationAtEnd
!

substreamClosed
	^substreamClosed
! !

!WriteSubstream class methodsFor:'documentation'!

version_HG

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