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


Java S3ObjectSummary.setSize方法代碼示例

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


在下文中一共展示了S3ObjectSummary.setSize方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: objectListingAnswer

import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
private Answer<ObjectListing> objectListingAnswer(@Nullable final String marker, final String... fileNames) {
    return new Answer<ObjectListing>() {
        @Override
        public ObjectListing answer(InvocationOnMock invocation)
                throws Throwable {
            ListObjectsRequest request = (ListObjectsRequest) invocation.getArguments()[0];

            ObjectListing objectListing = new ObjectListing();
            objectListing.setBucketName(request.getBucketName());
            objectListing.setPrefix(request.getPrefix());

            objectListing.setTruncated(marker != null);
            objectListing.setNextMarker(marker);

            for (String fileName : fileNames) {
                S3ObjectSummary objectSummary = new S3ObjectSummary();
                objectSummary.setKey(request.getPrefix() + fileName);
                objectSummary.setSize(100);
                objectListing.getObjectSummaries().add(objectSummary);
            }

            return objectListing;
        }
    };
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:26,代碼來源:StashReaderTest.java

示例2: listObjects

import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws AmazonClientException, AmazonServiceException {
    MockObjectListing list = new MockObjectListing();
    list.setTruncated(false);

    String blobName;
    String prefix = listObjectsRequest.getPrefix();

    ArrayList<S3ObjectSummary> mockObjectSummaries = new ArrayList<>();

    for (Map.Entry<String, InputStream> blob : blobs.entrySet()) {
        blobName = blob.getKey();
        S3ObjectSummary objectSummary = new S3ObjectSummary();

        if (prefix.isEmpty() || blobName.startsWith(prefix)) {
            objectSummary.setKey(blobName);

            try {
                objectSummary.setSize(getSize(blob.getValue()));
            } catch (IOException e) {
                throw new AmazonS3Exception("Object listing " +
                        "failed for blob [" + blob.getKey() + "]");
            }

            mockObjectSummaries.add(objectSummary);
        }
    }

    list.setObjectSummaries(mockObjectSummaries);
    return list;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:33,代碼來源:MockAmazonS3.java

示例3: listObjects

import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p/>
 * If the bucket does not exist, returns a listing with an empty list. If a prefix is specified in listObjectsRequest, only keys starting with the prefix
 * will be returned.
 */
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest, AmazonS3 s3Client)
{
    LOGGER.debug("listObjects(): listObjectsRequest.getBucketName() = " + listObjectsRequest.getBucketName());

    String bucketName = listObjectsRequest.getBucketName();

    if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName))
    {
        AmazonS3Exception amazonS3Exception = new AmazonS3Exception(MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
        amazonS3Exception.setErrorCode("NoSuchBucket");
        throw amazonS3Exception;
    }

    ObjectListing objectListing = new ObjectListing();
    objectListing.setBucketName(bucketName);

    MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
    if (mockS3Bucket != null)
    {
        for (MockS3Object mockS3Object : mockS3Bucket.getObjects().values())
        {
            String s3ObjectKey = mockS3Object.getKey();
            if (listObjectsRequest.getPrefix() == null || s3ObjectKey.startsWith(listObjectsRequest.getPrefix()))
            {
                S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
                s3ObjectSummary.setBucketName(bucketName);
                s3ObjectSummary.setKey(s3ObjectKey);
                s3ObjectSummary.setSize(mockS3Object.getData().length);
                s3ObjectSummary.setStorageClass(mockS3Object.getObjectMetadata() != null ? mockS3Object.getObjectMetadata().getStorageClass() : null);

                objectListing.getObjectSummaries().add(s3ObjectSummary);
            }
        }
    }

    return objectListing;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:45,代碼來源:MockS3OperationsImpl.java

示例4: testGetS3FileList

import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Test
@PrepareForTest(TerrapinUtil.class)
public void testGetS3FileList() throws Exception {
  AmazonS3Client s3Client = mock(AmazonS3Client.class);
  ObjectListing objectListing = mock(ObjectListing.class);
  S3ObjectSummary summary1 = new S3ObjectSummary();
  S3ObjectSummary summary2 = new S3ObjectSummary();
  S3ObjectSummary summary3 = new S3ObjectSummary();
  summary1.setKey("/abc/123");
  summary2.setKey("/abc/456");
  summary3.setKey("/def/123");
  summary1.setSize(32432);
  summary2.setSize(213423);
  summary3.setSize(2334);
  List<S3ObjectSummary> summaries = ImmutableList.of(summary1, summary2, summary3);
  whenNew(AmazonS3Client.class).withAnyArguments().thenReturn(s3Client);
  when(s3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
  when(objectListing.getObjectSummaries()).thenReturn(summaries);

  List<Pair<Path, Long>> results = TerrapinUtil.getS3FileList(new AnonymousAWSCredentials(),
      "bucket", "/abc");

  assertEquals(2, results.size());
  assertTrue(results.get(0).getLeft().toString().endsWith(summary1.getKey()));
  assertEquals(new Long(summary1.getSize()), results.get(0).getRight());
  assertTrue(results.get(1).getLeft().toString().endsWith(summary2.getKey()));
  assertEquals(new Long(summary2.getSize()), results.get(1).getRight());
}
 
開發者ID:pinterest-attic,項目名稱:terrapin,代碼行數:29,代碼來源:TerrapinUtilTest.java

示例5: createS3ObjectSummary

import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
/**
 * Creates an S3 object summary.
 *
 * @param filePath the file path
 * @param fileSizeInBytes the file size in bytes
 *
 * @return the S3 object summary
 */
private S3ObjectSummary createS3ObjectSummary(String filePath, long fileSizeInBytes)
{
    S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
    s3ObjectSummary.setKey(filePath);
    s3ObjectSummary.setSize(fileSizeInBytes);
    return s3ObjectSummary;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:16,代碼來源:StorageFileHelperTest.java


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