use of com.aliyun.oss.event.ProgressInputStream 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;
}
use of com.aliyun.oss.event.ProgressInputStream in project aliyun-oss-java-sdk by aliyun.
the class ResponseProgressHandler method handle.
@Override
public void handle(ResponseMessage response) throws OSSException, ClientException {
final ProgressListener listener = this.originalRequest.getProgressListener();
Map<String, String> headers = response.getHeaders();
String s = headers.get(HttpHeaders.CONTENT_LENGTH);
if (s != null) {
try {
long contentLength = Long.parseLong(s);
publishResponseContentLength(listener, contentLength);
} catch (NumberFormatException e) {
logException("Cannot parse the Content-Length header of the response: ", e);
}
}
InputStream content = response.getContent();
if (content != null && listener != ProgressListener.NOOP) {
InputStream progressInputStream = ProgressInputStream.inputStreamForResponse(content, originalRequest);
response.setContent(progressInputStream);
}
}
use of com.aliyun.oss.event.ProgressInputStream in project aliyun-oss-java-sdk by aliyun.
the class OSSUdfOperation method getUdfApplicationLog.
public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdfApplicationLogRequest) throws OSSException, ClientException {
assertParameterNotNull(getUdfApplicationLogRequest, "resizeUdfApplicationRequest");
String udfName = getUdfApplicationLogRequest.getName();
assertParameterNotNull(udfName, "udfName");
ensureBucketNameValid(udfName);
Map<String, String> params = new HashMap<String, String>();
populateGetUdfApplicationLogParameters(params, getUdfApplicationLogRequest);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setParameters(params).setOriginalRequest(getUdfApplicationLogRequest).build();
ProgressListener listener = getUdfApplicationLogRequest.getProgressListener();
UdfApplicationLog udfApplicationLog = null;
try {
publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
udfApplicationLog = doOperation(request, new GetUdfApplicationLogResponseParser(udfName), null, null, true);
InputStream instream = udfApplicationLog.getLogContent();
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);
udfApplicationLog.setLogContent(checkedInputstream);
} catch (RuntimeException e) {
publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw e;
}
return udfApplicationLog;
}
Aggregations