FileDocCategorySizeDatePackage
InputSourceStream.javaAPI DocJMF 2.1.1e3043Mon May 12 12:20:42 BST 2003javax.media.protocol

InputSourceStream

public class InputSourceStream extends Object implements PullSourceStream
Build a source stream out of an input stream.
see
DataSource
see
SourceStream
see
java.io.InputStream
version
1.3, 02/08/21.

Fields Summary
protected InputStream
stream
protected boolean
eosReached
ContentDescriptor
contentType
Constructors Summary
public InputSourceStream(InputStream s, ContentDescriptor type)
Construct an InputSourceStream from an input stream.

param
s The input stream to build the source stream from.
param
type The content-type of the source stream.

	stream = s;
	eosReached = false;
	contentType = type;
    
Methods Summary
public voidclose()
Turn the stream off.

exception
IOException Thrown if there is a problem closing the stream.

	stream.close();
    
public booleanendOfStream()
Return if the end of stream has been reached.

return
true if the end of the stream has been reached.

	return eosReached;
    
public javax.media.protocol.ContentDescriptorgetContentDescriptor()
Get the content type for this stream.

return
content descriptor for the stream.

	return contentType;
    
public longgetContentLength()
Obtain the content length

return
content length for this stream.

	 return SourceStream.LENGTH_UNKNOWN;
     
public java.lang.ObjectgetControl(java.lang.String controlName)
Returns null because no controls are implemented.

return
null.

	return null;
    
public java.lang.Object[]getControls()
Returns an zero length array because no controls are supported.

return
a zero length Object array.

	return new Object[0];
    
public intread(byte[] buffer, int offset, int length)
Read a buffer of data.

param
buffer The buffer to read data into.
param
offset The offset into the buffer for reading.
param
length The number of bytes to read.
return
The number of bytes read or -1 indicating end-of-stream.

	int bytesRead = stream.read(buffer, offset, length);
	if( bytesRead == -1) {
	    eosReached = true;
	}
	return bytesRead;
    
public booleanwillReadBlock()
Query if the next read will block.

return
true if a read will block.

	if( eosReached == true) {
	    return true;
	} else {
	    try {
		return stream.available() == 0;
	    } catch (IOException e) {
		return true;
	    }
	}