Class BufferStreamAdapter<T extends javax.media.protocol.SourceStream>

  • Type Parameters:
    T - the very type of SourceStream to be adapted by a BufferStreamAdapter
    All Implemented Interfaces:
    javax.media.Controls, javax.media.protocol.Controls, javax.media.protocol.SourceStream
    Direct Known Subclasses:
    PullBufferStreamAdapter, PushBufferStreamAdapter

    public abstract class BufferStreamAdapter<T extends javax.media.protocol.SourceStream>
    extends Object
    implements javax.media.protocol.SourceStream
    Represents a base class for adapters of SourceStreams, usually ones reading data in arrays of bytes and not in Buffers, to SourceStreams reading data in Buffers. An example use is creating a PushBufferStream representation of a PushSourceStream.
    Author:
    Lyubomir Marinov
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected T stream
      The SourceStream being adapted by this instance.
      • Fields inherited from interface javax.media.protocol.SourceStream

        LENGTH_UNKNOWN
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferStreamAdapter​(T stream, javax.media.Format format)
      Initializes a new BufferStreamAdapter which is to adapt a specific SourceStream into a SourceStream with a specific Format.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract int doRead​(javax.media.Buffer buffer, byte[] data, int offset, int length)
      Reads byte data from this stream into a specific array of bytes starting the storing at a specific offset and reading at most a specific number of bytes.
      boolean endOfStream()
      Implements SourceStream#endOfStream().
      javax.media.protocol.ContentDescriptor getContentDescriptor()
      Implements SourceStream#getContentDescriptor().
      long getContentLength()
      Implements SourceStream#getContentLength().
      Object getControl​(String controlType)
      Implements Controls#getControl(String).
      Object[] getControls()
      Implements Controls#getControls().
      javax.media.Format getFormat()
      Gets the Format of the data this stream provides.
      T getStream()
      Gets the SourceStream wrapped by this instance.
      protected void read​(javax.media.Buffer buffer, byte[] data, int offset, int length)
      Reads byte data from this stream into a specific Buffer which is to use a specific array of bytes for its data.
    • Field Detail

      • stream

        protected final T extends javax.media.protocol.SourceStream stream
        The SourceStream being adapted by this instance.
    • Constructor Detail

      • BufferStreamAdapter

        public BufferStreamAdapter​(T stream,
                                   javax.media.Format format)
        Initializes a new BufferStreamAdapter which is to adapt a specific SourceStream into a SourceStream with a specific Format.
        Parameters:
        stream - the SourceStream to be adapted
        format - the specific Format of the SourceStream
    • Method Detail

      • endOfStream

        public boolean endOfStream()
        Implements SourceStream#endOfStream(). Delegates to the wrapped SourceStream.
        Specified by:
        endOfStream in interface javax.media.protocol.SourceStream
        Returns:
        true if the stream is finished, false otherwise
      • getContentDescriptor

        public javax.media.protocol.ContentDescriptor getContentDescriptor()
        Implements SourceStream#getContentDescriptor(). Delegates to the wrapped SourceStream.
        Specified by:
        getContentDescriptor in interface javax.media.protocol.SourceStream
        Returns:
        the ContentDescriptor of the stream
      • getContentLength

        public long getContentLength()
        Implements SourceStream#getContentLength(). Delegates to the wrapped SourceStream.
        Specified by:
        getContentLength in interface javax.media.protocol.SourceStream
        Returns:
        content length
      • getControl

        public Object getControl​(String controlType)
        Implements Controls#getControl(String). Delegates to the wrapped SourceStream.
        Specified by:
        getControl in interface javax.media.Controls
        Parameters:
        controlType - a String value naming the type of the control of this instance to be retrieved
        Returns:
        an Object which represents the control of this instance with the specified type
      • getControls

        public Object[] getControls()
        Implements Controls#getControls(). Delegates to the wrapped SourceStream.
        Specified by:
        getControls in interface javax.media.Controls
        Returns:
        array of JMF Control objects
      • getFormat

        public javax.media.Format getFormat()
        Gets the Format of the data this stream provides.
        Returns:
        the Format of the data this stream provides
      • getStream

        public T getStream()
        Gets the SourceStream wrapped by this instance.
        Returns:
        the SourceStream wrapped by this instance
      • read

        protected void read​(javax.media.Buffer buffer,
                            byte[] data,
                            int offset,
                            int length)
                     throws IOException
        Reads byte data from this stream into a specific Buffer which is to use a specific array of bytes for its data.
        Parameters:
        buffer - the Buffer to read byte data into from this instance
        data - the array of bytes to read data into from this instance and to be set as the data of the specified buffer
        Throws:
        IOException - if I/O related errors occurred during read operation
      • doRead

        protected abstract int doRead​(javax.media.Buffer buffer,
                                      byte[] data,
                                      int offset,
                                      int length)
                               throws IOException
        Reads byte data from this stream into a specific array of bytes starting the storing at a specific offset and reading at most a specific number of bytes.
        Parameters:
        buffer - an optional Buffer instance associated with the specified data, offset and length and provided to the method in case the implementation would like to provide additional Buffer properties such as flags
        data - the array of bytes into which the data read from this stream is to be written
        offset - the offset in the specified data at which writing data read from this stream should start
        length - the maximum number of bytes to be written into the specified data
        Returns:
        the number of bytes read from this stream and written into the specified data
        Throws:
        IOException - if I/O related errors occurred during read operation