Commit 92ac270c by olly Committed by Oliver Woodman

Return C constant rather than -1, as documented.

Note that the DataSourceInputStream read methods
are implementing a different interface (InputStream,
not DataSource), which is why -1 is still used in
that case.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119180851
parent 05ef643e
...@@ -108,7 +108,7 @@ public final class AssetDataSource implements DataSource { ...@@ -108,7 +108,7 @@ public final class AssetDataSource implements DataSource {
@Override @Override
public int read(byte[] buffer, int offset, int readLength) throws AssetDataSourceException { public int read(byte[] buffer, int offset, int readLength) throws AssetDataSourceException {
if (bytesRemaining == 0) { if (bytesRemaining == 0) {
return -1; return C.RESULT_END_OF_INPUT;
} else { } else {
int bytesRead = 0; int bytesRead = 0;
try { try {
......
...@@ -31,7 +31,7 @@ public final class ByteArrayDataSource implements DataSource { ...@@ -31,7 +31,7 @@ public final class ByteArrayDataSource implements DataSource {
private Uri uri; private Uri uri;
private int readPosition; private int readPosition;
private int remainingBytes; private int bytesRemaining;
/** /**
* @param data The data to be read. * @param data The data to be read.
...@@ -46,24 +46,24 @@ public final class ByteArrayDataSource implements DataSource { ...@@ -46,24 +46,24 @@ public final class ByteArrayDataSource implements DataSource {
public long open(DataSpec dataSpec) throws IOException { public long open(DataSpec dataSpec) throws IOException {
uri = dataSpec.uri; uri = dataSpec.uri;
readPosition = (int) dataSpec.position; readPosition = (int) dataSpec.position;
remainingBytes = (int) ((dataSpec.length == C.LENGTH_UNBOUNDED) bytesRemaining = (int) ((dataSpec.length == C.LENGTH_UNBOUNDED)
? (data.length - dataSpec.position) : dataSpec.length); ? (data.length - dataSpec.position) : dataSpec.length);
if (remainingBytes <= 0 || readPosition + remainingBytes > data.length) { if (bytesRemaining <= 0 || readPosition + bytesRemaining > data.length) {
throw new IOException("Unsatisfiable range: [" + readPosition + ", " + dataSpec.length throw new IOException("Unsatisfiable range: [" + readPosition + ", " + dataSpec.length
+ "], length: " + data.length); + "], length: " + data.length);
} }
return remainingBytes; return bytesRemaining;
} }
@Override @Override
public int read(byte[] buffer, int offset, int length) throws IOException { public int read(byte[] buffer, int offset, int length) throws IOException {
if (remainingBytes == 0) { if (bytesRemaining == 0) {
return -1; return C.RESULT_END_OF_INPUT;
} }
length = Math.min(length, remainingBytes); length = Math.min(length, bytesRemaining);
System.arraycopy(data, readPosition, buffer, offset, length); System.arraycopy(data, readPosition, buffer, offset, length);
readPosition += length; readPosition += length;
remainingBytes -= length; bytesRemaining -= length;
return length; return length;
} }
......
...@@ -106,7 +106,7 @@ public final class ContentDataSource implements DataSource { ...@@ -106,7 +106,7 @@ public final class ContentDataSource implements DataSource {
@Override @Override
public int read(byte[] buffer, int offset, int readLength) throws ContentDataSourceException { public int read(byte[] buffer, int offset, int readLength) throws ContentDataSourceException {
if (bytesRemaining == 0) { if (bytesRemaining == 0) {
return -1; return C.RESULT_END_OF_INPUT;
} else { } else {
int bytesRead = 0; int bytesRead = 0;
try { try {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.upstream; package com.google.android.exoplayer.upstream;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import java.io.IOException; import java.io.IOException;
...@@ -74,7 +75,8 @@ public final class DataSourceInputStream extends InputStream { ...@@ -74,7 +75,8 @@ public final class DataSourceInputStream extends InputStream {
public int read(byte[] buffer, int offset, int length) throws IOException { public int read(byte[] buffer, int offset, int length) throws IOException {
Assertions.checkState(!closed); Assertions.checkState(!closed);
checkOpened(); checkOpened();
return dataSource.read(buffer, offset, length); int bytesRead = dataSource.read(buffer, offset, length);
return bytesRead == C.RESULT_END_OF_INPUT ? -1 : bytesRead;
} }
@Override @Override
......
...@@ -88,7 +88,7 @@ public final class FileDataSource implements DataSource { ...@@ -88,7 +88,7 @@ public final class FileDataSource implements DataSource {
@Override @Override
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException { public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
if (bytesRemaining == 0) { if (bytesRemaining == 0) {
return -1; return C.RESULT_END_OF_INPUT;
} else { } else {
int bytesRead = 0; int bytesRead = 0;
try { try {
......
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