本文整理汇总了Java中org.jets3t.service.model.S3Object.setMd5Hash方法的典型用法代码示例。如果您正苦于以下问题:Java S3Object.setMd5Hash方法的具体用法?Java S3Object.setMd5Hash怎么用?Java S3Object.setMd5Hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.model.S3Object
的用法示例。
在下文中一共展示了S3Object.setMd5Hash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeLargeFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void storeLargeFile(String key, File file, byte[] md5Hash)
throws IOException {
S3Object object = new S3Object(key);
object.setDataInputFile(file);
object.setContentType("binary/octet-stream");
object.setContentLength(file.length());
object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
if (md5Hash != null) {
object.setMd5Hash(md5Hash);
}
List<StorageObject> objectsToUploadAsMultipart =
new ArrayList<StorageObject>();
objectsToUploadAsMultipart.add(object);
MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);
try {
mpUtils.uploadObjects(bucket.getName(), s3Service,
objectsToUploadAsMultipart, null);
} catch (Exception e) {
handleException(e, key);
}
}
示例2: getDetails
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
* Add default metadata
*/
protected S3Object getDetails(final Path file, final TransferStatus status) {
final S3Object object = new S3Object(containerService.getKey(file));
final String mime = status.getMime();
if(StringUtils.isNotBlank(mime)) {
object.setContentType(mime);
}
final Checksum checksum = status.getChecksum();
if(Checksum.NONE != checksum) {
switch(checksum.algorithm) {
case md5:
object.setMd5Hash(ServiceUtils.fromHex(checksum.hash));
break;
case sha256:
object.addMetadata("x-amz-content-sha256", checksum.hash);
break;
}
}
if(StringUtils.isNotBlank(status.getStorageClass())) {
if(!S3Object.STORAGE_CLASS_STANDARD.equals(status.getStorageClass())) {
// The default setting is STANDARD.
object.setStorageClass(status.getStorageClass());
}
}
final Encryption.Algorithm encryption = status.getEncryption();
object.setServerSideEncryptionAlgorithm(encryption.algorithm);
// If the x-amz-server-side-encryption is present and has the value of aws:kms, this header specifies the ID of the
// AWS Key Management Service (KMS) master encryption key that was used for the object.
object.setServerSideEncryptionKmsKeyId(encryption.key);
for(Map.Entry<String, String> m : status.getMetadata().entrySet()) {
object.addMetadata(m.getKey(), m.getValue());
}
return object;
}
示例3: storeFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeFile(String key, File file, byte[] md5Hash)
throws IOException {
if (multipartEnabled && file.length() >= multipartBlockSize) {
storeLargeFile(key, file, md5Hash);
return;
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
S3Object object = new S3Object(key);
object.setDataInputStream(in);
object.setContentType("binary/octet-stream");
object.setContentLength(file.length());
object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
if (md5Hash != null) {
object.setMd5Hash(md5Hash);
}
s3Service.putObject(bucket, object);
} catch (ServiceException e) {
handleException(e, key);
} finally {
IOUtils.closeStream(in);
}
}
示例4: splitFileIntoObjectsByMaxPartSize
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
* Split the given file into objects such that no object has a size greater than
* the defined maximum part size. Each object uses a
* {@link SegmentedRepeatableFileInputStream} input stream to manage its own
* byte range within the underlying file.
*
* @param objectKey
* the object key name to apply to all objects returned by this method.
* @param file
* a file to split into multiple parts.
* @return
* an ordered list of objects that can be uploaded as multipart parts to S3 to
* re-constitute the given file in the service.
*
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public List<S3Object> splitFileIntoObjectsByMaxPartSize(String objectKey, File file)
throws IOException, NoSuchAlgorithmException
{
long fileLength = file.length();
long partCount = fileLength / maxPartSize + (fileLength % maxPartSize > 0 ? 1 : 0);
if (log.isDebugEnabled()) {
log.debug("Splitting file " + file.getAbsolutePath() + " of "
+ fileLength + " bytes into " + partCount
+ " object parts with a maximum part size of " + maxPartSize);
}
ArrayList<S3Object> multipartPartList = new ArrayList<S3Object>();
SegmentedRepeatableFileInputStream segFIS = null;
for (long offset = 0; offset < partCount; offset++) {
S3Object object = new S3Object(objectKey);
if (offset < partCount - 1) {
object.setContentLength(maxPartSize);
segFIS = new SegmentedRepeatableFileInputStream(
file, offset * maxPartSize, maxPartSize);
} else {
// Last part, may not be full size.
long partLength = fileLength % maxPartSize;
// Handle edge-case where last part is exactly the size of maxPartSize
if (partLength == 0) {
partLength = maxPartSize;
}
object.setContentLength(partLength);
segFIS = new SegmentedRepeatableFileInputStream(
file, offset * maxPartSize, partLength);
}
object.setContentLength(segFIS.available());
object.setDataInputStream(segFIS);
// Calculate part's MD5 hash and reset stream
object.setMd5Hash(ServiceUtils.computeMD5Hash(segFIS));
segFIS.reset();
multipartPartList.add(object);
}
return multipartPartList;
}
示例5: createObjectForUpload
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
/**
* Prepares a file for upload to a named object in S3, potentially transforming it if
* zipping or encryption is requested.
* <p>
* The file will have the following metadata items added:
* <ul>
* <li>{@link Constants#METADATA_JETS3T_LOCAL_FILE_DATE}: The local file's last modified date
* in ISO 8601 format</li>
* <li><tt>Content-Type</tt> : A content type guessed from the file's extension, or
* {@link Mimetypes#MIMETYPE_BINARY_OCTET_STREAM} if the file is a directory</li>
* <li><tt>Content-Length</tt> : The size of the file</li>
* <li><tt>MD5-Hash</tt> : An MD5 hash of the file's data</li>
* <li>{@link StorageObject#METADATA_HEADER_ORIGINAL_HASH_MD5}: An MD5 hash of the
* original file's data (added if gzipping or encryption is applied)</li>
* </ul>
*
* @param objectKey
* the object key name to use in S3
* @param dataFile
* the file to prepare for upload.
* @param encryptionUtil
* if this variable is null no encryption will be applied, otherwise the provided
* encryption utility object will be used to encrypt the file's data.
* @param gzipFile
* if true the file will be Gzipped.
* @param progressWatcher
* watcher to monitor progress of file transformation and hash generation.
*
* @return
* an S3Object representing the file, or a transformed copy of the file, complete with
* all JetS3t-specific metadata items set and ready for upload to S3.
*
* @throws Exception
* exceptions could include IO failures, gzipping and encryption failures.
*/
public static S3Object createObjectForUpload(String objectKey, File dataFile,
EncryptionUtil encryptionUtil, boolean gzipFile, BytesProgressWatcher progressWatcher)
throws Exception
{
S3Object s3Object = new S3Object(objectKey);
// Set object explicitly to private access by default.
s3Object.setAcl(AccessControlList.REST_CANNED_PRIVATE);
s3Object.addMetadata(Constants.METADATA_JETS3T_LOCAL_FILE_DATE,
ServiceUtils.formatIso8601Date(new Date(dataFile.lastModified())));
if (dataFile.isDirectory()) {
s3Object.setContentLength(0);
s3Object.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM);
} else {
s3Object.setContentType(Mimetypes.getInstance().getMimetype(dataFile));
File uploadFile = transformUploadFile(dataFile, s3Object, encryptionUtil,
gzipFile, progressWatcher);
s3Object.setContentLength(uploadFile.length());
s3Object.setDataInputFile(uploadFile);
// Compute the upload file's MD5 hash.
InputStream inputStream = new BufferedInputStream(new FileInputStream(uploadFile));
if (progressWatcher != null) {
inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
}
s3Object.setMd5Hash(ServiceUtils.computeMD5Hash(inputStream));
if (!uploadFile.equals(dataFile)) {
// Compute the MD5 hash of the *original* file, if upload file has been altered
// through encryption or gzipping.
inputStream = new BufferedInputStream(new FileInputStream(dataFile));
if (progressWatcher != null) {
inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
}
s3Object.addMetadata(
S3Object.METADATA_HEADER_ORIGINAL_HASH_MD5,
ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(inputStream)));
}
}
return s3Object;
}