use of com.aliyun.oss.internal.ResponseParsers.GetObjectResponseParser in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method getObject.
/**
* Pull an object from oss.
*/
public OSSObject getObject(GetObjectRequest getObjectRequest) throws OSSException, ClientException {
assertParameterNotNull(getObjectRequest, "getObjectRequest");
String bucketName = null;
String key = null;
RequestMessage request = null;
if (!getObjectRequest.isUseUrlSignature()) {
assertParameterNotNull(getObjectRequest, "getObjectRequest");
bucketName = getObjectRequest.getBucketName();
key = getObjectRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
assertParameterNotNull(key, "key");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(key);
Map<String, String> headers = new HashMap<String, String>();
populateGetObjectRequestHeaders(getObjectRequest, headers);
Map<String, String> params = new HashMap<String, String>();
populateResponseHeaderParameters(params, getObjectRequest.getResponseHeaders());
String process = getObjectRequest.getProcess();
if (process != null) {
params.put(RequestParameters.SUBRESOURCE_PROCESS, process);
}
request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setKey(key).setHeaders(headers).setParameters(params).setOriginalRequest(getObjectRequest).build();
} else {
request = new RequestMessage(getObjectRequest, bucketName, key);
request.setMethod(HttpMethod.GET);
request.setAbsoluteUrl(getObjectRequest.getAbsoluteUri());
request.setUseUrlSignature(true);
request.setHeaders(getObjectRequest.getHeaders());
}
final ProgressListener listener = getObjectRequest.getProgressListener();
OSSObject ossObject = null;
try {
publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
ossObject = doOperation(request, new GetObjectResponseParser(bucketName, key), bucketName, key, true);
InputStream instream = ossObject.getObjectContent();
ProgressInputStream progressInputStream = new ProgressInputStream(instream, listener) {
@Override
protected void onEOF() {
publishProgress(getListener(), ProgressEventType.TRANSFER_COMPLETED_EVENT);
}
};
CRC64 crc = new CRC64();
CheckedInputStream checkedInputstream = new CheckedInputStream(progressInputStream, crc);
ossObject.setObjectContent(checkedInputstream);
} catch (RuntimeException e) {
publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw e;
}
return ossObject;
}
Aggregations