in genie-common-internal/src/main/java/com/netflix/genie/common/internal/aws/s3/SimpleStorageRangeResource.java [91:142]
public InputStream getInputStream() throws IOException {
if (!this.exists()) {
throw new FileNotFoundException("No such object: " + this.bucket + "/" + key);
}
// Index of first and last byte to fetch (inclusive)
final long rangeStart;
final long rangeEnd;
if (this.range.getLeft() == null && this.range.getRight() == null) {
// Full object
rangeStart = 0;
rangeEnd = Math.max(0, this.contentLength - 1);
} else if (this.range.getLeft() == null && this.range.getRight() != null) {
// Object suffix
rangeStart = Math.max(0, this.contentLength - this.range.getRight());
rangeEnd = Math.max(0, this.contentLength - 1);
} else if (this.range.getLeft() != null && this.range.getRight() == null) {
// From offset to end
rangeStart = this.range.getLeft();
rangeEnd = Math.max(0, this.contentLength - 1);
} else {
// Range start and end are provided
rangeStart = this.range.getLeft();
rangeEnd = Math.min(this.range.getRight(), this.contentLength - 1);
}
log.debug(
"Resource {}/{} requested range: {}-{}, actual range: {}-{}",
this.bucket,
this.key,
this.range.getLeft(),
this.range.getRight(),
rangeStart,
rangeEnd
);
final long skipBytes = Math.max(0, rangeStart);
final InputStream inputStream;
if (rangeEnd - rangeStart < 0 || (rangeEnd == 0 && rangeStart == 0)) {
inputStream = new EmptyInputStream();
} else {
final GetObjectRequest getObjectRequest = new GetObjectRequest(this.bucket, this.key)
.withRange(rangeStart, rangeEnd)
.withVersionId(this.versionId);
inputStream = this.client.getObject(getObjectRequest).getObjectContent();
}
return new SkipInputStream(skipBytes, inputStream);
}