in src/main/java/com/aliyun/oss/common/comm/io/ChunkedUploadStream.java [71:104]
public int read(byte[] buffer, int offset, int count) throws IOException {
if (buffer == null) {
throw new NullPointerException();
} else if (offset < 0 || count < 0 || count > buffer.length - offset) {
throw new IndexOutOfBoundsException(
String.format("buffer size: %n, offset: %n, count: %n", buffer.length, offset, count));
} else if (count == 0) {
return 0;
}
if (outputBufferPos == -1) {
if (innerStreamConsumed && isTerminatingChunk) {
return -1;
}
int bytesRead = fillInputBuffer();
constructOutputBufferChunk(bytesRead);
isTerminatingChunk = (innerStreamConsumed && bytesRead == 0);
}
int outputRemaining = outputBufferDataLen - outputBufferPos;
int bytesToRead = count;
if (outputRemaining < count) {
bytesToRead = outputRemaining;
}
System.arraycopy(outputBuffer, outputBufferPos, buffer, 0, bytesToRead);
outputBufferPos += bytesToRead;
if (outputBufferPos >= outputBufferDataLen) {
outputBufferPos = -1;
}
return bytesToRead;
}