Commit 5ea7424e by Oliver Woodman

Tidy up AssetDataSource.

parent 053e5b9f
......@@ -15,15 +15,13 @@
*/
package com.google.android.exoplayer.upstream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import com.google.android.exoplayer.C;
import android.content.res.AssetManager;
import android.util.Log;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.upstream.FileDataSource.FileDataSourceException;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/**
* A local asset {@link DataSource}.
......@@ -41,10 +39,10 @@ public final class AssetDataSource implements DataSource {
}
private final AssetManager assetManager;
private final TransferListener listener;
private InputStream assetInputStream;
private AssetManager assetManager;
private long bytesRemaining;
private boolean opened;
......@@ -69,7 +67,8 @@ public final class AssetDataSource implements DataSource {
public long open(DataSpec dataSpec) throws AssetDataSourceException {
try {
// Lose the '/' prefix in the path or else AssetManager won't find our file
assetInputStream = assetManager.open(dataSpec.uri.getPath().substring(1), AssetManager.ACCESS_RANDOM);
assetInputStream = assetManager.open(dataSpec.uri.getPath().substring(1),
AssetManager.ACCESS_RANDOM);
assetInputStream.skip(dataSpec.position);
bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? assetInputStream.available()
: dataSpec.length;
......@@ -94,7 +93,8 @@ public final class AssetDataSource implements DataSource {
} else {
int bytesRead = 0;
try {
bytesRead = assetInputStream.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
bytesRead = assetInputStream.read(buffer, offset,
(int) Math.min(bytesRemaining, readLength));
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
......@@ -119,7 +119,6 @@ public final class AssetDataSource implements DataSource {
throw new AssetDataSourceException(e);
} finally {
assetInputStream = null;
if (opened) {
opened = false;
if (listener != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment