Java 类com.google.android.exoplayer2.upstream.DataSourceInputStream 实例源码

项目:ExoPlayer-Offline    文件:SampleChooserActivity.java   
@Override
protected List<SampleGroup> doInBackground(String... uris) {
  List<SampleGroup> result = new ArrayList<>();
  Context context = getApplicationContext();
  String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
  DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
  for (String uri : uris) {
    DataSpec dataSpec = new DataSpec(Uri.parse(uri));
    InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
    } catch (Exception e) {
      Log.e(TAG, "Error loading sample list: " + uri, e);
      sawError = true;
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
  return result;
}
项目:ExoPlayer-Offline    文件:CustomDrmCallback.java   
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
        throws IOException {
    HttpDataSource dataSource = dataSourceFactory.createDataSource();
    if (requestProperties != null) {
        for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
            dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
        }
    }
    DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
        return Util.toByteArray(inputStream);
    } finally {
        Util.closeQuietly(inputStream);
    }
}
项目:Exoplayer2Radio    文件:HttpMediaDrmCallback.java   
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
项目:K-Sonic    文件:HttpMediaDrmCallback.java   
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
项目:videoPickPlayer    文件:HttpMediaDrmCallback.java   
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
    throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    inputStream.close();
  }
}
项目:transistor    文件:SampleChooserActivity.java   
@Override
protected List<SampleGroup> doInBackground(String... uris) {
  List<SampleGroup> result = new ArrayList<>();
  Context context = getApplicationContext();
  String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
  DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
  for (String uri : uris) {
    DataSpec dataSpec = new DataSpec(Uri.parse(uri));
    InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
    } catch (Exception e) {
      Log.e(TAG, "Error loading sample list: " + uri, e);
      sawError = true;
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
  return result;
}
项目:transistor    文件:CacheAsserts.java   
/** Asserts that the cache contains the given data for {@code uriString}. */
public static void assertDataCached(Cache cache, Uri uri, byte[] expected) throws IOException {
  CacheDataSource dataSource = new CacheDataSource(cache, DummyDataSource.INSTANCE, 0);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource,
      new DataSpec(uri, DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH));
  try {
    inputStream.open();
    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = inputStream.read(buffer)) != -1) {
      outputStream.write(buffer, 0, bytesRead);
    }
  } catch (IOException e) {
    // Ignore
  } finally {
    inputStream.close();
  }
  MoreAsserts.assertEquals("Cached data doesn't match expected for '" + uri + "',",
      expected, outputStream.toByteArray());
}
项目:transistor    文件:HttpMediaDrmCallback.java   
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
项目:transistor    文件:CacheAsserts.java   
/** Asserts that the cache contains the given data for {@code uriString}. */
public static void assertDataCached(Cache cache, Uri uri, byte[] expected) throws IOException {
  CacheDataSource dataSource = new CacheDataSource(cache, DummyDataSource.INSTANCE, 0);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource,
      new DataSpec(uri, DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH));
  try {
    inputStream.open();
    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = inputStream.read(buffer)) != -1) {
      outputStream.write(buffer, 0, bytesRead);
    }
  } catch (IOException e) {
    // Ignore
  } finally {
    inputStream.close();
  }
  assertWithMessage("Cached data doesn't match expected for '" + uri + "'")
      .that(outputStream.toByteArray()).isEqualTo(expected);
}
项目:K-Sonic    文件:DashUtil.java   
/**
 * Loads a DASH manifest.
 *
 * @param dataSource The {@link HttpDataSource} from which the manifest should be read.
 * @param manifestUriString The URI of the manifest to be read.
 * @return An instance of {@link DashManifest}.
 * @throws IOException If an error occurs reading data from the stream.
 * @see DashManifestParser
 */
public static DashManifest loadManifest(DataSource dataSource, String manifestUriString)
    throws IOException {
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource,
      new DataSpec(Uri.parse(manifestUriString), DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH));
  try {
    inputStream.open();
    DashManifestParser parser = new DashManifestParser();
    return parser.parse(dataSource.getUri(), inputStream);
  } finally {
    inputStream.close();
  }
}