substreams/Xtreams__WriteSubstream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 01 Feb 2012 00:56:17 +0000
changeset 103 726bf2ca0b99
parent 67 a87e5ce04545
child 109 9587e2df7029
permissions -rw-r--r--
Removed methods from FileHandle to make it compilable. Having methods there is not a good idea anyway.

"{ 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_SVN
    ^ '$Id$'
! !