diff --git a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java index 0d741b583d..216d4bbbf7 100644 --- a/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java +++ b/extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java @@ -180,8 +180,6 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { @Nullable private Response response; @Nullable private InputStream responseByteStream; private boolean opened; - - private long bytesSkipped; private long bytesToRead; private long bytesRead; @@ -275,7 +273,6 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { public long open(DataSpec dataSpec) throws HttpDataSourceException { this.dataSpec = dataSpec; this.bytesRead = 0; - this.bytesSkipped = 0; transferInitializing(dataSpec); Request request = makeRequest(dataSpec); @@ -372,38 +369,6 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { } } - /** - * Returns the number of bytes that were skipped during the most recent call to {@link - * #open(DataSpec)}. - * - * @return The number of bytes skipped. - */ - protected final long bytesSkipped() { - return bytesSkipped; - } - - /** - * Returns the number of bytes that have been read since the most recent call to - * {@link #open(DataSpec)}. - * - * @return The number of bytes read. - */ - protected final long bytesRead() { - return bytesRead; - } - - /** - * Returns the number of bytes that are still to be read for the current {@link DataSpec}. - *
- * If the total length of the data being read is known, then this length minus {@code bytesRead()} - * is returned. If the total length is unknown, {@link C#LENGTH_UNSET} is returned. - * - * @return The remaining length, or {@link C#LENGTH_UNSET}. - */ - protected final long bytesRemaining() { - return bytesToRead == C.LENGTH_UNSET ? bytesToRead : bytesToRead - bytesRead; - } - /** Establishes a connection. */ private Request makeRequest(DataSpec dataSpec) throws HttpDataSourceException { long position = dataSpec.position; @@ -471,8 +436,8 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { return true; } byte[] skipBuffer = new byte[4096]; - while (bytesSkipped != bytesToSkip) { - int readLength = (int) min(bytesToSkip - bytesSkipped, skipBuffer.length); + while (bytesToSkip > 0) { + int readLength = (int) min(bytesToSkip, skipBuffer.length); int read = castNonNull(responseByteStream).read(skipBuffer, 0, readLength); if (Thread.currentThread().isInterrupted()) { throw new InterruptedIOException(); @@ -480,7 +445,7 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource { if (read == -1) { return false; } - bytesSkipped += read; + bytesToSkip -= read; bytesTransferred(read); } return true; diff --git a/library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java b/library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java index e7df4c0599..e184a34408 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java @@ -222,8 +222,6 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou @Nullable private InputStream inputStream; private boolean opened; private int responseCode; - - private long bytesSkipped; private long bytesToRead; private long bytesRead; @@ -338,7 +336,6 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou public long open(DataSpec dataSpec) throws HttpDataSourceException { this.dataSpec = dataSpec; this.bytesRead = 0; - this.bytesSkipped = 0; transferInitializing(dataSpec); try { @@ -455,7 +452,9 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou try { @Nullable InputStream inputStream = this.inputStream; if (inputStream != null) { - maybeTerminateInputStream(connection, bytesRemaining()); + long bytesRemaining = + bytesToRead == C.LENGTH_UNSET ? C.LENGTH_UNSET : bytesToRead - bytesRead; + maybeTerminateInputStream(connection, bytesRemaining); try { inputStream.close(); } catch (IOException e) { @@ -473,48 +472,6 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou } } - /** - * Returns the current connection, or null if the source is not currently opened. - * - * @return The current open connection, or null. - */ - @Nullable - protected final HttpURLConnection getConnection() { - return connection; - } - - /** - * Returns the number of bytes that were skipped during the most recent call to {@link - * #open(DataSpec)}. - * - * @return The number of bytes skipped. - */ - protected final long bytesSkipped() { - return bytesSkipped; - } - - /** - * Returns the number of bytes that have been read since the most recent call to - * {@link #open(DataSpec)}. - * - * @return The number of bytes read. - */ - protected final long bytesRead() { - return bytesRead; - } - - /** - * Returns the number of bytes that are still to be read for the current {@link DataSpec}. - *
- * If the total length of the data being read is known, then this length minus {@code bytesRead()} - * is returned. If the total length is unknown, {@link C#LENGTH_UNSET} is returned. - * - * @return The remaining length, or {@link C#LENGTH_UNSET}. - */ - protected final long bytesRemaining() { - return bytesToRead == C.LENGTH_UNSET ? bytesToRead : bytesToRead - bytesRead; - } - /** * Establishes a connection, following redirects to do so where permitted. */ @@ -742,8 +699,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou return true; } byte[] skipBuffer = new byte[4096]; - while (bytesSkipped != bytesToSkip) { - int readLength = (int) min(bytesToSkip - bytesSkipped, skipBuffer.length); + while (bytesToSkip > 0) { + int readLength = (int) min(bytesToSkip, skipBuffer.length); int read = castNonNull(inputStream).read(skipBuffer, 0, readLength); if (Thread.currentThread().isInterrupted()) { throw new InterruptedIOException(); @@ -751,7 +708,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou if (read == -1) { return false; } - bytesSkipped += read; + bytesToSkip -= read; bytesTransferred(read); } return true;