本文整理汇总了Java中com.amazonaws.services.s3.model.ListObjectsRequest类的典型用法代码示例。如果您正苦于以下问题:Java ListObjectsRequest类的具体用法?Java ListObjectsRequest怎么用?Java ListObjectsRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListObjectsRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了ListObjectsRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listObjects
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的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.ListObjectsRequest; //导入依赖的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: listDirectChildren
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的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();
}
示例4: listObjects
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的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;
}
示例5: copyMultipleObjects
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
@Test
public void copyMultipleObjects() throws Exception {
// Making sure we only request 1 file at the time so we need to loop
ListObjectsRequestFactory mockListObjectRequestFactory = Mockito.mock(ListObjectsRequestFactory.class);
when(mockListObjectRequestFactory.newInstance()).thenReturn(new ListObjectsRequest().withMaxKeys(1));
client.putObject("source", "bar/data1", inputData);
client.putObject("source", "bar/data2", inputData);
Path sourceBaseLocation = new Path("s3://source/bar/");
Path replicaLocation = new Path("s3://target/foo/");
List<Path> sourceSubLocations = new ArrayList<>();
S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
transferManagerFactory, mockListObjectRequestFactory, registry, s3S3CopierOptions);
Metrics metrics = s3s3Copier.copy();
assertThat(metrics.getBytesReplicated(), is(14L));
S3Object object1 = client.getObject("target", "foo/data1");
String data1 = IOUtils.toString(object1.getObjectContent());
assertThat(data1, is("bar foo"));
S3Object object2 = client.getObject("target", "foo/data2");
String data2 = IOUtils.toString(object2.getObjectContent());
assertThat(data2, is("bar foo"));
}
示例6: prepareCurrentListing
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
private void prepareCurrentListing() {
while ( currentListing == null || (!currentIterator.hasNext() && currentListing.isTruncated()) ) {
if ( currentListing == null ) {
ListObjectsRequest req = new ListObjectsRequest();
req.setBucketName(getBucketName());
req.setPrefix(getPrefix());
req.setMaxKeys(getBatchSize());
currentListing = getS3().listObjects(req);
} else {
currentListing = getS3().listNextBatchOfObjects(currentListing);
}
currentIterator = currentListing.getObjectSummaries().iterator();
}
}
示例7: getFileList
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
@Override
public void getFileList(String path, OutputStream out) throws Exception {
String marker = null;
do {
ListObjectsRequest request = new ListObjectsRequest(bucketName, path, null, "/", 1000);
ObjectListing listing = client.listObjects(request);
for (S3ObjectSummary object : listing.getObjectSummaries()) {
String line = object.getKey() + "\n";
out.write(line.getBytes());
}
for (String commonPrefix : listing.getCommonPrefixes()) {
getFileList(commonPrefix, out);
}
marker = listing.getNextMarker();
} while (marker != null);
}
示例8: scanBucket
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
public void scanBucket() {
ListObjectsRequest listReq = new ListObjectsRequest()
.withPrefix(opt.prefix())
.withBucketName(opt.bucket());
Logger.Info("Scanning S3 bucket %s %s", opt.bucket(), opt.prefix());
ObjectListing listing = s3.listObjects(listReq);
boolean ok = processObjects(listing.getObjectSummaries());
while (ok && listing.isTruncated()) {
listing = s3.listNextBatchOfObjects(listing);
ok = processObjects(listing.getObjectSummaries());
}
Logger.Info("Completed scan, added %s images to the processing queue.", numSeen.get());
}
示例9: list
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
@Override
@SuppressWarnings("unused")
public List<AwsFileMiniModel> list(String prefix) {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
List<AwsFileMiniModel> files = new ArrayList();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"
+ " (date = " + objectSummary.getLastModified() + ")");
files.add(new AwsFileMiniModel(objectSummary.getKey(), objectSummary.getLastModified()));
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
return files;
}
示例10: listObjectRequest
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
private Matcher<ListObjectsRequest> listObjectRequest(final String bucket, final String prefix, @Nullable final String marker) {
return new BaseMatcher<ListObjectsRequest>() {
@Override
public boolean matches(Object item) {
ListObjectsRequest request = (ListObjectsRequest) item;
return request != null &&
request.getBucketName().equals(bucket) &&
request.getPrefix().equals(prefix) &&
Objects.equals(request.getMarker(), marker);
}
@Override
public void describeTo(Description description) {
description.appendText("ListObjectRequest[s3://").appendText(bucket).appendText("/").appendText(prefix);
if (marker != null) {
description.appendText(", marker=").appendText(marker);
}
description.appendText("]");
}
};
}
示例11: objectListingAnswer
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的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;
}
};
}
示例12: listObjects
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的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;
}
示例13: getFileNames
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
@Override
protected List<String> getFileNames(String lockPrefix) throws Exception
{
ListObjectsRequest request = new ListObjectsRequest();
request.setBucketName(bucket);
request.setPrefix(lockPrefix);
ObjectListing objectListing = client.listObjects(request);
return Lists.transform
(
objectListing.getObjectSummaries(),
new Function<S3ObjectSummary, String>()
{
@Override
public String apply(S3ObjectSummary summary)
{
return summary.getKey();
}
}
);
}
示例14: listKeysInOutputBucket
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
public List<String> listKeysInOutputBucket(String bucketName) {
List<String> videoKeys = new ArrayList<>();
ListObjectsRequest listFirstLevelKeyRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withDelimiter("/");
for (String commonPrefix : s3client.listObjects(listFirstLevelKeyRequest).getCommonPrefixes()) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(commonPrefix)
.withDelimiter("/");
for (S3ObjectSummary file : s3client.listObjects(listObjectsRequest).getObjectSummaries()) {
videoKeys.add(file.getKey());
}
}
return videoKeys;
}
示例15: getAllSummaries
import com.amazonaws.services.s3.model.ListObjectsRequest; //导入依赖的package包/类
/**
* Method returns list of all <b>S3ObjectSummary</b> objects, subject to
* <i>req</i> parameters. Multiple S3 calls will be performed if there are
* more than 1000 elements there
*
* @param req
* - ListObjectRequest to be used.
* @return List of S3ObjectSummary from bucket,
*/
public List<S3ObjectSummary> getAllSummaries(ListObjectsRequest req) {
List<S3ObjectSummary> result = new ArrayList<>();
String marker = null;
ListObjectsRequest req2 = (ListObjectsRequest) req.clone();
ObjectListing listing;
do {
listing = client.listObjects(req2.withMarker(marker));
marker = listing.getNextMarker();
result.addAll(listing.getObjectSummaries());
} while (listing.isTruncated());
return result;
}