mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +00:00
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:
parent
05ef643e28
commit
92ac270ce5
5 changed files with 14 additions and 12 deletions
|
|
@ -108,7 +108,7 @@ public final class AssetDataSource implements DataSource {
|
|||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws AssetDataSourceException {
|
||||
if (bytesRemaining == 0) {
|
||||
return -1;
|
||||
return C.RESULT_END_OF_INPUT;
|
||||
} else {
|
||||
int bytesRead = 0;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public final class ByteArrayDataSource implements DataSource {
|
|||
|
||||
private Uri uri;
|
||||
private int readPosition;
|
||||
private int remainingBytes;
|
||||
private int bytesRemaining;
|
||||
|
||||
/**
|
||||
* @param data The data to be read.
|
||||
|
|
@ -46,24 +46,24 @@ public final class ByteArrayDataSource implements DataSource {
|
|||
public long open(DataSpec dataSpec) throws IOException {
|
||||
uri = dataSpec.uri;
|
||||
readPosition = (int) dataSpec.position;
|
||||
remainingBytes = (int) ((dataSpec.length == C.LENGTH_UNBOUNDED)
|
||||
bytesRemaining = (int) ((dataSpec.length == C.LENGTH_UNBOUNDED)
|
||||
? (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
|
||||
+ "], length: " + data.length);
|
||||
}
|
||||
return remainingBytes;
|
||||
return bytesRemaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int length) throws IOException {
|
||||
if (remainingBytes == 0) {
|
||||
return -1;
|
||||
if (bytesRemaining == 0) {
|
||||
return C.RESULT_END_OF_INPUT;
|
||||
}
|
||||
length = Math.min(length, remainingBytes);
|
||||
length = Math.min(length, bytesRemaining);
|
||||
System.arraycopy(data, readPosition, buffer, offset, length);
|
||||
readPosition += length;
|
||||
remainingBytes -= length;
|
||||
bytesRemaining -= length;
|
||||
return length;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public final class ContentDataSource implements DataSource {
|
|||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws ContentDataSourceException {
|
||||
if (bytesRemaining == 0) {
|
||||
return -1;
|
||||
return C.RESULT_END_OF_INPUT;
|
||||
} else {
|
||||
int bytesRead = 0;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer.upstream;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
||||
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 {
|
||||
Assertions.checkState(!closed);
|
||||
checkOpened();
|
||||
return dataSource.read(buffer, offset, length);
|
||||
int bytesRead = dataSource.read(buffer, offset, length);
|
||||
return bytesRead == C.RESULT_END_OF_INPUT ? -1 : bytesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public final class FileDataSource implements DataSource {
|
|||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
|
||||
if (bytesRemaining == 0) {
|
||||
return -1;
|
||||
return C.RESULT_END_OF_INPUT;
|
||||
} else {
|
||||
int bytesRead = 0;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue