Search in sources :

Example 1 with ObsObject

use of com.obs.services.model.ObsObject in project simpleFS by shengdingbox.

the class HuaweiCloudOssApiClient method downloadFileStream.

@Override
public InputStream downloadFileStream(String key) {
    ObsObject obsObject = obsClient.getObject(bucket, key);
    System.out.println("Object content:");
    return obsObject.getObjectContent();
}
Also used : ObsObject(com.obs.services.model.ObsObject)

Example 2 with ObsObject

use of com.obs.services.model.ObsObject in project onex-boot by zhangchaoxu.

the class HuaweiCloudOssService method download.

@Override
public InputStream download(String objectKey) {
    ObsClient ossClient = null;
    ObsObject ossObject = null;
    try {
        ossClient = new ObsClient(config.getAccessKeyId(), config.getAccessKeySecret(), config.getEndPoint());
        ossObject = ossClient.getObject(config.getBucketName(), objectKey);
        return ossObject.getObjectContent();
    } catch (ObsException e) {
        throw new OnexException(ErrorCode.OSS_UPLOAD_FILE_ERROR, e);
    } finally {
        // ObsClient在调用ObsClient.close方法关闭后不能再次使用
        if (ossClient != null) {
            try {
                ossClient.close();
            } catch (IOException e) {
                log.error("huaweicloud obs client close error", e);
            }
        }
    }
}
Also used : OnexException(com.nb6868.onex.common.exception.OnexException) ObsException(com.obs.services.exception.ObsException) ObsObject(com.obs.services.model.ObsObject) ObsClient(com.obs.services.ObsClient)

Example 3 with ObsObject

use of com.obs.services.model.ObsObject 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

ObsObject (com.obs.services.model.ObsObject)3 ObsException (com.obs.services.exception.ObsException)2 OnexException (com.nb6868.onex.common.exception.OnexException)1 ObsClient (com.obs.services.ObsClient)1 GetObjectRequest (com.obs.services.model.GetObjectRequest)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1