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


Java ObjectMetadata類代碼示例

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


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

示例1: uploadFile

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
/**
 * Upload a file which is in the assets bucket.
 * 
 * @param fileName File name
 * @param file File
 * @param contentType Content type for file
 * @return
 */
public static boolean uploadFile(String fileName, File file, String contentType) {
    try {
        if (S3Module.amazonS3 != null) {
            String bucket = S3Module.s3Bucket;
            ObjectMetadata metaData = new ObjectMetadata();
            if (contentType != null) {
                metaData.setContentType(contentType);
            }
            PutObjectRequest putObj = new PutObjectRequest(bucket,
                    fileName, file);
            putObj.setMetadata(metaData);
            putObj.withCannedAcl(CannedAccessControlList.PublicRead);
            S3Module.amazonS3.putObject(putObj);
            return true;
        } else {
            Logger.error("Could not save because amazonS3 was null");
            return false;
        }
    } catch (Exception e) {
        Logger.error("S3 Upload -" + e.getMessage());
        return false;
    }
}
 
開發者ID:webinerds,項目名稱:s3-proxy-chunk-upload,代碼行數:32,代碼來源:AssetsS3.java

示例2: shouldGetObjectMetadata

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的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

示例3: store

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
/**
 * Stores the {@link InputStream} as an object in the S3 bucket.
 *
 * @param keyName The requested key name for the object.
 * @param inStream The {@link InputStream} to write out to an object in S3.
 * @param size The size of the {@link InputStream}.
 * @return A {@link CompletableFuture} that will eventually contain the S3 object key.
 */
@Override
public CompletableFuture<String> store(String keyName, InputStream inStream, long size) {
	final String bucketName = environment.getProperty(Constants.BUCKET_NAME_ENV_VARIABLE);
	final String kmsKey = environment.getProperty(Constants.KMS_KEY_ENV_VARIABLE);
	if (Strings.isNullOrEmpty(bucketName) || Strings.isNullOrEmpty(kmsKey)) {
		API_LOG.warn("No bucket name is specified or no KMS key specified.");
		return CompletableFuture.completedFuture("");
	}

	ObjectMetadata s3ObjectMetadata = new ObjectMetadata();
	s3ObjectMetadata.setContentLength(size);

	PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inStream, s3ObjectMetadata)
		.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(kmsKey));

	API_LOG.info("Writing object {} to S3 bucket {}", keyName, bucketName);
	return actOnItem(putObjectRequest);
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:27,代碼來源:StorageServiceImpl.java

示例4: move

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
            blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }

        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });

    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:S3BlobContainer.java

示例5: shouldCopyObjectEncrypted

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的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 shouldCopyObjectEncrypted() 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;

  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  copyObjectRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_ENC_KEYREF));

  final CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);

  final ObjectMetadata metadata =
      s3Client.getObjectMetadata(destinationBucketName, destinationKey);

  final InputStream uploadFileIS = new FileInputStream(uploadFile);
  final String uploadHash = HashUtil.getDigest(TEST_ENC_KEYREF, uploadFileIS);
  assertThat("ETag should match", copyObjectResult.getETag(), is(uploadHash));
  assertThat("Files should have the same length", metadata.getContentLength(),
      is(uploadFile.length()));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:32,代碼來源:AmazonClientUploadIT.java

示例6: store

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
@Override
public void store(BuildCacheKey key, BuildCacheEntryWriter writer) {
  logger.info("Start storing cache entry '{}' in S3 bucket", key.getHashCode());
  ObjectMetadata meta = new ObjectMetadata();
  meta.setContentType(BUILD_CACHE_CONTENT_TYPE);

  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    writer.writeTo(os);
    meta.setContentLength(os.size());
    try (InputStream is = new ByteArrayInputStream(os.toByteArray())) {
        PutObjectRequest request = getPutObjectRequest(key, meta, is);
        if(this.reducedRedundancy) {
          request.withStorageClass(StorageClass.ReducedRedundancy);
        }
        s3.putObject(request);
    }
  } catch (IOException e) {
    throw new BuildCacheException("Error while storing cache object in S3 bucket", e);
  }
}
 
開發者ID:myniva,項目名稱:gradle-s3-build-cache,代碼行數:21,代碼來源:AwsS3BuildCacheService.java

示例7: shouldUploadWithEncryption

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
/**
 * Tests if Object can be uploaded with KMS
 */
@Test
public void shouldUploadWithEncryption() {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String objectKey = UPLOAD_FILE_NAME;
  s3Client.createBucket(BUCKET_NAME);
  final PutObjectRequest putObjectRequest =
      new PutObjectRequest(BUCKET_NAME, objectKey, uploadFile);
  putObjectRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_ENC_KEYREF));

  s3Client.putObject(putObjectRequest);

  final GetObjectMetadataRequest getObjectMetadataRequest =
      new GetObjectMetadataRequest(BUCKET_NAME, objectKey);

  final ObjectMetadata objectMetadata = s3Client.getObjectMetadata(getObjectMetadataRequest);

  assertThat(objectMetadata.getContentLength(), is(uploadFile.length()));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:22,代碼來源:AmazonClientUploadIT.java

示例8: deleteShortUrl

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
/**
 * This method deletes the url for code
 * 
 * @param code
 */
public void deleteShortUrl(String code) {
	try {
		// get the object
		ObjectMetadata metaData = this.s3Client.getObjectMetadata(this.bucket, code);
		String url = metaData.getUserMetaDataOf("url");
		logger.info("The url to be deleted {}", url);
		this.s3Client.deleteObject(this.bucket, code);
		this.s3Client.deleteObject(this.bucket + "-dummy", code + Base64.encodeBase64String(url.getBytes()));

	} catch (AmazonS3Exception ex) {
		if (ex.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
			return;
		}
		logger.warn("Unable to get object status", ex);
		throw ex;
	}

}
 
開發者ID:weblegit,項目名稱:urlshortner,代碼行數:24,代碼來源:UrlShortnerService.java

示例9: create

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
@Override
@Guarded(by = STARTED)
public Blob create(final InputStream blobData, final Map<String, String> headers) {
  checkNotNull(blobData);

  return create(headers, destination -> {
      try (InputStream data = blobData) {
        MetricsInputStream input = new MetricsInputStream(data);
        TransferManager transferManager = new TransferManager(s3);
        transferManager.upload(getConfiguredBucket(), destination, input, new ObjectMetadata())
            .waitForCompletion();
        return input.getMetrics();
      } catch (InterruptedException e) {
        throw new BlobStoreException("error uploading blob", e, null);
      }
    });
}
 
開發者ID:sonatype,項目名稱:nexus-blobstore-s3,代碼行數:18,代碼來源:S3BlobStore.java

示例10: updateSnapshotIndex

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
/**
 * Write a list of all of the state versions to S3.
 * @param newVersion
 */
private synchronized void updateSnapshotIndex(Long newVersion) {
	/// insert the new version into the list
	int idx = Collections.binarySearch(snapshotIndex, newVersion);
	int insertionPoint = Math.abs(idx) - 1;
	snapshotIndex.add(insertionPoint, newVersion);
	
	/// build a binary representation of the list -- gap encoded variable-length integers
	byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex();
	
	/// indicate the Content-Length
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setHeader("Content-Length", (long)idxBytes.length);
	
    /// upload the new file content.
    try(InputStream is = new ByteArrayInputStream(idxBytes)) {
        Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata);
        
        upload.waitForCompletion();
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:Netflix,項目名稱:hollow-reference-implementation,代碼行數:27,代碼來源:S3Publisher.java

示例11: createEmptyObject

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
private void createEmptyObject(final String bucketName, final String objectName)
    throws AmazonClientException, AmazonServiceException {
  final InputStream im = new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  };

  final ObjectMetadata om = new ObjectMetadata();
  om.setContentLength(0L);
  if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
    om.setServerSideEncryption(serverSideEncryptionAlgorithm);
  }
  PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, im, om);
  putObjectRequest.setCannedAcl(cannedACL);
  s3.putObject(putObjectRequest);
  statistics.incrementWriteOps(1);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:S3AFileSystem.java

示例12: putObject

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的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

示例13: populateMetadataWithEncryptionParams

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
private void populateMetadataWithEncryptionParams(ObjectMetadata source, ObjectMetadata destination) {
    Map<String, String> userMetadataSource = source.getUserMetadata();
    Map<String, String> userMetadataDestination = destination.getUserMetadata();

    String[] headersToCopy = { Headers.CRYPTO_CEK_ALGORITHM,
            Headers.CRYPTO_IV, Headers.CRYPTO_KEY, Headers.CRYPTO_KEY_V2,
            Headers.CRYPTO_KEYWRAP_ALGORITHM, Headers.CRYPTO_TAG_LENGTH,
            Headers.MATERIALS_DESCRIPTION,
            Headers.UNENCRYPTED_CONTENT_LENGTH,
            Headers.UNENCRYPTED_CONTENT_MD5 };

    if (userMetadataSource != null) {
        if(userMetadataDestination == null){
            userMetadataDestination= new HashMap<String,String>();
            destination.setUserMetadata(userMetadataDestination);
        }

        String headerValue;
        for(String header : headersToCopy){
            headerValue = userMetadataSource.get(header);
            if(headerValue != null){
                userMetadataDestination.put(header, headerValue);
            }
        }
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:27,代碼來源:CopyCallable.java

示例14: put

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
public void put(InputStream inputStream, Long contentLength, URI destination) {
    checkRequiredJigsawModuleIsOnPath();
    try {
        S3RegionalResource s3RegionalResource = new S3RegionalResource(destination);
        String bucketName = s3RegionalResource.getBucketName();
        String s3BucketKey = s3RegionalResource.getKey();
        configureClient(s3RegionalResource);

        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(contentLength);

        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3BucketKey, inputStream, objectMetadata);
        LOGGER.debug("Attempting to put resource:[{}] into s3 bucket [{}]", s3BucketKey, bucketName);

        amazonS3Client.putObject(putObjectRequest);
    } catch (AmazonClientException e) {
        throw ResourceExceptions.putFailed(destination, e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:S3Client.java

示例15: storeFileInBucket

import com.amazonaws.services.s3.model.ObjectMetadata; //導入依賴的package包/類
public static void storeFileInBucket(String filename, InputStream is, ObjectMetadata metadata) {
	String bucketName = properties.getProperty(S3_BUCKET_NAME);
	try {
		LOG.info("Storing file {} in S3 bucket {}.", filename, bucketName);
		S3.putObject(bucketName, filename, is, metadata);
		S3.setObjectAcl(bucketName, filename, CannedAccessControlList.PublicRead);
	} catch (AmazonServiceException e) {
		LOG.error("Exception occured when fetching file from S3 bucket {}.", bucketName, e);
	}
}
 
開發者ID:villeau,項目名稱:pprxmtr,代碼行數:11,代碼來源:S3.java


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