Search in sources :

Example 1 with GetObjectRequest

use of com.obs.services.model.GetObjectRequest in project alluxio by Alluxio.

the class OBSInputStream method createStream.

@Override
protected InputStream createStream(long startPos, long endPos) throws IOException {
    GetObjectRequest req = new GetObjectRequest(mBucketName, mKey);
    req.setRangeStart(startPos);
    req.setRangeEnd(endPos < mContentLength ? endPos - 1 : mContentLength - 1);
    ObsException lastException = null;
    while (mRetryPolicy.attempt()) {
        try {
            ObsObject obj = mObsClient.getObject(req);
            return new BufferedInputStream(obj.getObjectContent());
        } catch (ObsException e) {
            System.out.println(e.getResponseCode());
            LOG.warn("Attempt {} to open key {} in bucket {} failed with exception : {}", mRetryPolicy.getAttemptCount(), mKey, mBucketName, e.toString());
            if (e.getResponseCode() != HttpStatus.SC_NOT_FOUND) {
                throw new IOException(e);
            }
            // Key does not exist
            lastException = e;
        }
    }
    // Failed after retrying key does not exist
    throw new IOException(lastException);
}
Also used : ObsException(com.obs.services.exception.ObsException) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) ObsObject(com.obs.services.model.ObsObject) GetObjectRequest(com.obs.services.model.GetObjectRequest)

Aggregations

ObsException (com.obs.services.exception.ObsException)1 GetObjectRequest (com.obs.services.model.GetObjectRequest)1 ObsObject (com.obs.services.model.ObsObject)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1