use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testGetObjectIfNoneMatchWrongEtag.
@Test
public void testGetObjectIfNoneMatchWrongEtag() throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File localFile = buildTestFile(1024);
String key = "ut/" + localFile.getName();
cosclient.putObject(bucket, key, localFile);
try {
String fileEtag = Md5Utils.md5Hex(localFile);
String wrongEtag = fileEtag.substring(5) + fileEtag.substring(0, 5);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
List<String> eTagList = new ArrayList<>();
eTagList.add("\"" + wrongEtag + "\"");
getObjectRequest.setNonmatchingETagConstraints(eTagList);
COSObject cosObject = cosclient.getObject(getObjectRequest);
assertNotNull(cosObject);
} catch (CosServiceException cse) {
fail(cse.toString());
} finally {
cosclient.deleteObject(bucket, key);
assertTrue(localFile.delete());
}
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testGetObjectIfMatchRightEtag.
@Test
public void testGetObjectIfMatchRightEtag() throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File localFile = buildTestFile(1024);
String key = "ut/" + localFile.getName();
cosclient.putObject(bucket, key, localFile);
try {
String fileEtag = Md5Utils.md5Hex(localFile);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
List<String> eTagList = new ArrayList<>();
eTagList.add("\"" + fileEtag + "\"");
getObjectRequest.setMatchingETagConstraints(eTagList);
COSObject cosObject = cosclient.getObject(getObjectRequest);
assertNotNull(cosObject);
} catch (CosServiceException cse) {
fail(cse.toString());
} finally {
cosclient.deleteObject(bucket, key);
assertTrue(localFile.delete());
}
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class ResumableDownloadSubmitter method submit.
public void submit() throws Exception {
long contentLength = Long.parseLong(downloadRecord.getContentLength());
download.setState(TransferState.InProgress);
if (contentLength < this.multiThreadThreshold) {
throw new CosClientException("contentLenth " + contentLength + " < " + this.multiThreadThreshold + " should not use resumabledownload.");
}
long start = 0;
publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
while (contentLength > start) {
long bytesToRead = Math.min(partSize, contentLength - start);
long end = start + bytesToRead - 1;
String block = String.format("%d-%d", start, end);
if (downloadRecord.hasDownloadedBlocks(block)) {
log.debug("part found in download record: " + block);
CRC64 crc64 = new CRC64();
byte[] buffer = new byte[1024 * 10];
int readBytes;
destRandomAccessFile.seek(start);
while (bytesToRead > 0 && (readBytes = destRandomAccessFile.read(buffer)) != -1) {
long updateBytes = Math.min(readBytes, bytesToRead);
bytesToRead -= updateBytes;
crc64.update(buffer, (int) updateBytes);
}
skippedParts.add(new DownloadPart(start, end, crc64.getValue()));
transferProgress.updateProgress(end + 1 - start);
} else {
GetObjectRequest getObj = copyGetObjectRequest(req);
getObj.setRange(start, end);
if (threadPool.isShutdown()) {
publishProgress(listener, ProgressEventType.TRANSFER_CANCELED_EVENT);
throw new CancellationException("TransferManager has been shutdown");
}
futures.add(threadPool.submit(new RangeDownloadCallable(cos, getObj, destFile, destFileChannel, downloadRecord)));
}
start = end + 1;
}
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class ResumableDownloadSubmitter method copyGetObjectRequest.
GetObjectRequest copyGetObjectRequest(GetObjectRequest origin) {
GetObjectRequest dst = new GetObjectRequest(origin.getCOSObjectId());
dst.setCosCredentials(origin.getCosCredentials());
dst.setFixedEndpointAddr(origin.getFixedEndpointAddr());
dst.setGeneralProgressListener(origin.getGeneralProgressListener());
dst.setMatchingETagConstraints(origin.getMatchingETagConstraints());
dst.setModifiedSinceConstraint(origin.getModifiedSinceConstraint());
dst.setNonmatchingETagConstraints(origin.getNonmatchingETagConstraints());
dst.setResponseHeaders(origin.getResponseHeaders());
dst.setSSECustomerKey(origin.getSSECustomerKey());
dst.setTrafficLimit(origin.getTrafficLimit());
dst.setUnmodifiedSinceConstraint(origin.getUnmodifiedSinceConstraint());
return dst;
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class SymmetricKeyEncryptionClientDemo method getObjectDemo.
static void getObjectDemo() {
// 下载文件
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
File downloadFile = new File("downSym.txt");
ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
System.out.println(objectMetadata.getRequestId());
}
Aggregations