Search in sources :

Example 1 with GetObjectRequest

use of com.aliyun.oss.model.GetObjectRequest in project alluxio by Alluxio.

the class OSSInputStream method createStream.

@Override
protected InputStream createStream(long startPos, long endPos) throws IOException {
    GetObjectRequest req = new GetObjectRequest(mBucketName, mKey);
    // OSS returns entire object if we read past the end
    req.setRange(startPos, endPos < mContentLength ? endPos - 1 : mContentLength - 1);
    OSSObject ossObject = mOssClient.getObject(req);
    return new BufferedInputStream(ossObject.getObjectContent());
}
Also used : OSSObject(com.aliyun.oss.model.OSSObject) BufferedInputStream(java.io.BufferedInputStream) GetObjectRequest(com.aliyun.oss.model.GetObjectRequest)

Example 2 with GetObjectRequest

use of com.aliyun.oss.model.GetObjectRequest in project hadoop by apache.

the class AliyunOSSFileSystemStore method retrieve.

/**
   * Retrieve a part of an object.
   *
   * @param key the object name that is being retrieved from the Aliyun OSS.
   * @param byteStart start position.
   * @param byteEnd end position.
   * @return This method returns null if the key is not found.
   */
public InputStream retrieve(String key, long byteStart, long byteEnd) {
    try {
        GetObjectRequest request = new GetObjectRequest(bucketName, key);
        request.setRange(byteStart, byteEnd);
        return ossClient.getObject(request).getObjectContent();
    } catch (OSSException | ClientException e) {
        return null;
    }
}
Also used : OSSException(com.aliyun.oss.OSSException) ClientException(com.aliyun.oss.ClientException) GetObjectRequest(com.aliyun.oss.model.GetObjectRequest)

Aggregations

GetObjectRequest (com.aliyun.oss.model.GetObjectRequest)2 ClientException (com.aliyun.oss.ClientException)1 OSSException (com.aliyun.oss.OSSException)1 OSSObject (com.aliyun.oss.model.OSSObject)1 BufferedInputStream (java.io.BufferedInputStream)1