@@ -0,0 +1,2862 @@
+/*%0A * Copyright (C) 2014 The Android Open Source Project%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.google.android.exoplayer.upstream;%0A%0Aimport com.google.android.exoplayer.util.Assertions;%0A%0Aimport java.io.IOException;%0A%0A/**%0A * A data source that fetches data from a local or remote %7B@link DataSpec%7D.%0A */%0Apublic final class UriDataSource implements DataSource %7B%0A%0A  private static final String FILE_URI_SCHEME = %22file%22;%0A%0A  private final DataSource fileDataSource;%0A  private final DataSource httpDataSource;%0A%0A  /**%0A   * %7B@code null%7D if no data source is open. Otherwise, equal to %7B@link #fileDataSource%7D if the open%0A   * data source is a file, or %7B@link #httpDataSource%7D otherwise.%0A   */%0A  private DataSource dataSource;%0A%0A  /**%0A   * Constructs a new data source that delegates to a %7B@link FileDataSource%7D for file URIs and an%0A   * %7B@link HttpDataSource%7D for other URIs.%0A   *%0A   * @param userAgent The User-Agent string that should be used when requesting remote data.%0A   * @param transferListener An optional listener.%0A   */%0A  public UriDataSource(String userAgent, TransferListener transferListener) %7B%0A    this(new FileDataSource(transferListener),%0A        new HttpDataSource(userAgent, null, transferListener));%0A  %7D%0A%0A  /**%0A   * Constructs a new data source using %7B@code fileDataSource%7D for file URIs, and%0A   * %7B@code httpDataSource%7D for non-file URIs.%0A   *%0A   * @param fileDataSource %7B@link DataSource%7D to use for file URIs.%0A   * @param httpDataSource %7B@link DataSource%7D to use for non-file URIs.%0A   */%0A  public UriDataSource(DataSource fileDataSource, DataSource httpDataSource) %7B%0A    this.fileDataSource = Assertions.checkNotNull(fileDataSource);%0A    this.httpDataSource = Assertions.checkNotNull(httpDataSource);%0A  %7D%0A%0A  @Override%0A  public long open(DataSpec dataSpec) throws IOException %7B%0A    Assertions.checkState(dataSource == null);%0A%0A    dataSource = dataSpec.uri.getScheme().equals(FILE_URI_SCHEME) ? fileDataSource : httpDataSource;%0A    return dataSource.open(dataSpec);%0A  %7D%0A%0A  @Override%0A  public void close() throws IOException %7B%0A    Assertions.checkNotNull(dataSource);%0A%0A    dataSource.close();%0A    dataSource = null;%0A  %7D%0A%0A  @Override%0A  public int read(byte%5B%5D buffer, int offset, int readLength) throws IOException %7B%0A    Assertions.checkNotNull(dataSource);%0A%0A    return dataSource.read(buffer, offset, readLength);%0A  %7D%0A%0A%7D%0A

Add a UriDataSource for reading from file or network.