use of com.qcloud.cos.model.GetObjectRequest in project alluxio by Alluxio.
the class COSInputStream method createStream.
@Override
protected InputStream createStream(long startPos, long endPos) throws IOException {
GetObjectRequest req = new GetObjectRequest(mBucketName, mKey);
// COS returns entire object if we read past the end
req.setRange(startPos, endPos < mContentLength ? endPos - 1 : mContentLength - 1);
CosServiceException lastException = null;
String errorMessage = String.format("Failed to open key: %s bucket: %s", mKey, mBucketName);
while (mRetryPolicy.attempt()) {
try {
COSObject object = mCosClient.getObject(req);
return new BufferedInputStream(object.getObjectContent());
} catch (CosServiceException e) {
errorMessage = String.format("Failed to open key: %s bucket: %s attempts: %d error: %s", mKey, mBucketName, mRetryPolicy.getAttemptCount(), e.getMessage());
if (e.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
throw new IOException(errorMessage, e);
}
// Key does not exist
lastException = e;
}
}
// Failed after retrying key does not exist
throw new IOException(errorMessage, lastException);
}
Aggregations