本文整理汇总了Java中org.jets3t.service.model.S3Object.getContentLength方法的典型用法代码示例。如果您正苦于以下问题:Java S3Object.getContentLength方法的具体用法?Java S3Object.getContentLength怎么用?Java S3Object.getContentLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.model.S3Object
的用法示例。
在下文中一共展示了S3Object.getContentLength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copy
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void copy(String srcKey, String dstKey) throws IOException {
try {
if(LOG.isDebugEnabled()) {
LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName());
}
if (multipartEnabled) {
S3Object object = s3Service.getObjectDetails(bucket, srcKey, null,
null, null, null);
if (multipartCopyBlockSize > 0 &&
object.getContentLength() > multipartCopyBlockSize) {
copyLargeFile(object, dstKey);
return;
}
}
S3Object dstObject = new S3Object(dstKey);
dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(),
dstObject, false);
} catch (ServiceException e) {
handleException(e, srcKey);
}
}
示例2: retrieveMetadata
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public FileMetadata retrieveMetadata(String key) throws IOException {
try {
S3Object object = s3Service.getObjectDetails(bucket, key);
return new FileMetadata(key, object.getContentLength(),
object.getLastModifiedDate().getTime());
} catch (S3ServiceException e) {
// Following is brittle. Is there a better way?
if (e.getMessage().contains("ResponseCode=404")) {
return null;
}
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
}
示例3: list
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private PartialListing list(String prefix, String delimiter,
int maxListingLength, String priorLastKey) throws IOException {
try {
if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) {
prefix += PATH_DELIMITER;
}
S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(),
prefix, delimiter, maxListingLength, priorLastKey);
FileMetadata[] fileMetadata =
new FileMetadata[chunk.getObjects().length];
for (int i = 0; i < fileMetadata.length; i++) {
S3Object object = chunk.getObjects()[i];
fileMetadata[i] = new FileMetadata(object.getKey(),
object.getContentLength(), object.getLastModifiedDate().getTime());
}
return new PartialListing(chunk.getPriorLastKey(), fileMetadata,
chunk.getCommonPrefixes());
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
}
示例4: list
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private PartialListing list(String prefix, String delimiter,
int maxListingLength, String priorLastKey) throws IOException {
try {
if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) {
prefix += PATH_DELIMITER;
}
S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(),
prefix, delimiter, maxListingLength, priorLastKey);
FileMetadata[] fileMetadata =
new FileMetadata[chunk.getObjects().length];
for (int i = 0; i < fileMetadata.length; i++) {
S3Object object = chunk.getObjects()[i];
fileMetadata[i] = new FileMetadata(object.getKey(),
object.getContentLength(), object.getLastModifiedDate().getTime());
}
return new PartialListing(chunk.getPriorLastKey(), fileMetadata,
chunk.getCommonPrefixes());
} catch (S3ServiceException e) {
handleServiceException(e);
return null; //never returned - keep compiler happy
}
}
示例5: copy
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void copy(String srcKey, String dstKey) throws IOException {
try {
if(LOG.isDebugEnabled()) {
LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName());
}
if (multipartEnabled) {
S3Object object = s3Service.getObjectDetails(bucket, srcKey, null,
null, null, null);
if (multipartCopyBlockSize > 0 &&
object.getContentLength() > multipartCopyBlockSize) {
copyLargeFile(object, dstKey);
return;
}
}
s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(),
new S3Object(dstKey), false);
} catch (ServiceException e) {
handleServiceException(srcKey, e);
}
}
示例6: get
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public byte[] get(String path) {
try {
S3Object obj = m_s3service.getObject(BUCKET, path);
m_logger.trace("GetObject: {}", path);
inc();
if(obj == null) return null;
int len = (int)obj.getContentLength();
byte[] data = new byte[len];
int start = 0;
InputStream is = obj.getDataInputStream();
while(start < len) {
start += is.read(data, start, len - start);
}
is.close();
return data;
} catch (Exception e) {
return null;
}
}
示例7: copyLargeFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void copyLargeFile(S3Object srcObject, String dstKey) throws IOException {
try {
long partCount = srcObject.getContentLength() / multipartCopyBlockSize +
(srcObject.getContentLength() % multipartCopyBlockSize > 0 ? 1 : 0);
MultipartUpload multipartUpload = s3Service.multipartStartUpload
(bucket.getName(), dstKey, srcObject.getMetadataMap());
List<MultipartPart> listedParts = new ArrayList<MultipartPart>();
for (int i = 0; i < partCount; i++) {
long byteRangeStart = i * multipartCopyBlockSize;
long byteLength;
if (i < partCount - 1) {
byteLength = multipartCopyBlockSize;
} else {
byteLength = srcObject.getContentLength() % multipartCopyBlockSize;
if (byteLength == 0) {
byteLength = multipartCopyBlockSize;
}
}
MultipartPart copiedPart = s3Service.multipartUploadPartCopy
(multipartUpload, i + 1, bucket.getName(), srcObject.getKey(),
null, null, null, null, byteRangeStart,
byteRangeStart + byteLength - 1, null);
listedParts.add(copiedPart);
}
Collections.reverse(listedParts);
s3Service.multipartCompleteUpload(multipartUpload, listedParts);
} catch (ServiceException e) {
handleException(e, srcObject.getKey());
}
}
示例8: retrieveMetadata
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public FileMetadata retrieveMetadata(String key) throws IOException {
try {
S3Object object = s3Service.getObjectDetails(bucket, key);
return new FileMetadata(key, object.getContentLength(),
object.getLastModifiedDate().getTime());
} catch (S3ServiceException e) {
// Following is brittle. Is there a better way?
if (e.getMessage().contains("ResponseCode=404")) {
return null;
}
handleServiceException(e);
return null; //never returned - keep compiler happy
}
}
示例9: copyLargeFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void copyLargeFile(S3Object srcObject, String dstKey) throws IOException {
try {
long partCount = srcObject.getContentLength() / multipartCopyBlockSize +
(srcObject.getContentLength() % multipartCopyBlockSize > 0 ? 1 : 0);
MultipartUpload multipartUpload = s3Service.multipartStartUpload
(bucket.getName(), dstKey, srcObject.getMetadataMap());
List<MultipartPart> listedParts = new ArrayList<MultipartPart>();
for (int i = 0; i < partCount; i++) {
long byteRangeStart = i * multipartCopyBlockSize;
long byteLength;
if (i < partCount - 1) {
byteLength = multipartCopyBlockSize;
} else {
byteLength = srcObject.getContentLength() % multipartCopyBlockSize;
if (byteLength == 0) {
byteLength = multipartCopyBlockSize;
}
}
MultipartPart copiedPart = s3Service.multipartUploadPartCopy
(multipartUpload, i + 1, bucket.getName(), srcObject.getKey(),
null, null, null, null, byteRangeStart,
byteRangeStart + byteLength - 1, null);
listedParts.add(copiedPart);
}
Collections.reverse(listedParts);
s3Service.multipartCompleteUpload(multipartUpload, listedParts);
} catch (ServiceException e) {
handleServiceException(e);
}
}
示例10: prepareForObjectsDownload
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void prepareForObjectsDownload() {
// Build map of existing local files.
Map<String, String> objectKeyToFilepathMap = null;
try {
boolean storeEmptyDirectories = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME)
.getBoolProperty("uploads.storeEmptyDirectories", true);
objectKeyToFilepathMap = FileComparer.getInstance()
.buildObjectKeyToFilepathMap(downloadDirectory.listFiles(), "", storeEmptyDirectories);
} catch (Exception e) {
String message = "Unable to review files in targetted download directory";
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, cockpitLiteProperties.getProperties(), message, e);
return;
}
filesAlreadyInDownloadDirectoryMap = new HashMap();
// Build map of S3 Objects being downloaded.
s3DownloadObjectsMap = FileComparer.getInstance()
.populateObjectMap("", getSelectedObjects());
// Identify objects that may clash with existing files, or may be directories,
// and retrieve details for these.
ArrayList potentialClashingObjects = new ArrayList();
Set existingFilesObjectKeys = objectKeyToFilepathMap.keySet();
Iterator objectsIter = s3DownloadObjectsMap.entrySet().iterator();
while (objectsIter.hasNext()) {
Map.Entry entry = (Map.Entry) objectsIter.next();
String objectKey = (String) entry.getKey();
S3Object object = (S3Object) entry.getValue();
if (object.getContentLength() == 0 || existingFilesObjectKeys.contains(objectKey)) {
potentialClashingObjects.add(object);
}
if (existingFilesObjectKeys.contains(objectKey)) {
filesAlreadyInDownloadDirectoryMap.put(
objectKey, objectKeyToFilepathMap.get(objectKey));
}
}
if (potentialClashingObjects.size() > 0) {
// Retrieve details of potential clashes.
final S3Object[] clashingObjects = (S3Object[])
potentialClashingObjects.toArray(new S3Object[potentialClashingObjects.size()]);
(new Thread() {
@Override
public void run() {
isDownloadingObjects = true;
retrieveObjectsDetails(clashingObjects);
}
}).start();
} else {
compareRemoteAndLocalFiles(filesAlreadyInDownloadDirectoryMap, s3DownloadObjectsMap, false);
}
}