in src/main/java/software/amazon/encryption/s3/legacy/internal/RangedGetUtils.java [70:99]
public static Subscriber<? super ByteBuffer> adjustToDesiredRange(Subscriber<? super ByteBuffer> subscriber, long[] cryptoRange, String contentRange, int cipherTagLengthBits) {
if (cryptoRange == null || contentRange == null) {
return subscriber;
}
final long maxOffset = calculateMaxOffset(contentRange, cipherTagLengthBits);
if (cryptoRange[1] > maxOffset) {
cryptoRange[1] = maxOffset;
if (cryptoRange[0] > cryptoRange[1]) {
// When the beginning of the crypto range is after the max offset,
// there is no data to read. The current implementation of
// AdjustedRangeSubscriber handles this case itself,
// but this might as well be a Null/Noop Subscriber
try {
return new AdjustedRangeSubscriber(subscriber, cryptoRange[0], cryptoRange[1]);
} catch (IOException e) {
throw new S3EncryptionClientException(e.getMessage());
}
}
}
if (cryptoRange[0] > cryptoRange[1]) {
// Make no modifications if range is invalid.
return subscriber;
}
try {
return new AdjustedRangeSubscriber(subscriber, cryptoRange[0], cryptoRange[1]);
} catch (IOException e) {
throw new S3EncryptionClientException("Error adjusting output to desired byte range: " + e.getMessage());
}
}