Use is subject to License Terms. Your use of this web site or any of its contents or software indicates your agreement to be bound by these License Terms.

Copyright © 2002-2006 Sun Microsystems, Inc.; Nokia Corporation. All rights reserved. See the Copyright Notice and Specification License for more details.

MMAPI 1.2

javax.microedition.media.protocol
Interface SourceStream

All Superinterfaces:
Controllable

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.

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 content 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

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

Value 0 is assigned to NOT_SEEKABLE.

See Also:
Constant Field Values

SEEKABLE_TO_START

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.

See Also:
Constant Field Values

RANDOM_ACCESSIBLE

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

See Also:
Constant Field Values
Method Detail

getContentDescriptor

ContentDescriptor getContentDescriptor()
Get the content type for this stream.

Returns:
The current ContentDescriptor for this stream.

getContentLength

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.

read

int read(byte[] b,
         int off,
         int len)
         throws java.io.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 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.

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:
java.io.IOException - if an I/O error occurs.

getTransferSize

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.
See Also:
read(byte[], int, int)

seek

long seek(long where)
          throws java.io.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 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.

Parameters:
where - The position to seek to.
Returns:
The new stream position.
Throws:
java.io.IOException - Thrown if an I/O error occurs.

tell

long tell()
Obtain the current position in the stream.

Returns:
The current position in the stream.

getSeekType

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.

MMAPI 1.2

Copyright © 2002-2006 Sun Microsystems, Inc.; Nokia Corporation. All rights reserved. See the Copyright Notice and Specification License for more details.

Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 135 specification.