|
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 /** |
|
61 * from DataSource |
|
62 * @return Content Type |
|
63 * @see DataSource |
|
64 */ |
|
65 public String getContentType() |
|
66 { |
|
67 return iDataSource.getContentType(); |
|
68 } |
|
69 |
|
70 /** |
|
71 * from DataSource |
|
72 * Connect to the stream |
|
73 * @throws IOException |
|
74 * @see DataSource |
|
75 */ |
|
76 public void connect() throws IOException |
|
77 { |
|
78 iDataSource.connect(); |
|
79 } |
|
80 |
|
81 /** |
|
82 * from DataSource |
|
83 * Disconnect from the stream |
|
84 */ |
|
85 public void disconnect() |
|
86 { |
|
87 iDataSource.disconnect(); |
|
88 } |
|
89 |
|
90 /** |
|
91 * from DataSource |
|
92 * Put DataSource to STARTED state |
|
93 * @throws IOException Throw if DataSource is in wrong state |
|
94 * @see DataSource |
|
95 */ |
|
96 public void start() throws IOException |
|
97 { |
|
98 iDataSource.start(); |
|
99 } |
|
100 |
|
101 /** |
|
102 * from DataSource |
|
103 * Stops DataSource |
|
104 * @see DataSource |
|
105 */ |
|
106 public void stop() throws IOException |
|
107 { |
|
108 iDataSource.stop(); |
|
109 } |
|
110 |
|
111 /** |
|
112 * from DataSource |
|
113 * return sourceStreams of the DataSource |
|
114 * |
|
115 * @return set of source streams |
|
116 * @see DataSource |
|
117 */ |
|
118 public SourceStream[] getStreams() |
|
119 { |
|
120 // return all streams from delegated DataSource except first |
|
121 // buffered stream. |
|
122 SourceStream[] originalStreams = iDataSource.getStreams(); |
|
123 SourceStream[] streams = new SourceStream[ originalStreams.length ]; |
|
124 System.arraycopy(originalStreams, 0, |
|
125 streams, 0, originalStreams.length); |
|
126 streams[ 0 ] = iSourceStream; |
|
127 return streams; |
|
128 } |
|
129 |
|
130 /** |
|
131 * from interface Controllable |
|
132 * Method return controls of the DataSource |
|
133 * @return Control |
|
134 * @see Controllable |
|
135 * @see DataSource |
|
136 */ |
|
137 public Control[] getControls() |
|
138 { |
|
139 return iDataSource.getControls(); |
|
140 } |
|
141 |
|
142 /** |
|
143 * from interface Controllable |
|
144 * Return a control by the Control Type, not supported |
|
145 * @param controlType type of the control |
|
146 * @return Control |
|
147 */ |
|
148 public Control getControl(String aControlType) |
|
149 { |
|
150 return iDataSource.getControl(aControlType); |
|
151 } |
|
152 |
|
153 } |
|
154 // End of File |
|
155 |