/** * Creates a new instance of {@link COSInputStream}. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for COS * @param position the position to begin reading from * @param multiRangeChunkSize the chunk size to use on this stream */ COSInputStream(String bucketName, String key, COSClient client, long position, long multiRangeChunkSize) throws IOException { super(multiRangeChunkSize); mBucketName = bucketName; mKey = key; mCosClient = client; mPos = position; ObjectMetadata meta = mCosClient.getObjectMetadata(mBucketName, key); mContentLength = meta == null ? 0 : meta.getContentLength(); }
@Override protected ObjectStatus getObjectStatus(String key) { try { ObjectMetadata meta = mClient.getObjectMetadata(mBucketNameInternal, key); if (meta == null) { return null; } return new ObjectStatus(key, meta.getETag(), meta.getContentLength(), meta.getLastModified().getTime()); } catch (CosClientException e) { LOG.warn("Failed to get Object {}, return null", key, e); return null; } }
/** * Returns the physical length of the entire object stored in COS. This is useful during, for * example, a range get operation. */ public long getInstanceLength() { String contentRange = (String) metadata.get(Headers.CONTENT_RANGE); if (contentRange != null) { int pos = contentRange.lastIndexOf("/"); if (pos >= 0) return Long.parseLong(contentRange.substring(pos + 1)); } return getContentLength(); }
/** * Returns the physical length of the entire object stored in COS. This is useful during, for * example, a range get operation. */ public long getInstanceLength() { String contentRange = (String) metadata.get(Headers.CONTENT_RANGE); if (contentRange != null) { int pos = contentRange.lastIndexOf("/"); if (pos >= 0) return Long.parseLong(contentRange.substring(pos + 1)); } return getContentLength(); }
/** * Returns the size of the data in this request, otherwise -1 if the content * length is unknown. * * @param putObjectRequest * The request to check. * * @return The size of the data in this request, otherwise -1 if the size of * the data is unknown. */ public static long getContentLength(PutObjectRequest putObjectRequest) { File file = getRequestFile(putObjectRequest); if (file != null) return file.length(); if (putObjectRequest.getInputStream() != null) { if (putObjectRequest.getMetadata().getContentLength() > 0) { return putObjectRequest.getMetadata().getContentLength(); } } return -1; }
/** * Returns the size of the data in this request, otherwise -1 if the content * length is unknown. * * @param putObjectRequest * The request to check. * * @return The size of the data in this request, otherwise -1 if the size of * the data is unknown. */ public static long getContentLength(PutObjectRequest putObjectRequest) { File file = getRequestFile(putObjectRequest); if (file != null) return file.length(); if (putObjectRequest.getInputStream() != null) { if (putObjectRequest.getMetadata().getContentLength() > 0) { return putObjectRequest.getMetadata().getContentLength(); } } return -1; }
/** * Returns the plaintext length from the request and metadata; or -1 if unknown. */ protected final long plaintextLength(AbstractPutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadataValue(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * Returns the plaintext length from the request and metadata; or -1 if unknown. */ protected final long plaintextLength(AbstractPutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadataValue(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * Performs the copy of an COS object from source bucket to destination bucket as multiple copy * part requests. The information about the part to be copied is specified in the request as a * byte range (first-last) * * @throws Exception Any Exception that occurs while carrying out the request. */ private void copyInParts() throws Exception { multipartUploadId = initiateMultipartUpload(copyObjectRequest); long optimalPartSize = getOptimalPartSize(metadata.getContentLength()); try { CopyPartRequestFactory requestFactory = new CopyPartRequestFactory(copyObjectRequest, multipartUploadId, optimalPartSize, metadata.getContentLength()); copyPartsInParallel(requestFactory); } catch (Exception e) { publishProgress(listenerChain, ProgressEventType.TRANSFER_FAILED_EVENT); abortMultipartCopy(); throw new RuntimeException("Unable to perform multipart copy", e); } }
/** * Performs the copy of an COS object from source bucket to destination bucket as multiple copy * part requests. The information about the part to be copied is specified in the request as a * byte range (first-last) * * @throws Exception Any Exception that occurs while carrying out the request. */ private void copyInParts() throws Exception { multipartUploadId = initiateMultipartUpload(copyObjectRequest); long optimalPartSize = getOptimalPartSize(metadata.getContentLength()); try { CopyPartRequestFactory requestFactory = new CopyPartRequestFactory(copyObjectRequest, multipartUploadId, optimalPartSize, metadata.getContentLength()); copyPartsInParallel(requestFactory); } catch (Exception e) { publishProgress(listenerChain, ProgressEventType.TRANSFER_FAILED_EVENT); abortMultipartCopy(); throw new RuntimeException("Unable to perform multipart copy", e); } }
/** * Returns true if this CopyCallable is processing a multi-part copy. * * @return True if this CopyCallable is processing a multi-part copy. */ public boolean isMultipartCopy() { Region sourceRegion = copyObjectRequest.getSourceBucketRegion(); Region destRegion = cos.getClientConfig().getRegion(); // 如果没有设置source region, 表示使用的和clientconfig里面同一region, 这里不适用分块copy,使用put object copy即可 if (sourceRegion == null) { return false; } else { // 如果设置了source region, 且和目的region相同, 则也是用put object copy. if (sourceRegion.equals(destRegion)) { return false; } } return (metadata.getContentLength() > configuration.getMultipartCopyThreshold()); }
/** * Returns true if this CopyCallable is processing a multi-part copy. * * @return True if this CopyCallable is processing a multi-part copy. */ public boolean isMultipartCopy() { Region sourceRegion = copyObjectRequest.getSourceBucketRegion(); Region destRegion = cos.getClientConfig().getRegion(); // 如果没有设置source region, 表示使用的和clientconfig里面同一region, 这里不适用分块copy,使用put object copy即可 if (sourceRegion == null) { return false; } else { // 如果设置了source region, 且和目的region相同, 则也是用put object copy. if (sourceRegion.equals(destRegion)) { return false; } } return (metadata.getContentLength() > configuration.getMultipartCopyThreshold()); }
final ObjectMetadata objectMetadata = cos.getObjectMetadata(getObjectMetadataRequest); lastByte = objectMetadata.getContentLength() - 1;
final ObjectMetadata objectMetadata = cos.getObjectMetadata(getObjectMetadataRequest); lastByte = objectMetadata.getContentLength() - 1;
cosObject.getObjectMetadata().getContentLength(), // expected length
cosObject.getObjectMetadata().getContentLength(), // expected length
transferProgress.setTotalBytesToTransfer(metadata.getContentLength());
transferProgress.setTotalBytesToTransfer(metadata.getContentLength());