本文整理汇总了Java中org.jets3t.service.model.S3Object.setDataInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java S3Object.setDataInputStream方法的具体用法?Java S3Object.setDataInputStream怎么用?Java S3Object.setDataInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.model.S3Object
的用法示例。
在下文中一共展示了S3Object.setDataInputStream方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void put(String key, InputStream in, long length, boolean storeMetadata)
throws IOException {
try {
S3Object object = new S3Object(key);
object.setDataInputStream(in);
object.setContentType("binary/octet-stream");
object.setContentLength(length);
if (storeMetadata) {
object.addAllMetadata(METADATA);
}
s3Service.putObject(bucket, object);
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
}
示例2: saveImage
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
private void saveImage(String filename, MultipartFile image)
throws ImageUploadException {
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3AccessKey, s3SecretKey);
S3Service s3 = new RestS3Service(awsCredentials);
S3Bucket imageBucket = s3.getBucket("spitterImages");
S3Object imageObject = new S3Object(filename);
imageObject.setDataInputStream(
new ByteArrayInputStream(image.getBytes()));
imageObject.setContentLength(image.getBytes().length);
imageObject.setContentType("image/jpeg");
AccessControlList acl = new AccessControlList();
acl.setOwner(imageBucket.getOwner());
acl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
imageObject.setAcl(acl);
s3.putObject(imageBucket, imageObject);
} catch (Exception e) {
throw new ImageUploadException("Unable to save image", e);
}
}
示例3: storeEmptyFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
try {
S3Object object = new S3Object(key);
object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
object.setContentType("binary/octet-stream");
object.setContentLength(0);
object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
s3Service.putObject(bucket, object);
} catch (ServiceException e) {
handleException(e, key);
}
}
示例4: 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);
}
}
示例5: storeEmptyFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
public void storeEmptyFile(String key) throws IOException {
try {
S3Object object = new S3Object(key);
object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
object.setContentType("binary/octet-stream");
object.setContentLength(0);
s3Service.putObject(bucket, object);
} catch (S3ServiceException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new S3Exception(e);
}
}
示例6: storeEmptyFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
try {
S3Object object = new S3Object(key);
object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
object.setContentType("binary/octet-stream");
object.setContentLength(0);
s3Service.putObject(bucket, object);
} catch (S3ServiceException e) {
handleServiceException(e);
}
}
示例7: storeFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeFile(String path, InputStream is, long size) throws IOException {
path = stripLeadingSlash(path);
S3Object fileObject = new S3Object(path);
fileObject.setDataInputStream(is);
if (size != -1) {
fileObject.setContentLength(size);
}
try {
service.putObject(bucketName, fileObject);
} catch (S3ServiceException e) {
throw new IOException(e);
}
}
示例8: storeEmptyFile
import org.jets3t.service.model.S3Object; //导入方法依赖的package包/类
@Override
public void storeEmptyFile(String key) throws IOException {
try {
S3Object object = new S3Object(key);
object.setDataInputStream(new ByteArrayInputStream(new byte[0]));
object.setContentType("binary/octet-stream");
object.setContentLength(0);
s3Service.putObject(bucket, object);
} catch (S3ServiceException e) {
handleS3ServiceException(e);
}
}
示例9: 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;
}