當前位置: 首頁>>代碼示例>>Java>>正文


Java PutObjectResult類代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.PutObjectResult的典型用法代碼示例。如果您正苦於以下問題:Java PutObjectResult類的具體用法?Java PutObjectResult怎麽用?Java PutObjectResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PutObjectResult類屬於com.amazonaws.services.s3.model包,在下文中一共展示了PutObjectResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: putObject

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:MockAmazonS3.java

示例2: putObject

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@SuppressWarnings("resource")
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
    putObjectRequests.add(putObjectRequest);
    
    S3Object s3Object = new S3Object();
    s3Object.setBucketName(putObjectRequest.getBucketName());
    s3Object.setKey(putObjectRequest.getKey());
    if (putObjectRequest.getFile() != null) {
        try {
            s3Object.setObjectContent(new FileInputStream(putObjectRequest.getFile()));
        } catch (FileNotFoundException e) {
            throw new AmazonServiceException("Cannot store the file object.", e);
        }
    } else {
        s3Object.setObjectContent(putObjectRequest.getInputStream());
    }
    objects.add(s3Object);
    
    PutObjectResult putObjectResult = new PutObjectResult();
    putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
    return putObjectResult;
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:24,代碼來源:AmazonS3ClientMock.java

示例3: putObject

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Override
public PutObjectResult putObject(String bucketName, String key, String content)
        throws AmazonServiceException, SdkClientException {

    rejectNull(bucketName, "Bucket name must be provided");
    rejectNull(key, "Object key must be provided");
    rejectNull(content, "String content must be provided");

    byte[] contentBytes = content.getBytes(StringUtils.UTF8);

    InputStream is = new ByteArrayInputStream(contentBytes);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType("text/plain");
    metadata.setContentLength(contentBytes.length);

    return putObject(new PutObjectRequest(bucketName, key, is, metadata));
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:AmazonS3Client.java

示例4: putObjectUsingMetadata

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的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);
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:17,代碼來源:S3CryptoModuleBase.java

示例5: shouldCopyObject

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
/**
 * Puts an Object; Copies that object to a new bucket; Downloads the object from the new
 * bucket; compares checksums
 * of original and copied object
 *
 * @throws Exception if an Exception occurs
 */
@Test
public void shouldCopyObject() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String sourceKey = UPLOAD_FILE_NAME;
  final String destinationBucketName = "destinationBucket";
  final String destinationKey = "copyOf/" + sourceKey;

  final PutObjectResult putObjectResult =
      s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  s3Client.copyObject(copyObjectRequest);

  final com.amazonaws.services.s3.model.S3Object copiedObject =
      s3Client.getObject(destinationBucketName, destinationKey);

  final String copiedHash = HashUtil.getDigest(copiedObject.getObjectContent());
  copiedObject.close();

  assertThat("Sourcefile and copied File should have same Hashes",
      copiedHash,
      is(equalTo(putObjectResult.getETag())));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:32,代碼來源:AmazonClientUploadIT.java

示例6: shouldGetObjectMetadata

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
/**
 * Tests if the Metadata of an existing file can be retrieved.
 */
@Test
public void shouldGetObjectMetadata() {
  final String nonExistingFileName = "nonExistingFileName";
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  s3Client.createBucket(BUCKET_NAME);

  final PutObjectResult putObjectResult =
      s3Client.putObject(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  final ObjectMetadata metadataExisting =
      s3Client.getObjectMetadata(BUCKET_NAME, UPLOAD_FILE_NAME);

  assertThat("The ETags should be identically!", metadataExisting.getETag(),
      is(putObjectResult.getETag()));

  thrown.expect(AmazonS3Exception.class);
  thrown.expectMessage(containsString("Status Code: 404"));
  s3Client.getObjectMetadata(BUCKET_NAME, nonExistingFileName);
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:22,代碼來源:AmazonClientUploadIT.java

示例7: uploadPage

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void uploadPage() throws IOException, TemplateException {
    doCallRealMethod().when(uploader).uploadPage(any());
    doReturn(mock(PutObjectResult.class)).when(s3client).putObject(any());

    URL url = new URL("http://www.example.com");
    doReturn(url).when(s3client).getUrl(anyString(), anyString());
    
    String result = uploader.uploadPage("content");
    
    verify(s3client, times(1)).putObject(any());
    verify(s3client, times(1)).getUrl(anyString(), anyString());

    assertEquals(result, "http://www.example.com");
}
 
開發者ID:julianghionoiu,項目名稱:tdl-auth,代碼行數:17,代碼來源:IntroPageTemplateUploaderTest.java

示例8: testPut

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Test
public void testPut() {
    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, 12L));
    PutObjectRequest request = requestCaptor.getValue();

    assertEquals("model-bucket", request.getBucketName());
    assertEquals("path", request.getKey());
    assertEquals(stream, request.getInputStream());
    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());
}
 
開發者ID:coding4people,項目名稱:mosquito-report-api,代碼行數:27,代碼來源:BucketTest.java

示例9: simpleUploadFile

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception
{
    byte[]                          md5 = md5(bytes, bytes.length);

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(bytes.length);
    metadata.setLastModified(new Date());
    metadata.setContentMD5(S3Utils.toBase64(md5));
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata);
    PutObjectResult putObjectResult = client.putObject(putObjectRequest);

    if ( !putObjectResult.getETag().equals(S3Utils.toHex(md5)) )
    {
        throw new Exception("Unable to match MD5 for config");
    }

    return metadata;
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:19,代碼來源:S3Utils.java

示例10: starting

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Override
protected void starting(Description description)
{
  super.starting(description);
  outputPath = new File(
      "target" + Path.SEPARATOR + description.getClassName() + Path.SEPARATOR + description.getMethodName())
          .getPath();

  Attribute.AttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.DAGContext.APPLICATION_ID, description.getClassName());
  attributes.put(DAG.DAGContext.APPLICATION_PATH, outputPath);
  context = mockOperatorContext(1, attributes);

  underTest = new S3Reconciler();
  underTest.setAccessKey("");
  underTest.setSecretKey("");

  underTest.setup(context);

  MockitoAnnotations.initMocks(this);
  PutObjectResult result = new PutObjectResult();
  result.setETag(outputPath);
  when(s3clientMock.putObject((PutObjectRequest)any())).thenReturn(result);
  underTest.setS3client(s3clientMock);
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:26,代碼來源:S3ReconcilerTest.java

示例11: uploadObject

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Override
public PutObjectResult uploadObject(final String bucketName, final String fileName, final InputStream inputStream,
		final CannedAccessControlList cannedAcl) throws AmazonClientException, AmazonServiceException, IOException {
	LOGGER.info("uploadObject invoked, bucketName: {} , fileName: {}, cannedAccessControlList: {}", bucketName, fileName, cannedAcl);
	File tempFile = null;
	PutObjectRequest putObjectRequest = null;
	PutObjectResult uploadResult = null;
	try {
		// Create temporary file from stream to avoid 'out of memory' exception
		tempFile = AWSUtil.createTempFileFromStream(inputStream);
		putObjectRequest = new PutObjectRequest(bucketName, fileName, tempFile).withCannedAcl(cannedAcl);
		uploadResult = uploadObject(putObjectRequest);
	} finally {
		AWSUtil.deleteTempFile(tempFile); // Delete the temporary file once uploaded
	}
	return uploadResult;
}
 
開發者ID:abhinavmishra14,項目名稱:aws-s3-utils,代碼行數:18,代碼來源:AwsS3IamServiceImpl.java

示例12: createDirectory

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Override
public PutObjectResult createDirectory(final String bucketName, final String dirName,
		final boolean isPublicAccessible) throws AmazonClientException, AmazonServiceException {
	LOGGER.info("createDirectory invoked, bucketName: {}, dirName: {} and isPublicAccessible: {}", bucketName, dirName, isPublicAccessible);
	final ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentLength(0);
	// Create empty content,since creating empty folder needs an empty content
	final InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
	// Create a PutObjectRequest passing the directory name suffixed by '/'
	final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, dirName + AWSUtilConstants.SEPARATOR,
			emptyContent, metadata);
	if(isPublicAccessible){
	  putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
	}
	return s3client.putObject(putObjectRequest);
}
 
開發者ID:abhinavmishra14,項目名稱:aws-s3-utils,代碼行數:17,代碼來源:AwsS3IamServiceImpl.java

示例13: testConditionalGet

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Test
public void testConditionalGet() throws Exception {
    assumeTrue(!blobStoreType.equals("b2"));

    String blobName = "blob-name";
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(BYTE_SOURCE.size());
    PutObjectResult result = client.putObject(containerName, blobName,
            BYTE_SOURCE.openStream(), metadata);

    S3Object object = client.getObject(
            new GetObjectRequest(containerName, blobName)
                    .withMatchingETagConstraint(result.getETag()));
    try (InputStream is = object.getObjectContent()) {
        assertThat(is).isNotNull();
        ByteStreams.copy(is, ByteStreams.nullOutputStream());
    }

    object = client.getObject(
            new GetObjectRequest(containerName, blobName)
                    .withNonmatchingETagConstraint(result.getETag()));
    assertThat(object).isNull();
}
 
開發者ID:gaul,項目名稱:s3proxy,代碼行數:24,代碼來源:AwsSdkTest.java

示例14: uploadEntity

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
@Override
public boolean uploadEntity(String bucketName, String keyName, File file) {
    LOG.info("Uploads the specified file " + file
            + " to Amazon S3 under the specified bucket " + bucketName
            + " and key name " + keyName);
    
    try {
    	PutObjectResult putObjectResult = amazonS3Client.putObject(bucketName, keyName, file);
    	if (putObjectResult != null) {
    		return true;
    	}
    } catch (AmazonServiceException ase) {
        LOG.error(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error(ace.getMessage(), ace);
    }
    return false;
}
 
開發者ID:dgks0n,項目名稱:milton-aws,代碼行數:19,代碼來源:AmazonS3ManagerImpl.java

示例15: store

import com.amazonaws.services.s3.model.PutObjectResult; //導入依賴的package包/類
protected MediaMetadata store(String bucketName, String key,String fileName,InputStream data, MediaType contentType, Date lastModified)
   throws IOException
{
   File tmpFile = cache(data);
   ObjectMetadata metadata = new ObjectMetadata();
   metadata.setContentType(contentType.toString());
   metadata.setContentLength(tmpFile.length());
   metadata.setLastModified(lastModified==null ? new Date() : lastModified);
   if (lastModified!=null) {
      metadata.addUserMetadata("last-modified", DateUtils.format(lastModified,DateUtils.FORMAT_RFC_3339.get(0)));
   }
   InputStream is = new FileInputStream(tmpFile);
   try {
      PutObjectResult result = s3Client.putObject(bucketName, key, is, metadata);
      is.close();
      return new S3Metadata(fileName,contentType,lastModified,metadata.getContentLength());
   } catch (AmazonClientException ex) {
      is.close();
      throw new IOException("Cannot create object due to S3 error.",ex);
   } finally {
      tmpFile.delete();
   }
   
}
 
開發者ID:alexmilowski,項目名稱:xproclet,代碼行數:25,代碼來源:S3MediaStorage.java


注:本文中的com.amazonaws.services.s3.model.PutObjectResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。