本文整理汇总了Java中com.amazonaws.services.s3.model.PutObjectRequest.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java PutObjectRequest.getInputStream方法的具体用法?Java PutObjectRequest.getInputStream怎么用?Java PutObjectRequest.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.PutObjectRequest
的用法示例。
在下文中一共展示了PutObjectRequest.getInputStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putObject
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
throws AmazonClientException, AmazonServiceException {
String blobName = putObjectRequest.getKey();
DigestInputStream stream = (DigestInputStream) putObjectRequest.getInputStream();
if (blobs.containsKey(blobName)) {
throw new AmazonS3Exception("[" + blobName + "] already exists.");
}
blobs.put(blobName, stream);
// input and output md5 hashes need to match to avoid an exception
String md5 = Base64.encodeAsString(stream.getMessageDigest().digest());
PutObjectResult result = new PutObjectResult();
result.setContentMd5(md5);
return result;
}
示例2: putObjectUsingMetadata
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) {
ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req);
// Wraps the object data with a cipher input stream
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial);
// Update the metadata
req.setMetadata(updateMetadataWithContentCryptoMaterial(
req.getMetadata(), req.getFile(), cekMaterial));
// Put the encrypted object into S3
try {
return s3.putObject(wrappedReq);
} finally {
cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log);
}
}
示例3: verifyStringPut
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
private void verifyStringPut(AmazonS3 mock, String key, String content) throws Exception {
ArgumentCaptor<PutObjectRequest> argument
= ArgumentCaptor.forClass(PutObjectRequest.class);
verify(mock)
.putObject(argument.capture());
PutObjectRequest req = argument.getValue();
assertEquals(key, req.getKey());
assertEquals(this.testBucket, req.getBucketName());
InputStreamReader input = new InputStreamReader(req.getInputStream(), "UTF-8");
StringBuilder sb = new StringBuilder(1024);
final char[] buffer = new char[1024];
try {
for(int read = input.read(buffer, 0, buffer.length);
read != -1;
read = input.read(buffer, 0, buffer.length)) {
sb.append(buffer, 0, read);
}
} catch (IOException ignore) { }
assertEquals(content, sb.toString());
}
示例4: UploadPartRequestFactory
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
public UploadPartRequestFactory(PutObjectRequest origReq, String uploadId, long optimalPartSize) {
this.origReq = origReq;
this.uploadId = uploadId;
this.optimalPartSize = optimalPartSize;
this.bucketName = origReq.getBucketName();
this.key = origReq.getKey();
this.file = TransferManagerUtils.getRequestFile(origReq);
this.remainingBytes = TransferManagerUtils.getContentLength(origReq);
this.sseCustomerKey = origReq.getSSECustomerKey();
this.totalNumberOfParts = (int) Math.ceil((double) this.remainingBytes
/ this.optimalPartSize);
if (origReq.getInputStream() != null) {
wrappedStream = ReleasableInputStream.wrap(origReq.getInputStream());
}
}
示例5: getContentLength
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
/**
* 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;
}
示例6: putObjectUsingInstructionFile
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
/**
* Puts an encrypted object into S3, and puts an instruction file into S3.
* Encryption info is stored in the instruction file.
*
* @param putObjectRequest
* The request object containing all the parameters to upload a
* new object to Amazon S3.
* @return A {@link PutObjectResult} object containing the information
* returned by Amazon S3 for the new, created object.
*/
private PutObjectResult putObjectUsingInstructionFile(
PutObjectRequest putObjectRequest) {
final File fileOrig = putObjectRequest.getFile();
final InputStream isOrig = putObjectRequest.getInputStream();
final PutObjectRequest putInstFileRequest = putObjectRequest.clone()
.withFile(null)
.withInputStream(null)
;
putInstFileRequest.setKey(putInstFileRequest.getKey() + DOT
+ DEFAULT_INSTRUCTION_FILE_SUFFIX);
// Create instruction
ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(putObjectRequest);
// Wraps the object data with a cipher input stream; note the metadata
// is mutated as a side effect.
PutObjectRequest req = wrapWithCipher(putObjectRequest, cekMaterial);
// Put the encrypted object into S3
final PutObjectResult result;
try {
result = s3.putObject(req);
} finally {
cleanupDataSource(putObjectRequest, fileOrig, isOrig,
req.getInputStream(), log);
}
// Put the instruction file into S3
s3.putObject(updateInstructionPutRequest(putInstFileRequest,
cekMaterial));
// Return the result of the encrypted object PUT.
return result;
}
示例7: testPutWithoutContentLenght
import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
@Test
public void testPutWithoutContentLenght() {
ModelBucket bucket = getService(ModelBucket.class);
InputStream stream = new ByteArrayInputStream("file content".getBytes());
ArgumentCaptor<PutObjectRequest> requestCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
PutObjectResult expected = new PutObjectResult();
when(amazonS3Client.putObject(requestCaptor.capture())).thenReturn(expected);
assertEquals(expected, bucket.put("path", stream, null));
PutObjectRequest request = requestCaptor.getValue();
Scanner scanner = new Scanner(request.getInputStream());
assertEquals("model-bucket", request.getBucketName());
assertEquals("path", request.getKey());
assertEquals("file content", scanner.useDelimiter("\\A").next());
assertEquals(12L, request.getMetadata().getContentLength());
List<Grant> grants = request.getAccessControlList().getGrantsAsList();
assertEquals(1, grants.size());
assertEquals(GroupGrantee.AllUsers, grants.get(0).getGrantee());
assertEquals(Permission.Read, grants.get(0).getPermission());
scanner.close();
}