in src/main/java/software/amazon/encryption/s3/internal/CipherSubscriber.java [102:117]
private int getAmountToReadFromByteBuffer(ByteBuffer byteBuffer) {
// If content length is null, we should include everything in the cipher because the stream is essentially
// unbounded.
if (contentLength == null) {
return byteBuffer.remaining();
}
long amountReadSoFar = contentRead.getAndAdd(byteBuffer.remaining());
long amountRemaining = Math.max(0, contentLength - amountReadSoFar);
if (amountRemaining > byteBuffer.remaining()) {
return byteBuffer.remaining();
} else {
return Math.toIntExact(amountRemaining);
}
}