use of com.qcloud.cos.model.COSObject in project cos-java-sdk-v5 by tencentyun.
the class DownloadTaskImpl method getCOSObjectStream.
@Override
public COSObject getCOSObjectStream() {
COSObject cosObject = cos.getObject(getObjectRequest);
download.setCosObject(cosObject);
return cosObject;
}
use of com.qcloud.cos.model.COSObject in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method putInstructionFileSecurely.
@Override
public final PutObjectResult putInstructionFileSecurely(PutInstructionFileRequest req) {
final COSObjectId id = req.getCOSObjectId();
final GetObjectRequest getreq = new GetObjectRequest(id);
// Get the object from cos
final COSObject retrieved = cos.getObject(getreq);
// We only need the meta-data already retrieved, not the data stream.
// So close it immediately to prevent resource leakage.
IOUtils.closeQuietly(retrieved, log);
if (retrieved == null) {
throw new IllegalArgumentException("The specified COS object (" + id + ") doesn't exist.");
}
COSObjectWrapper wrapped = new COSObjectWrapper(retrieved, id);
try {
final ContentCryptoMaterial origCCM = contentCryptoMaterialOf(wrapped);
securityCheck(origCCM, wrapped);
// Re-ecnrypt the CEK in a new content crypto material
final EncryptionMaterials newKEK = req.getEncryptionMaterials();
final ContentCryptoMaterial newCCM;
if (newKEK == null) {
newCCM = origCCM.recreate(req.getMaterialsDescription(), this.kekMaterialsProvider, cryptoScheme, cryptoConfig.getCryptoProvider(), kms, req);
} else {
newCCM = origCCM.recreate(newKEK, this.kekMaterialsProvider, cryptoScheme, cryptoConfig.getCryptoProvider(), kms, req);
}
PutObjectRequest putInstFileRequest = req.createPutObjectRequest(retrieved);
// Put the new instruction file into COS
return cos.putObject(updateInstructionPutRequest(putInstFileRequest, newCCM));
} catch (RuntimeException ex) {
// If we're unable to set up the decryption, make sure we close the
// HTTP connection
IOUtils.closeQuietly(retrieved, log);
throw ex;
} catch (Error error) {
IOUtils.closeQuietly(retrieved, log);
throw error;
}
}
use of com.qcloud.cos.model.COSObject in project jeesuite-libs by vakinge.
the class QcloudProvider method getObjectInputStream.
@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
try {
String _bucketName = buildBucketName(bucketName);
String _fileKey = resolveFileKey(bucketName, fileKey);
COSObject cosObject = cosclient.getObject(_bucketName, _fileKey);
return cosObject.getObjectContent();
} catch (Exception e) {
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
}
use of com.qcloud.cos.model.COSObject in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method retrieve.
/**
* @param key The key is the object name that is being retrieved from the
* cos bucket.
* @return This method returns null if the key is not found.
* @throws IOException Retrieve the specified cos key with a specified byte range start failed.
*/
@Override
public InputStream retrieve(String key, long byteRangeStart) throws IOException {
try {
LOG.debug("Retrieve the cos key: {}, byte range start: {}.", key, byteRangeStart);
long fileSize = getFileLength(key);
long byteRangeEnd = fileSize - 1;
GetObjectRequest getObjectRequest = new GetObjectRequest(this.bucketName, key);
if (this.trafficLimit >= 0) {
getObjectRequest.setTrafficLimit(this.trafficLimit);
}
this.setEncryptionMetadata(getObjectRequest, new ObjectMetadata());
if (byteRangeEnd >= byteRangeStart) {
getObjectRequest.setRange(byteRangeStart, fileSize - 1);
}
COSObject cosObject = (COSObject) callCOSClientWithRetry(getObjectRequest);
return cosObject.getObjectContent();
} catch (Exception e) {
String errMsg = String.format("Retrieving key [%s] with byteRangeStart [%d] " + "occurs an exception: %s.", key, byteRangeStart, e);
handleException(new Exception(errMsg), key);
// never will get here
return null;
}
}
use of com.qcloud.cos.model.COSObject in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method retrieveBlock.
@Override
public InputStream retrieveBlock(String key, long byteRangeStart, long byteRangeEnd) throws IOException {
LOG.debug("Retrieve the cos key: {}, byte range start: {}, byte range end: {}.", key, byteRangeStart, byteRangeEnd);
try {
GetObjectRequest request = new GetObjectRequest(this.bucketName, key);
request.setRange(byteRangeStart, byteRangeEnd);
if (this.trafficLimit >= 0) {
request.setTrafficLimit(this.trafficLimit);
}
this.setEncryptionMetadata(request, new ObjectMetadata());
COSObject cosObject = (COSObject) this.callCOSClientWithRetry(request);
return cosObject.getObjectContent();
} catch (CosServiceException e) {
String errMsg = String.format("Retrieving the key %s with the byteRangeStart [%d] " + "occurs an exception: %s.", key, byteRangeStart, e);
handleException(new Exception(errMsg), key);
} catch (CosClientException e) {
String errMsg = String.format("Retrieving key %s with the byteRangeStart [%d] and the byteRangeEnd [%d] " + "occurs an exception: %s.", key, byteRangeStart, byteRangeEnd, e);
handleException(new Exception(errMsg), key);
}
return null;
}
Aggregations