javauis/mmapi_qt/baseline/javasrc.emc/com/nokia/microedition/media/BufferDataSource.java
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Buffered DataSource
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.microedition.media;
       
    20 
       
    21 import javax.microedition.media.Control;
       
    22 import javax.microedition.media.protocol.DataSource;
       
    23 import javax.microedition.media.protocol.SourceStream;
       
    24 import java.io.IOException;
       
    25 
       
    26 /**
       
    27  * BufferDataSource is used to read header from DataSource's SourceStream.
       
    28  * This class delegates all method calls to DataSource given in constructor
       
    29  * except getStream method which returns buffered SourceStream.
       
    30  */
       
    31 public class BufferDataSource extends DataSource
       
    32 {
       
    33     // delegated source
       
    34     protected DataSource iDataSource;
       
    35 
       
    36     // buffers DataSource's first stream.
       
    37     protected BufferSourceStream iSourceStream;
       
    38 
       
    39     /**
       
    40      * Constructor.
       
    41      * @param aDataSource delegated DataSource
       
    42      */
       
    43     public BufferDataSource(DataSource aDataSource) throws IOException
       
    44     {
       
    45         super(aDataSource.getLocator());
       
    46         iDataSource = aDataSource;
       
    47         SourceStream ss = aDataSource.getStreams()[ 0 ];
       
    48         iSourceStream = new BufferSourceStream(ss);
       
    49     }
       
    50 
       
    51     /**
       
    52      * Return header data.
       
    53      * @return header data
       
    54      */
       
    55     public byte[] getHeader() throws IOException
       
    56     {
       
    57         return iSourceStream.getHeader();
       
    58     }
       
    59 
       
    60     public int readAndBuffer(byte[] aBuffer, int aOffset, int aLength) throws IOException
       
    61     {
       
    62         return iSourceStream.readAndBuffer(aBuffer, aOffset, aLength);
       
    63     }
       
    64 
       
    65     /**
       
    66      * from DataSource
       
    67      * @return Content Type
       
    68      * @see DataSource
       
    69      */
       
    70     public String getContentType()
       
    71     {
       
    72         return iDataSource.getContentType();
       
    73     }
       
    74 
       
    75     /**
       
    76      * from DataSource
       
    77      * Connect to the stream
       
    78      * @throws IOException
       
    79      * @see DataSource
       
    80      */
       
    81     public void connect() throws IOException
       
    82     {
       
    83         iDataSource.connect();
       
    84     }
       
    85 
       
    86     /**
       
    87      * from DataSource
       
    88      * Disconnect from the stream
       
    89      */
       
    90     public void disconnect()
       
    91     {
       
    92         iDataSource.disconnect();
       
    93     }
       
    94 
       
    95     /**
       
    96      * from DataSource
       
    97      * Put DataSource to STARTED state
       
    98      * @throws IOException Throw if DataSource is in wrong state
       
    99      * @see DataSource
       
   100      */
       
   101     public void start() throws IOException
       
   102     {
       
   103         iDataSource.start();
       
   104     }
       
   105 
       
   106     /**
       
   107      * from DataSource
       
   108      * Stops DataSource
       
   109      * @see DataSource
       
   110      */
       
   111     public void stop() throws IOException
       
   112     {
       
   113         iDataSource.stop();
       
   114     }
       
   115 
       
   116     /**
       
   117      * from DataSource
       
   118      * return sourceStreams of the DataSource
       
   119      *
       
   120      * @return set of source streams
       
   121      * @see DataSource
       
   122      */
       
   123     public SourceStream[] getStreams()
       
   124     {
       
   125         // return all streams from delegated DataSource except first
       
   126         // buffered stream.
       
   127         SourceStream[] originalStreams = iDataSource.getStreams();
       
   128         SourceStream[] streams = new SourceStream[ originalStreams.length ];
       
   129         System.arraycopy(originalStreams, 0,
       
   130                          streams, 0, originalStreams.length);
       
   131         streams[ 0 ] = iSourceStream;
       
   132         return streams;
       
   133     }
       
   134 
       
   135     /**
       
   136      * from interface Controllable
       
   137      * Method return controls of the DataSource
       
   138      * @return Control
       
   139      * @see Controllable
       
   140      * @see DataSource
       
   141      */
       
   142     public Control[] getControls()
       
   143     {
       
   144         return iDataSource.getControls();
       
   145     }
       
   146 
       
   147     /**
       
   148      * from interface Controllable
       
   149      * Return a control by the Control Type, not supported
       
   150      * @param controlType type of the control
       
   151      * @return Control
       
   152      */
       
   153     public Control getControl(String aControlType)
       
   154     {
       
   155         return iDataSource.getControl(aControlType);
       
   156     }
       
   157     /**
       
   158      * @author d35kumar
       
   159      * @return
       
   160      */
       
   161     public DataSource getDataSource(){
       
   162     	return iDataSource;
       
   163     }
       
   164     
       
   165 }
       
   166 // End of File
       
   167