當前位置: 首頁>>代碼示例>>Java>>正文


Java COSObject類代碼示例

本文整理匯總了Java中com.qcloud.cos.model.COSObject的典型用法代碼示例。如果您正苦於以下問題:Java COSObject類的具體用法?Java COSObject怎麽用?Java COSObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


COSObject類屬於com.qcloud.cos.model包,在下文中一共展示了COSObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
@Override
public ObjectMetadata getObject(final GetObjectRequest getObjectRequest, File destinationFile)
        throws CosClientException, CosServiceException {
    rejectNull(destinationFile,
            "The destination file parameter must be specified when downloading an object directly to a file");
    COSObject cosObject = ServiceUtils.retryableDownloadCOSObjectToFile(destinationFile,
            new ServiceUtils.RetryableCOSDownloadTask() {

                @Override
                public boolean needIntegrityCheck() {
                    return !skipMd5CheckStrategy
                            .skipClientSideValidationPerRequest(getObjectRequest);
                }

                @Override
                public COSObject getCOSObjectStream() {
                    return getObject(getObjectRequest);
                }
            }, ServiceUtils.OVERWRITE_MODE);

    if (cosObject == null)
        return null;

    return cosObject.getObjectMetadata();
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:26,代碼來源:COSClient.java

示例2: call

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * This method must return a non-null object, or else the existing implementation in
 * {@link AbstractTransfer#waitForCompletion()} would block forever.
 * 
 * @return the downloaded file
 */
@Override
public File call() throws Exception {
    try {
        latch.await();
        download.setState(TransferState.InProgress);
        COSObject cosObject = retryableDownloadCOSObjectToFile(dstfile,
                new DownloadTaskImpl(cos, download, req), resumeExistingDownload);

        if (cosObject == null) {
            download.setState(TransferState.Canceled);
            download.setMonitor(new DownloadMonitor(download, null));
        } else {
            download.setState(TransferState.Completed);
        }
        return dstfile;
    } catch (Throwable t) {
        // Downloads aren't allowed to move from canceled to failed
        if (download.getState() != TransferState.Canceled) {
            download.setState(TransferState.Failed);
        }
        if (t instanceof Exception)
            throw (Exception) t;
        else
            throw (Error) t;
    }
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:33,代碼來源:DownloadCallable.java

示例3: DownloadImpl

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
public DownloadImpl(String description, TransferProgress transferProgress,
        ProgressListenerChain progressListenerChain, COSObject cosObject,
        TransferStateChangeListener listener,
        GetObjectRequest getObjectRequest, File file) {
    super(description, transferProgress, progressListenerChain, listener);
    this.cosObject = cosObject;
    this.persistableDownload = captureDownloadState(getObjectRequest, file);
    COSProgressPublisher.publishTransferPersistable(progressListenerChain,
            persistableDownload);
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:11,代碼來源:DownloadImpl.java

示例4: handle

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
@Override
public CosServiceResponse<COSObject> handle(CosHttpResponse response) throws Exception {
    COSObject object = new COSObject();
    CosServiceResponse<COSObject> cosResponse = parseResponseMetadata(response);

    ObjectMetadata metadata = object.getObjectMetadata();
    populateObjectMetadata(response, metadata);
    object.setObjectContent(
            new COSObjectInputStream(response.getContent(), response.getHttpRequest()));
    cosResponse.setResult(object);
    return cosResponse;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:13,代碼來源:COSObjectResponseHandler.java

示例5: parseToCCSObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * COSObject到CCSObject
 */
public static CCSObject parseToCCSObject(COSObject cosObject) {
	CCSObject ccsObject = new CCSObject();
	ccsObject.setBucketName(cosObject.getBucketName());
	ccsObject.setCcsPath(cosObject.getKey());
	ccsObject.setObjectContent(cosObject.getObjectContent());
	ccsObject.setCcsObjectMetadata(parseToCCSObjectMetadata(cosObject.getObjectMetadata()));
	return ccsObject;
}
 
開發者ID:MinsxCloud,項目名稱:minsx-ccs,代碼行數:12,代碼來源:COSParseUtil.java

示例6: getCosObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
public Optional<COSObject> getCosObject(){
	if(cosObject!=null){
		return cosObject;
	}
	if(!cosClient.doesObjectExist(bucketName, key)){
		cosObject = Optional.empty();
	}else{
		cosObject = Optional.ofNullable(cosClient.getObject(bucketName, key));
	}
	return cosObject;
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:12,代碼來源:CosClientWrapper.java

示例7: override

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
public ObjectOperation override(File file){
	Optional<COSObject> opt = getCosObject();
	if(!opt.isPresent()){
		throw new BaseException("key["+key+"] is not exists in bucket["+bucketName+"]");
	}
	return store(file);
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:8,代碼來源:CosClientWrapper.java

示例8: retryableDownloadCOSObjectToFile

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * Gets an object stored in COS and downloads it into the specified file.
 * This method includes the one-time retry mechanism after integrity check failure
 * on the downloaded file. It will also return immediately after getting null valued
 * COSObject (when getObject request does not meet the specified constraints).
 *
 * @param file
 *             The file to store the object's data in.
 * @param retryableCOSDownloadTask
 *             The implementation of SafeCOSDownloadTask interface which allows user to
 *             get access to all the visible variables at the calling site of this method.
 */
public static COSObject retryableDownloadCOSObjectToFile(File file,
        RetryableCOSDownloadTask retryableCOSDownloadTask, boolean appendData) {
    boolean hasRetried = false;
    boolean needRetry;
    COSObject cosObject;
    do {
        needRetry = false;
        cosObject = retryableCOSDownloadTask.getCOSObjectStream();
        if ( cosObject == null )
            return null;

        try {
            ServiceUtils.downloadObjectToFile(cosObject, file,
                    retryableCOSDownloadTask.needIntegrityCheck(),
                    appendData);
        } catch (CosClientException cse) {
            if (!cse.isRetryable()) {
                cosObject.getObjectContent().abort();
                throw cse;
            }
            // Determine whether an immediate retry is needed according to the captured CosClientException.
            // (There are three cases when downloadObjectToFile() throws CosClientException:
            //        1) SocketException or SSLProtocolException when writing to disk (e.g. when user aborts the download)
            //        2) Other IOException when writing to disk
            //        3) MD5 hashes don't match
            // The current code will retry the download only when case 2) or 3) happens.
            if (cse.getCause() instanceof SocketException || cse.getCause() instanceof SSLProtocolException) {
                throw cse;
            } else {
                needRetry = true;
                if ( hasRetried ) {
                    cosObject.getObjectContent().abort();
                    throw cse;
                } else {
                    log.info("Retry the download of object " + cosObject.getKey() + " (bucket " + cosObject.getBucketName() + ")", cse);
                    hasRetried = true;
                }
            }
        }
    } while ( needRetry );
    return cosObject;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:55,代碼來源:ServiceUtils.java

示例9: retryableDownloadCOSObjectToFile

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
private COSObject retryableDownloadCOSObjectToFile(File file,
        RetryableCOSDownloadTask retryableCOSDownloadTask, boolean appendData) {
    boolean hasRetried = false;
    COSObject cosObject;
    for (;;) {
        if (resumeExistingDownload && hasRetried) {
            // Need to adjust the get range or else we risk corrupting the downloaded file
            adjustRequest(req);
        }
        cosObject = retryableCOSDownloadTask.getCOSObjectStream();
        if (cosObject == null)
            return null;
        try {
            if (testing && resumeExistingDownload && !hasRetried) {
                throw new CosClientException("testing");
            }
            ServiceUtils.downloadToFile(cosObject, file,
                    retryableCOSDownloadTask.needIntegrityCheck(), appendData,
                    expectedFileLength);
            return cosObject;
        } catch (CosClientException ace) {
            if (!ace.isRetryable())
                throw ace;
            // Determine whether an immediate retry is needed according to the captured
            // CosClientException.
            // (There are three cases when downloadObjectToFile() throws CosClientException:
            // 1) SocketException or SSLProtocolException when writing to disk (e.g. when user
            // aborts the download)
            // 2) Other IOException when writing to disk
            // 3) MD5 hashes don't match
            // The current code will retry the download only when case 2) or 3) happens.
            if (ace.getCause() instanceof SocketException
                    || ace.getCause() instanceof SSLProtocolException) {
                throw ace;
            } else {
                if (hasRetried)
                    throw ace;
                else {
                    log.info("Retry the download of object " + cosObject.getKey() + " (bucket "
                            + cosObject.getBucketName() + ")", ace);
                    hasRetried = true;
                }
            }
        } finally {
            cosObject.getObjectContent().abort();
        }
    }
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:49,代碼來源:DownloadCallable.java

示例10: getCOSObjectStream

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
@Override
public COSObject getCOSObjectStream() {
    COSObject cosObject = cos.getObject(getObjectRequest);
    download.setCosObject(cosObject);
    return cosObject;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:7,代碼來源:DownloadTaskImpl.java

示例11: getCosObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
public COSObject getCosObject() {
    return cosObject;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:4,代碼來源:DownloadImpl.java

示例12: setCosObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
public void setCosObject(COSObject cosObject) {
    this.cosObject = cosObject;
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:4,代碼來源:DownloadImpl.java

示例13: getObject

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * <p>
 * Gets the object stored in under the specified bucket and key.
 * </p>
 * <p>
 * Be extremely careful when using this method; the returned COS object contains a direct stream
 * of data from the HTTP connection. The underlying HTTP connection cannot be closed until the
 * user finishes reading the data and closes the stream. Therefore:
 * </p>
 * <ul>
 * <li>Use the data from the input stream in object as soon as possible</li>
 * <li>Close the input stream in object as soon as possible</li>
 * </ul>
 * If these rules are not followed, the client can run out of resources by allocating too many
 * open, but unused, HTTP connections.
 * </p>
 * <p>
 * To get an object from , the caller must have {@link Permission#Read} access to the object.
 * </p>
 * <p>
 * If the object fetched is publicly readable, it can also read it by pasting its URL into a
 * browser.
 * </p>
 * <p>
 * For more advanced options (such as downloading only a range of an object's content, or
 * placing constraints on when the object should be downloaded) callers can use
 * {@link #getObject(GetObjectRequest)}.
 * </p>
 *
 * @param bucketName The name of the bucket containing the desired object.
 * @param key The key under which the desired object is stored.
 *
 * @return The object stored in in the specified bucket and key.
 *
 * @throws CosClientException If any errors are encountered in the client while making the
 *         request or handling the response.
 * @throws CosServiceException If any errors occurred in while processing the request.
 *
 * @see COS#getObject(GetObjectRequest)
 * @see COS#getObject(GetObjectRequest, File)
 */
public COSObject getObject(String bucketName, String key)
        throws CosClientException, CosServiceException;
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:44,代碼來源:COS.java

示例14: downloadObjectToFile

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * Downloads an COSObject, as returned from
 * {@link COSClient#getObject(com.qcloud.cos.model.GetObjectRequest)},
 * to the specified file.
 *
 * @param cosObject
 *            The COSObject containing a reference to an InputStream
 *            containing the object's data.
 * @param destinationFile
 *            The file to store the object's data in.
 * @param performIntegrityCheck
 *            Boolean valuable to indicate whether to perform integrity check
 * @param appendData
 *            appends the data to end of the file.
 */
public static void downloadObjectToFile(COSObject cosObject,
        final File destinationFile, boolean performIntegrityCheck,
        boolean appendData) {
    downloadToFile(cosObject, destinationFile, performIntegrityCheck, appendData, -1);
}
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:21,代碼來源:ServiceUtils.java

示例15: getCOSObjectStream

import com.qcloud.cos.model.COSObject; //導入依賴的package包/類
/**
 * User defines how to get the COSObject from COS for this RetryableCOSDownloadTask.
 *
 * @return
 *         The COSObject containing a reference to an InputStream
 *        containing the object's data.
 */
public COSObject getCOSObjectStream ();
 
開發者ID:tencentyun,項目名稱:cos-java-sdk-v5,代碼行數:9,代碼來源:ServiceUtils.java


注:本文中的com.qcloud.cos.model.COSObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。