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
This commit is contained in:
olly 2016-04-06 11:12:28 -07:00 committed by Oliver Woodman
parent 05ef643e28
commit 92ac270ce5
5 changed files with 14 additions and 12 deletions

View file

@ -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 {

View file

@ -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 {
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;
} }

View file

@ -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 {

View file

@ -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 {
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

View file

@ -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 {