FileDocCategorySizeDatePackage
SourceStream.javaAPI DocphoneME MR2 API (J2ME)7619Wed May 02 16:47:16 BST 2007javax.microedition.media.protocol

SourceStream

public interface SourceStream implements javax.microedition.media.Controllable
Abstracts a single stream of media data. It is used in conjunction with DataSource to provide the input interface to a Player

SourceStream may provide type-specific controls. For that reason, it implements the Controllable interface to provide additional controls.

see
DataSource

Fields Summary
int
NOT_SEEKABLE
The value returned by getSeekType indicating that this SourceStream is not seekable.

Value 0 is assigned to NOT_SEEKABLE.

int
SEEKABLE_TO_START
The value returned by getSeekType indicating that this SourceStream can be seeked only to the beginning of the media stream.

Value 1 is assigned to SEEKABLE_TO_START.

int
RANDOM_ACCESSIBLE
The value returned by getSeekType indicating that this SourceStream can be seeked anywhere within the media.

Value 2 is assigned to RANDOM_ACCESSIBLE.

Constructors Summary
Methods Summary
public ContentDescriptorgetContentDescriptor()
Get the content type for this stream.

return
The current ContentDescriptor for this stream.

public longgetContentLength()
Get the size in bytes of the content on this stream.

return
The content length in bytes. -1 is returned if the length is not known.

public intgetSeekType()
Find out if the stream is seekable. The return value can be one of these three: NOT_SEEKABLE, SEEKABLE_TO_START and RANDOM_ACCESSIBLE. If the return value is SEEKABLE_TO_START, it means that the stream can only be repositioned to the beginning of the stream. If the return value is RANDOM_ACCESSIBLE, the stream can be seeked anywhere within the stream.

return
Returns an enumerated value to indicate the level of seekability.

public intgetTransferSize()
Get the size of a "logical" chunk of media data from the source. This method can be used to determine the minimum size of the buffer to use in conjunction with the read method to read data from the source.

return
The minimum size of the buffer needed to read a "logical" chunk of data from the source. Returns -1 if the size cannot be determined.
see
#read(byte[], int, int)

public intread(byte[] b, int off, int len)
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

If the first byte cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.

param
b the buffer into which the data is read.
param
off the start offset in array b at which the data is written.
param
len the maximum number of bytes to read.
return
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
exception
IOException if an I/O error occurs.

public longseek(long where)
Seek to the specified point in the stream. The seek method may, for a variety of reasons, fail to seek to the specified position. For example, it may be asked to seek to a position beyond the size of the stream; or the stream may only be seekable to the beginning (getSeekType returns SEEKABLE_TO_START). The return value indicates whether the seeking is successful. If it is successful, the value returned will be the same as the given position. Otherwise, the return value will indicate what the new position is.

If the given position is negative, seek will treat that as 0 and attempt to seek to 0.

An IOException will be thrown if an I/O error occurs, e.g. when the stream comes from a remote connection and the connection is broken.

param
where The position to seek to.
return
The new stream position.
exception
IOException Thrown if an I/O error occurs.

public longtell()
Obtain the current position in the stream.

return
The current position in the stream.