javax.microedition.media.protocol
Interface SourceStream

All Superinterfaces:
Controllable
All Known Implementing Classes:
ByteArrayInputStreamDataSource

public interface SourceStream
extends 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.

Since:
JDE 4.0.0
See Also:
DataSource

Field Summary
static int NOT_SEEKABLE
          The value returned by getSeekType indicating that this SourceStream is not seekable.
static int RANDOM_ACCESSIBLE
          The value returned by getSeekType indicating that this SourceStream can be seeked anywhere within the media.
static int SEEKABLE_TO_START
          The value returned by getSeekType indicating that this SourceStream can be seeked only to the beginning of the media stream.
 
Method Summary
 ContentDescriptor getContentDescriptor()
          Get the current type for this stream.
 long getContentLength()
          Get the size in bytes of the content on this stream.
 int getSeekType()
          Find out if the stream is seekable.
 int getTransferSize()
          Get the size of a "logical" chunk of media data from the source.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 long seek(long where)
          Seek to the specified point in the stream.
 long tell()
          Obtain the current position in the stream.
 
Methods inherited from interface javax.microedition.media.Controllable
getControl, getControls
 

Field Detail

NOT_SEEKABLE

public static final int NOT_SEEKABLE
The value returned by getSeekType indicating that this SourceStream is not seekable.

Value 0 is assigned to NOT_SEEKABLE.

Since:
JDE 4.0.0

RANDOM_ACCESSIBLE

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

Value 2 is assinged to RANDOM_ACCESSIBLE.

Since:
JDE 4.0.0

SEEKABLE_TO_START

public static final 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.

Since:
JDE 4.0.0
Method Detail

getContentDescriptor

public ContentDescriptor getContentDescriptor()
Get the current type for this stream.
Returns:
The current ContentDescriptor for this stream.
Since:
JDE 4.0.0

getContentLength

public long getContentLength()
Get the size in bytes of the content on this stream.
Returns:
The content length in bytes. -1 is returned if the length is not known.
Since:
JDE 4.0.0

getSeekType

public int getSeekType()
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.
Returns:
Returns an enumerated value to indicate the level of seekability.
Since:
JDE 4.0.0

getTransferSize

public int getTransferSize()
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.
Returns:
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.
Since:
JDE 4.0.0
See Also:
read(byte[], int, int)

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
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 the end of the 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.

Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
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.
Throws:
IOException - if an I/O error occurs.
Since:
JDE 4.0.0

seek

public long seek(long where)
          throws IOException
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 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.

Parameters:
where - The position to seek to.
Returns:
The new stream position.
Since:
JDE 4.0.0

tell

public long tell()
Obtain the current position in the stream.
Returns:
The current position in the stream.
Since:
JDE 4.0.0



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.