use of com.qcloud.cos.exception.CosClientException in project cos-java-sdk-v5 by tencentyun.
the class ResumableDownloadMonitor method call.
@Override
public File call() throws Exception {
downloadSubmitter.submit();
futures.addAll(downloadSubmitter.getFutures());
List<DownloadPart> downloadParts = new ArrayList<DownloadPart>();
downloadParts.addAll(downloadSubmitter.getSkippedParts());
try {
for (Future<DownloadPart> future : futures) {
try {
downloadParts.add(future.get());
} catch (Exception e) {
throw new CosClientException("range download got exception: " + e.getCause().getMessage() + e.getMessage());
}
}
// download finished.
downloadRecord.getDumpFile().delete();
destFileChannel.close();
if ((downloadRecord.getCrc64ecma() != null) && !downloadRecord.getCrc64ecma().isEmpty()) {
checkCRC(downloadParts);
}
downloadComplete();
return destFile;
} catch (CancellationException e) {
transfer.setState(TransferState.Canceled);
publishProgress(listener, ProgressEventType.TRANSFER_CANCELED_EVENT);
throw new CosClientException("Download canceled");
} catch (Exception e) {
downloadFailed();
throw e;
}
}
use of com.qcloud.cos.exception.CosClientException 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.exception.CosClientException in project cos-java-sdk-v5 by tencentyun.
the class CopyMonitor method call.
@Override
public CopyResult call() throws Exception {
try {
CopyResult result = multipartCopyCallable.call();
if (result == null) {
futures.addAll(multipartCopyCallable.getFutures());
futureReference.set(threadPool.submit(new CompleteMultipartCopy(multipartCopyCallable.getMultipartUploadId(), cos, origReq, futures, listener, this)));
} else {
copyComplete();
}
return result;
} catch (CancellationException e) {
transfer.setState(TransferState.Canceled);
publishProgress(listener, ProgressEventType.TRANSFER_CANCELED_EVENT);
throw new CosClientException("Upload canceled");
} catch (Exception e) {
transfer.setState(TransferState.Failed);
publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw e;
}
}
use of com.qcloud.cos.exception.CosClientException in project cos-java-sdk-v5 by tencentyun.
the class AclXmlFactory method convertToXmlByteArray.
/**
* Converts the specified AccessControlList object to an XML fragment that can be sent to COS.
*
* @param acl The AccessControlList to convert to XML.
*
* @return an XML representation of the Access Control List object, suitable to send in a
* request to COS.
*/
public byte[] convertToXmlByteArray(AccessControlList acl) throws CosClientException {
Owner owner = acl.getOwner();
if (owner == null) {
throw new CosClientException("Invalid AccessControlList: missing an COS Owner");
}
XmlWriter xml = new XmlWriter();
xml.start("AccessControlPolicy");
xml.start("Owner");
if (owner.getId() != null) {
xml.start("ID").value(owner.getId()).end();
}
if (owner.getDisplayName() != null) {
xml.start("DisplayName").value(owner.getDisplayName()).end();
}
xml.end();
xml.start("AccessControlList");
for (Grant grant : acl.getGrantsAsList()) {
xml.start("Grant");
convertToXml(grant.getGrantee(), xml);
xml.start("Permission").value(grant.getPermission().toString()).end();
xml.end();
}
xml.end();
xml.end();
return xml.getBytes();
}
use of com.qcloud.cos.exception.CosClientException in project cos-java-sdk-v5 by tencentyun.
the class Message method validateMessageCrc.
private static void validateMessageCrc(ByteBuffer buf, int totalLength) {
Checksum crc = new CRC32();
Checksums.update(crc, (ByteBuffer) buf.duplicate().limit(buf.position() + totalLength - 4));
long computedMessageCrc = crc.getValue();
long wireMessageCrc = Utils.toUnsignedLong(buf.getInt(buf.position() + totalLength - 4));
if (wireMessageCrc != computedMessageCrc) {
throw new CosClientException(new CRC32MismatchException(format("Message checksum failure: expected 0x%x, computed 0x%x", wireMessageCrc, computedMessageCrc)));
}
}
Aggregations