use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class UploadCallable method uploadPartsInSeries.
/**
* Uploads all parts in the request in serial in this thread, then completes the upload and
* returns the result.
*/
private UploadResult uploadPartsInSeries(UploadPartRequestFactory requestFactory) {
final List<PartETag> partETags = new ArrayList<PartETag>();
while (requestFactory.hasMoreRequests()) {
if (threadPool.isShutdown())
throw new CancellationException("TransferManager has been shutdown");
UploadPartRequest uploadPartRequest = requestFactory.getNextUploadPartRequest();
// Mark the stream in case we need to reset it
InputStream inputStream = uploadPartRequest.getInputStream();
if (inputStream != null && inputStream.markSupported()) {
if (uploadPartRequest.getPartSize() >= Integer.MAX_VALUE) {
inputStream.mark(Integer.MAX_VALUE);
} else {
inputStream.mark((int) uploadPartRequest.getPartSize());
}
}
partETags.add(cos.uploadPart(uploadPartRequest).getPartETag());
}
CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest(origReq.getBucketName(), origReq.getKey(), multipartUploadId, partETags).withGeneralProgressListener(origReq.getGeneralProgressListener());
ObjectMetadata origMeta = origReq.getMetadata();
if (origMeta != null) {
ObjectMetadata objMeta = req.getObjectMetadata();
if (objMeta == null) {
objMeta = new ObjectMetadata();
}
objMeta.setUserMetadata(origMeta.getUserMetadata());
req.setObjectMetadata(objMeta);
}
if (origReq.getPicOperations() != null) {
req.setPicOperations(origReq.getPicOperations());
}
TransferManagerUtils.populateEndpointAddr(origReq, req);
CompleteMultipartUploadResult res = cos.completeMultipartUpload(req);
UploadResult uploadResult = new UploadResult();
uploadResult.setBucketName(res.getBucketName());
uploadResult.setKey(res.getKey());
uploadResult.setETag(res.getETag());
uploadResult.setVersionId(res.getVersionId());
uploadResult.setRequestId(res.getRequestId());
uploadResult.setDateStr(res.getDateStr());
uploadResult.setCrc64Ecma(res.getCrc64Ecma());
uploadResult.setCiUploadResult(res.getCiUploadResult());
return uploadResult;
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testPutObjectWithContentType.
@Test
public void testPutObjectWithContentType() throws IOException {
ObjectMetadata originObjectMeta = new ObjectMetadata();
originObjectMeta.setContentType("image/tiff");
testPutObjectByStreamDiffSize(0L, originObjectMeta);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testPutObjectWithServerSideEncryption.
@Test
public void testPutObjectWithServerSideEncryption() throws IOException {
useServerEncryption = true;
ObjectMetadata originObjectMeta = new ObjectMetadata();
originObjectMeta.setServerSideEncryption("AES256");
testPutObjectByStreamDiffSize(1L, originObjectMeta);
useServerEncryption = false;
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class TransferManager method doDownload.
/**
* Same as public interface, but adds a state listener so that callers can be notified of state
* changes to the download.
*
* @see TransferManager#download(GetObjectRequest, File)
*/
private Download doDownload(final GetObjectRequest getObjectRequest, final File file, final TransferStateChangeListener stateListener, final COSProgressListener cosProgressListener, final boolean resumeExistingDownload) {
appendSingleObjectUserAgent(getObjectRequest);
String description = "Downloading from " + getObjectRequest.getBucketName() + "/" + getObjectRequest.getKey();
TransferProgress transferProgress = new TransferProgress();
// COS progress listener to capture the persistable transfer when available
COSProgressListenerChain listenerChain = new COSProgressListenerChain(// The listener for updating transfer progress
new TransferProgressUpdatingListener(transferProgress), getObjectRequest.getGeneralProgressListener(), // Listeners
cosProgressListener);
// included in
// the original
// request
// The listener chain used by the low-level GetObject request.
// This listener chain ignores any COMPLETE event, so that we could
// delay firing the signal until the high-level download fully finishes.
getObjectRequest.setGeneralProgressListener(new ProgressListenerChain(new TransferCompletionFilter(), listenerChain));
long startingByte = 0;
long lastByte;
long[] range = getObjectRequest.getRange();
if (range != null && range.length == 2) {
startingByte = range[0];
lastByte = range[1];
} else {
GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest(getObjectRequest.getBucketName(), getObjectRequest.getKey());
if (getObjectRequest.getSSECustomerKey() != null)
getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey());
if (getObjectRequest.getVersionId() != null)
getObjectMetadataRequest.setVersionId(getObjectRequest.getVersionId());
final ObjectMetadata objectMetadata = cos.getObjectMetadata(getObjectMetadataRequest);
lastByte = objectMetadata.getContentLength() - 1;
}
final long origStartingByte = startingByte;
// We still pass the unfiltered listener chain into DownloadImpl
final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, null, stateListener, getObjectRequest, file);
long totalBytesToDownload = lastByte - startingByte + 1;
transferProgress.setTotalBytesToTransfer(totalBytesToDownload);
long fileLength = -1;
if (resumeExistingDownload) {
if (!FileLocks.lock(file)) {
throw new FileLockException("Fail to lock " + file + " for resume download");
}
try {
if (file.exists()) {
fileLength = file.length();
startingByte = startingByte + fileLength;
getObjectRequest.setRange(startingByte, lastByte);
transferProgress.updateProgress(Math.min(fileLength, totalBytesToDownload));
totalBytesToDownload = lastByte - startingByte + 1;
if (log.isDebugEnabled()) {
log.debug("Resume download: totalBytesToDownload=" + totalBytesToDownload + ", origStartingByte=" + origStartingByte + ", startingByte=" + startingByte + ", lastByte=" + lastByte + ", numberOfBytesRead=" + fileLength + ", file: " + file);
}
}
} finally {
FileLocks.unlock(file);
}
}
if (totalBytesToDownload < 0) {
throw new IllegalArgumentException("Unable to determine the range for download operation.");
}
final CountDownLatch latch = new CountDownLatch(1);
Future<?> future = threadPool.submit(new DownloadCallable(cos, latch, getObjectRequest, resumeExistingDownload, download, file, origStartingByte, fileLength));
download.setMonitor(new DownloadMonitor(download, future));
latch.countDown();
return download;
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class CompleteMultipartCopy method call.
@Override
public CopyResult call() throws Exception {
CompleteMultipartUploadResult res;
try {
CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest(origReq.getDestinationBucketName(), origReq.getDestinationKey(), uploadId, collectPartETags()).withGeneralProgressListener(origReq.getGeneralProgressListener());
ObjectMetadata origMeta = origReq.getNewObjectMetadata();
if (origMeta != null) {
ObjectMetadata objMeta = req.getObjectMetadata();
if (objMeta == null) {
objMeta = new ObjectMetadata();
}
objMeta.setUserMetadata(origMeta.getUserMetadata());
req.setObjectMetadata(objMeta);
}
TransferManagerUtils.populateEndpointAddr(origReq, req);
res = cos.completeMultipartUpload(req);
} catch (Exception e) {
publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw e;
}
CopyResult copyResult = new CopyResult();
copyResult.setSourceBucketName(origReq.getSourceBucketName());
copyResult.setSourceKey(origReq.getSourceKey());
copyResult.setDestinationBucketName(res.getBucketName());
copyResult.setDestinationKey(res.getKey());
copyResult.setETag(res.getETag());
copyResult.setVersionId(res.getVersionId());
copyResult.setRequestId(res.getRequestId());
copyResult.setDateStr(res.getDateStr());
copyResult.setCrc64Ecma(res.getCrc64Ecma());
monitor.copyComplete();
return copyResult;
}
Aggregations