本文整理匯總了Java中com.amazonaws.services.s3.model.S3ObjectSummary.setKey方法的典型用法代碼示例。如果您正苦於以下問題:Java S3ObjectSummary.setKey方法的具體用法?Java S3ObjectSummary.setKey怎麽用?Java S3ObjectSummary.setKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.model.S3ObjectSummary
的用法示例。
在下文中一共展示了S3ObjectSummary.setKey方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listObjects
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException, AmazonServiceException {
if ("nonExistingBucket".equals(listObjectsRequest.getBucketName()) && !nonExistingBucketCreated) {
AmazonServiceException ex = new AmazonServiceException("Unknown bucket");
ex.setStatusCode(404);
throw ex;
}
int capacity;
ObjectListing objectListing = new ObjectListing();
if (!ObjectHelper.isEmpty(listObjectsRequest.getMaxKeys()) && listObjectsRequest.getMaxKeys() != null) {
capacity = listObjectsRequest.getMaxKeys();
} else {
capacity = maxCapacity;
}
for (int index = 0; index < objects.size() && index < capacity; index++) {
S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
s3ObjectSummary.setBucketName(objects.get(index).getBucketName());
s3ObjectSummary.setKey(objects.get(index).getKey());
objectListing.getObjectSummaries().add(s3ObjectSummary);
}
return objectListing;
}
示例2: 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;
}
};
}
示例3: testGetKeysInPartialPath
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Test
public void testGetKeysInPartialPath() {
AmazonS3 client = mock(AmazonS3.class);
S3StoreService service = new S3StoreService(client, S3_BUCKET, S3_PREFIX);
String path = "path";
String key = "my-key";
S3ObjectSummary summary = new S3ObjectSummary();
summary.setKey(S3_PREFIX + key);
ObjectListing listing = mock(ObjectListing.class);
when(listing.getObjectSummaries()).thenReturn(Lists.newArrayList(summary));
when(client.listObjects(S3_BUCKET, S3_PREFIX + "/" + path)).thenReturn(listing);
// invoke method under test
Set<String> results = service.getKeysInPartialPath(path);
assertEquals(1, results.size());
assertEquals(key, results.iterator().next());
}
示例4: listObjects
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Override
public ObjectListing listObjects(ListObjectsRequest request) throws AmazonClientException, AmazonServiceException {
int currentRequestCount = requestCount.incrementAndGet();
assertEquals("mycamelbucket", request.getBucketName());
if (currentRequestCount == 2) {
assertEquals("confidential", request.getPrefix());
}
ObjectListing response = new ObjectListing();
response.setBucketName(request.getBucketName());
response.setPrefix(request.getPrefix());
S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
s3ObjectSummary.setBucketName(request.getBucketName());
s3ObjectSummary.setKey("key");
response.getObjectSummaries().add(s3ObjectSummary);
return response;
}
示例5: 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;
}
示例6: testGetAllBinaryKeys
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Test
public void testGetAllBinaryKeys() throws BinaryStoreException {
List<S3ObjectSummary> objectList = new ArrayList<>();
for(int i=0; i< 101; i++) {
S3ObjectSummary object = new S3ObjectSummary();
object.setKey(String.valueOf(i));
objectList.add(object);
}
// First request to get objects (incomplete list returned)
expect(s3Client.listObjects(isA(ListObjectsRequest.class)))
.andReturn(objectListing);
expect(objectListing.getObjectSummaries()).andReturn(objectList);
expect(objectListing.isTruncated()).andReturn(true);
// Second request to get more objects
expect(s3Client.listNextBatchOfObjects(objectListing))
.andReturn(objectListing);
expect(objectListing.getObjectSummaries()).andReturn(objectList);
expect(objectListing.isTruncated()).andReturn(false);
replayAll();
Iterable<BinaryKey> allKeys = s3BinaryStore.getAllBinaryKeys();
int keyCount = 0;
for(BinaryKey key : allKeys) {
keyCount++;
}
assertEquals(202, keyCount); // Expecting two sets of 101 objects
}
示例7: 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;
}
示例8: createSummaries
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
private List<S3ObjectSummary> createSummaries() {
List<S3ObjectSummary> summaries = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
S3ObjectSummary summary = new S3ObjectSummary();
summary.setKey("" + i);
summaries.add(summary);
}
return summaries;
}
示例9: 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());
}
示例10: getObjectsInBucket
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
private List<S3ObjectSummary> getObjectsInBucket(Date... dates) {
List<S3ObjectSummary> list = new ArrayList<S3ObjectSummary>();
for (Date date : dates) {
S3ObjectSummary s3Object = new S3ObjectSummary();
s3Object.setKey("dummy-key");
s3Object.setLastModified(date);
s3Object.setOwner(new Owner("123", "username"));
list.add(s3Object);
}
return list;
}
示例11: testRemoveValuesUnusedLongerThan
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Test
public void testRemoveValuesUnusedLongerThan() throws BinaryStoreException {
String usedObjectKey = "used-object";
String unusedNewKey = "unused-new";
String unusedOldKey = "unused-old";
// List of objects, one with unused=false,
// one with unused=true but updated within the hour,
// one with unused=true and last updated over a week ago (which should be removed)
List<S3ObjectSummary> objectList = new ArrayList<>();
S3ObjectSummary usedObject = new S3ObjectSummary();
usedObject.setKey(usedObjectKey);
objectList.add(usedObject);
S3ObjectSummary unusedNewObject = new S3ObjectSummary();
unusedNewObject.setKey(unusedNewKey);
objectList.add(unusedNewObject);
S3ObjectSummary unusedOldObject = new S3ObjectSummary();
unusedOldObject.setKey(unusedOldKey);
objectList.add(unusedOldObject);
// Expect request to get object list
expect(s3Client.listObjects(isA(ListObjectsRequest.class)))
.andReturn(objectListing);
expect(objectListing.getObjectSummaries()).andReturn(objectList);
expect(objectListing.isTruncated()).andReturn(false);
// Request for used object
ObjectMetadata usedObjMeta = new ObjectMetadata();
usedObjMeta.setUserMetadata(
Collections.singletonMap(s3BinaryStore.UNUSED_KEY, String.valueOf(false)));
usedObjMeta.setLastModified(new Date());
expect(s3Client.getObjectMetadata(BUCKET, usedObjectKey)).andReturn(usedObjMeta);
// Request for unused object with recent update
ObjectMetadata unusedNewObjMeta = new ObjectMetadata();
unusedNewObjMeta.setUserMetadata(
Collections.singletonMap(s3BinaryStore.UNUSED_KEY, String.valueOf(true)));
unusedNewObjMeta.setLastModified(new Date());
expect(s3Client.getObjectMetadata(BUCKET, unusedNewKey)).andReturn(unusedNewObjMeta);
// Request for unused object with old update
ObjectMetadata unusedOldObjMeta = new ObjectMetadata();
unusedOldObjMeta.setUserMetadata(
Collections.singletonMap(s3BinaryStore.UNUSED_KEY, String.valueOf(true)));
// Last modified 8 days ago
unusedOldObjMeta.setLastModified(new Date(System.currentTimeMillis() - 691200000));
expect(s3Client.getObjectMetadata(BUCKET, unusedOldKey)).andReturn(unusedOldObjMeta);
// Expect one delete
s3Client.deleteObject(BUCKET, unusedOldKey);
expectLastCall();
replayAll();
s3BinaryStore.removeValuesUnusedLongerThan(7, TimeUnit.DAYS);
}
示例12: testDeleteAllKeysOnPartialPath
import com.amazonaws.services.s3.model.S3ObjectSummary; //導入方法依賴的package包/類
@Test
public void testDeleteAllKeysOnPartialPath() {
AmazonS3 client = mock(AmazonS3.class);
S3StoreService service = new S3StoreService(client, S3_BUCKET, "");
String path = "path";
String key = "my-key";
S3ObjectSummary summary = new S3ObjectSummary();
summary.setKey(key);
ObjectListing listing = mock(ObjectListing.class);
when(listing.getObjectSummaries()).thenReturn(Lists.newArrayList(summary));
when(client.listObjects(S3_BUCKET, path)).thenReturn(listing);
// invoke method under test
service.deleteAllKeysOnPartialPath(path);
ArgumentCaptor<DeleteObjectsRequest> request = ArgumentCaptor.forClass(DeleteObjectsRequest.class);
verify(client, times(1)).deleteObjects(request.capture());
assertEquals(key, request.getValue().getKeys().get(0).getKey());
}
示例13: 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;
}