terminals/Xtreams__ExternalWriteStream.st
author mkobetic
Sun, 15 Jan 2012 02:18:17 +0000
changeset 39 80fdc4602b14
parent 25 02e7c3b6f63c
child 43 b9a077d6ce14
permissions -rw-r--r--
sockets and files

'From Smalltalk/X, Version:6.2.1 on 14-01-2012 at 09:10:27 PM'                  !

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

"{ NameSpace: Xtreams }"

WriteStream subclass:#ExternalWriteStream
	instanceVariableNames:'contentsSpecies'
	classVariableNames:''
	poolDictionaries:''
	category:'Xtreams-Terminals'
!

ExternalWriteStream comment:'Used to write to BlockableIOAccessors (e.g sockets or pipes). This is a binary stream (consumes bytes/ByteArrays).

{{{
	[ :in :out |
		[	out writing write: ''Hello''; close.
			in reading read: 5
		] ensure: [ in close. out close ]
	] valueWithArguments: SocketAccessor openPair
}}}
{{{
	[ :in :out |
		[	out writing write: ''Hello''; close.
			in reading read: 5
		] ensure: [ in close. out close ]
	] valueWithArguments: OSSystemSupport concreteClass pipeAccessorClass openPair
}}}

Instance Variables
	contentsSpecies	<Class> species for collections of elements of this stream

'
!


!ExternalWriteStream methodsFor:'accessing'!

write: anInteger from: aSequenceableCollection at: startIndex
        | count wrote |
        anInteger isZero ifTrue: [^0].
        count := 0.
        [count < anInteger] whileTrue:
                [wrote := destination nextPutBytes: anInteger - count from: aSequenceableCollection startingAt: startIndex + count.
                wrote isZero ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise].
                count := count + wrote].
        ^anInteger
! !

!ExternalWriteStream methodsFor:'initialize-release'!

close
	destination isActive ifFalse: [^self].
	destination close
!

contentsSpecies
	^contentsSpecies
!

contentsSpecies: aClass
	contentsSpecies := aClass
!

on: anAccessor
	super on: anAccessor.
	contentsSpecies := ByteArray
! !

!ExternalWriteStream class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !