本文整理汇总了Java中com.amazonaws.services.s3.model.ObjectListing类的典型用法代码示例。如果您正苦于以下问题:Java ObjectListing类的具体用法?Java ObjectListing怎么用?Java ObjectListing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectListing类属于com.amazonaws.services.s3.model包,在下文中一共展示了ObjectListing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listObjects
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
throws SdkClientException, AmazonServiceException {
listObjectsRequest = beforeClientExecution(listObjectsRequest);
rejectNull(listObjectsRequest.getBucketName(), "The bucket name parameter must be specified when listing objects in a bucket");
/**
* This flag shows whether we need to url decode S3 key names. This flag is enabled
* only when the customers don't explicitly call {@link ListObjectsRequest#setEncodingType(String)},
* otherwise, it will be disabled for maintaining backwards compatibility.
*/
final boolean shouldSDKDecodeResponse = listObjectsRequest.getEncodingType() == null;
Request<ListObjectsRequest> request = createRequest(listObjectsRequest.getBucketName(), null, listObjectsRequest, HttpMethodName.GET);
addParameterIfNotNull(request, "prefix", listObjectsRequest.getPrefix());
addParameterIfNotNull(request, "marker", listObjectsRequest.getMarker());
addParameterIfNotNull(request, "delimiter", listObjectsRequest.getDelimiter());
if (listObjectsRequest.getMaxKeys() != null && listObjectsRequest.getMaxKeys().intValue() >= 0) request.addParameter("max-keys", listObjectsRequest.getMaxKeys().toString());
request.addParameter("encoding-type", shouldSDKDecodeResponse ? Constants.URL_ENCODING : listObjectsRequest.getEncodingType());
return invoke(request, new Unmarshallers.ListObjectsUnmarshaller(shouldSDKDecodeResponse), listObjectsRequest.getBucketName(), null);
}
示例2: deleteAll
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
public void deleteAll(String bucket) {
logger.info("delete all from bucket, bucket={}", bucket);
ObjectListing listing = s3.listObjects(new ListObjectsRequest().withBucketName(bucket));
while (listing != null) {
List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<>(listing.getObjectSummaries().size());
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
String key = summary.getKey();
logger.info("add key to deletion batch, key={}", key);
keys.add(new DeleteObjectsRequest.KeyVersion(key));
}
if (!keys.isEmpty()) {
logger.info("delete key batch");
s3.deleteObjects(new DeleteObjectsRequest(bucket).withKeys(keys));
}
if (!listing.isTruncated()) return;
listing = s3.listNextBatchOfObjects(listing);
}
}
示例3: resolveDirectoryResourceNames
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
private List<String> resolveDirectoryResourceNames(ObjectListing objectListing) {
ImmutableList.Builder<String> builder = ImmutableList.builder();
if (objectListing.getCommonPrefixes() != null) {
for (String prefix : objectListing.getCommonPrefixes()) {
/**
* The common prefixes will also include the prefix of the <code>ObjectListing</code>
*/
String directChild = prefix.split(Pattern.quote(objectListing.getPrefix()))[1];
if (directChild.endsWith("/")) {
builder.add(directChild.substring(0, directChild.length() - 1));
} else {
builder.add(directChild);
}
}
return builder.build();
}
return Collections.emptyList();
}
示例4: listDirectChildren
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
public List<String> listDirectChildren(URI parent) {
S3RegionalResource s3RegionalResource = new S3RegionalResource(parent);
String bucketName = s3RegionalResource.getBucketName();
String s3BucketKey = s3RegionalResource.getKey();
configureClient(s3RegionalResource);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(s3BucketKey)
.withMaxKeys(1000)
.withDelimiter("/");
ObjectListing objectListing = amazonS3Client.listObjects(listObjectsRequest);
ImmutableList.Builder<String> builder = ImmutableList.builder();
builder.addAll(resourceResolver.resolveResourceNames(objectListing));
while (objectListing.isTruncated()) {
objectListing = amazonS3Client.listNextBatchOfObjects(objectListing);
builder.addAll(resourceResolver.resolveResourceNames(objectListing));
}
return builder.build();
}
示例5: listObjects
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的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;
}
示例6: testEmptyWithVersions
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
@Test
public void testEmptyWithVersions() throws Exception
{
// enable versioning on the bucket
SetBucketVersioningConfigurationRequest req = new SetBucketVersioningConfigurationRequest(
bucketName, new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED));
s3.setBucketVersioningConfiguration(req);
// create some versions
createVersionedObjects();
// empty the bucket of it's contents but leave the bucket itself
S3Cleaner.emptyBucket(s3, bucketName, false, offlineContext);
// check the bucket is still present but empty
assertTrue("Bucket '" + bucketName + "' should still be present", s3.doesBucketExistV2(bucketName));
ObjectListing objects = s3.listObjects(bucketName);
assertTrue("Bucket '" + bucketName + "' should be empty", objects.getObjectSummaries().isEmpty());
}
示例7: listUris
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
@Override
public List<URI> listUris(URI uri, Predicate<URI> uriPredicate) throws IOException {
String bucketName = uri.getHost();
if (client == null) {
client = clientBuilder.client(uri);
}
String prefix = uri.getPath().length() > 1 ? uri.getPath().substring(1) : "";
List<URI> uris = new ArrayList<>();
ObjectListing list = client.listObjects(bucketName, prefix);
addKeyUris(uris, list, uri, uriPredicate);
while (list.isTruncated()) {
list = client.listNextBatchOfObjects(list);
addKeyUris(uris, list, uri, uriPredicate);
}
return uris;
}
示例8: listNextBatchOfObjects
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
@Override
public ObjectListing listNextBatchOfObjects(ListNextBatchOfObjectsRequest listNextBatchOfObjectsRequest)
throws SdkClientException, AmazonServiceException {
listNextBatchOfObjectsRequest = beforeClientExecution(listNextBatchOfObjectsRequest);
rejectNull(listNextBatchOfObjectsRequest,
"The request object parameter must be specified when listing the next batch of objects in a bucket");
ObjectListing previousObjectListing = listNextBatchOfObjectsRequest.getPreviousObjectListing();
if (!previousObjectListing.isTruncated()) {
ObjectListing emptyListing = new ObjectListing();
emptyListing.setBucketName(previousObjectListing.getBucketName());
emptyListing.setDelimiter(previousObjectListing.getDelimiter());
emptyListing.setMarker(previousObjectListing.getNextMarker());
emptyListing.setMaxKeys(previousObjectListing.getMaxKeys());
emptyListing.setPrefix(previousObjectListing.getPrefix());
emptyListing.setEncodingType(previousObjectListing.getEncodingType());
emptyListing.setTruncated(false);
return emptyListing;
}
return listObjects(listNextBatchOfObjectsRequest.toListObjectsRequest());
}
示例9: handle
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
*/
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response);
responseHeaders = response.getHeaders();
if (responseUnmarshaller != null) {
log.trace("Beginning to parse service response XML");
T result = responseUnmarshaller.unmarshall(response.getContent());
log.trace("Done parsing service response XML");
awsResponse.setResult(result);
if (result instanceof ObjectListing) {
if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED))){
((ObjectListing) result).setIBMSSEKPEnabled(Boolean.parseBoolean(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED)));
}
if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))) {
((ObjectListing) result).setIBMSSEKPCrk(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
}
}
}
return awsResponse;
}
示例10: testHeadersAddedToObjectListing
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK are set in the ObjectLIsting
* response object
* @throws Exception
*
*/
@Test
public void testHeadersAddedToObjectListing() throws Exception {
Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
HttpResponse httpResponse = new HttpResponse(null, null);
httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");
httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "123456");
InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
httpResponse.setContent(is);
AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "123456");
assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
示例11: testNullKPHeadersAreHandled
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK null headers are handled
*
* @throws Exception
*
*/
@Test
public void testNullKPHeadersAreHandled() throws Exception {
Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
HttpResponse httpResponse = new HttpResponse(null, null);
httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, null);
httpResponse.addHeader(Headers.IBM_SSE_KP_CRK, null);
InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
httpResponse.setContent(is);
AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
示例12: testEmptyKPHeadersAreHandled
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK empty headers are handled
*
* @throws Exception
*
*/
@Test
public void testEmptyKPHeadersAreHandled() throws Exception {
Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
HttpResponse httpResponse = new HttpResponse(null, null);
InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
httpResponse.setContent(is);
AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
示例13: testOnlyKPEnabledHeaderIsSet
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Test the IBM_SSE_KP_CRK empty header is handled
*
* @throws Exception
*
*/
@Test
public void testOnlyKPEnabledHeaderIsSet() throws Exception {
Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
HttpResponse httpResponse = new HttpResponse(null, null);
httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");
InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
httpResponse.setContent(is);
AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
示例14: testOnlyCRKHeaderIsSet
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Test the IBM_SSE_KP_CRK empty header is handled
*
* @throws Exception
*
*/
@Test
public void testOnlyCRKHeaderIsSet() throws Exception {
Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
HttpResponse httpResponse = new HttpResponse(null, null);
httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "34567");
InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
httpResponse.setContent(is);
AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);
assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "34567");
assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
示例15: shouldGetObjectListing
import com.amazonaws.services.s3.model.ObjectListing; //导入依赖的package包/类
/**
* Tests if the list objects can be retrieved.
*/
@Test
public void shouldGetObjectListing() {
final File uploadFile = new File(UPLOAD_FILE_NAME);
s3Client.createBucket(BUCKET_NAME);
s3Client.putObject(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
final ObjectListing objectListingResult =
s3Client.listObjects(BUCKET_NAME, UPLOAD_FILE_NAME);
assertThat("ObjectListinig has no S3Objects.",
objectListingResult.getObjectSummaries().size(),
is(greaterThan(0)));
assertThat("The Name of the first S3ObjectSummary item has not expected the key name.",
objectListingResult.getObjectSummaries().get(0).getKey(),
is(UPLOAD_FILE_NAME));
}