本文整理汇总了Java中com.amazonaws.services.s3.model.ObjectListing.getCommonPrefixes方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectListing.getCommonPrefixes方法的具体用法?Java ObjectListing.getCommonPrefixes怎么用?Java ObjectListing.getCommonPrefixes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.ObjectListing
的用法示例。
在下文中一共展示了ObjectListing.getCommonPrefixes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: getFileList
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的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);
}
示例3: getCommonPrefixFromListing
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
private List<String> getCommonPrefixFromListing(ObjectListing listing, String prefix) {
List<String> results = new ArrayList<String>(100);
for (String commonPrefix : listing.getCommonPrefixes()) {
final String dirname;
/* remove prefix and trailing delimiter */
dirname = commonPrefix.substring(prefix.length(),
commonPrefix.length() - DELIMITER.length());
if (dirname.length() == 0 || dirname.contains(DELIMITER)) {
log.error("Error parsing S3 object prefix. Prefix: " + commonPrefix);
continue;
}
results.add(dirname);
}
return results;
}
示例4: findProgressivelyWithPartialMatch
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
/**
* Searches for matching keys progressively. This means that instead of retrieving all keys given a prefix, it goes
* down one level at a time and filters out all non-matching results. This avoids a lot of unused requests results.
* WARNING: This method does not truncate results. Therefore all matching resources will be returned regardless of
* the truncation.
*/
private void findProgressivelyWithPartialMatch(String bucketName, Set<Resource> resources, String prefix, String keyPattern) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withDelimiter("/").withPrefix(prefix);
ObjectListing objectListing = null;
do {
if (objectListing == null) {
objectListing = this.amazonS3.listObjects(listObjectsRequest);
} else {
objectListing = this.amazonS3.listNextBatchOfObjects(objectListing);
}
Set<Resource> newResources = getResourcesFromObjectSummaries(bucketName, keyPattern, objectListing.getObjectSummaries());
if (!newResources.isEmpty()) {
resources.addAll(newResources);
}
for (String commonPrefix : objectListing.getCommonPrefixes()) {
if (isKeyPathMatchesPartially(keyPattern, commonPrefix)) {
findPathMatchingKeyInBucket(bucketName, resources, commonPrefix, keyPattern);
}
}
} while (objectListing.isTruncated());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:30,代码来源:PathMatchingSimpleStorageResourcePatternResolver.java
示例5: testBlobListRecursive
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Test
public void testBlobListRecursive() throws Exception {
ObjectListing listing = client.listObjects(containerName);
assertThat(listing.getObjectSummaries()).isEmpty();
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, "prefix/blob1",
BYTE_SOURCE.openStream(), metadata);
client.putObject(containerName, "prefix/blob2",
BYTE_SOURCE.openStream(), metadata);
ImmutableList.Builder<String> builder = ImmutableList.builder();
listing = client.listObjects(new ListObjectsRequest()
.withBucketName(containerName)
.withDelimiter("/"));
assertThat(listing.getObjectSummaries()).isEmpty();
for (String prefix : listing.getCommonPrefixes()) {
builder.add(prefix);
}
assertThat(builder.build()).containsOnly("prefix/");
builder = ImmutableList.builder();
listing = client.listObjects(containerName);
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
builder.add(summary.getKey());
}
assertThat(builder.build()).containsOnly("prefix/blob1",
"prefix/blob2");
assertThat(listing.getCommonPrefixes()).isEmpty();
}
示例6: addDirectories
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
private void addDirectories(ObjectListing objectListing) {
List<String> directories = objectListing.getCommonPrefixes();
for (String directory : directories) {
String dir = stripPrefix(directory);
FileListModel model = new FileListModel(dir, dir, FileListModel.FILE_DIR);
listView.getItems().add(model);
}
}
示例7: getChildrenNames
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public String[] getChildrenNames(ITransaction transaction, final String uri) throws WebdavException {
LOG.debug("List children names of folder {} at {}", uri, transaction);
List<String> children = new ArrayList<>();
String keyspacePrefix = this.s3Properties.getKeyspacePrefix();
String folderUri = S3Properties.normalizeFolderUri(uri);
try {
ObjectListing objects = this.s3client.listObjects(new ListObjectsRequest(this.s3Properties.getBucketName(), keyspacePrefix + folderUri, null, "/", null));
while (objects != null) {
for (String folder : objects.getCommonPrefixes()) {
children.add(folder.substring(keyspacePrefix.length() + folderUri.length()));
}
for (S3ObjectSummary object : objects.getObjectSummaries()) {
String name = object.getKey().substring(keyspacePrefix.length());
if (name.startsWith(folderUri)) {
name = name.substring(folderUri.length());
}
if (!name.isEmpty()) {
children.add(name);
}
}
if (objects.isTruncated()) {
objects = this.s3client.listNextBatchOfObjects(objects);
} else {
objects = null;
}
}
return children.toArray(new String[children.size()]);
} catch (AmazonServiceException e) {
throw mapAmazonServiceException(e);
}
}
示例8: folderExistsInRootOfBucket
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public boolean folderExistsInRootOfBucket(String key) {
if (!key.endsWith(SLASH))
key += SLASH;
ObjectListing objects = listObjectsInRootFolder();
for (String commonPrefix : objects.getCommonPrefixes()) {
if (commonPrefix.equals(key))
return true;
}
return false;
}
示例9: execute
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
AmazonKey amazonKey = getAmazonKey( _session, argStruct );
AmazonS3 s3Client = getAmazonS3( amazonKey );
String bucket = getNamedStringParam( argStruct, "bucket", null );
String prefix = getNamedStringParam( argStruct, "prefix", "" );
if ( bucket == null )
throwException( _session, "Please specify a bucket" );
try {
// Create the results
cfQueryResultData qD = new cfQueryResultData( new String[] { "key", "size", "modified", "etag" }, null );
qD.setQuerySource( "AmazonS3." + amazonKey.getDataSource() );
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName( bucket )
.withDelimiter( "/" )
.withPrefix( prefix );
ObjectListing objectListing;
do {
objectListing = s3Client.listObjects( listObjectsRequest );
java.util.List<String> prefixes = objectListing.getCommonPrefixes();
// first add the prefixes
for ( String nextPrefix : prefixes ) {
qD.addRow( 1 );
qD.setCurrentRow( qD.getSize() );
qD.setCell( 1, new cfStringData( nextPrefix ) );
qD.setCell( 2, new cfNumberData( 0 ) );
qD.setCell( 3, cfNullData.NULL );
qD.setCell( 4, cfNullData.NULL );
}
for ( S3ObjectSummary objectSummary : objectListing.getObjectSummaries() ) {
// don't include the prefix being listed
if ( objectSummary.getKey().equals( prefix ) ) {
continue;
}
qD.addRow( 1 );
qD.setCurrentRow( qD.getSize() );
qD.setCell( 1, new cfStringData( objectSummary.getKey() ) );
qD.setCell( 2, new cfNumberData( objectSummary.getSize() ) );
qD.setCell( 3, new cfDateData( objectSummary.getLastModified() ) );
qD.setCell( 4, new cfStringData( objectSummary.getETag() ) );
}
listObjectsRequest.setMarker( objectListing.getNextMarker() );
} while ( objectListing.isTruncated() );
return qD;
} catch ( Exception e ) {
throwException( _session, "AmazonS3: " + e.getMessage() );
return cfBooleanData.FALSE;
}
}
示例10: call
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public Integer call() throws Exception {
BigInteger count = new BigInteger("0");
String nextMarker = null;
int nextLimit;
do {
// no limit always requests the max
nextLimit = AWS_MAX_KEYS;
if(limit != null) {
// if it is set, limit the next request to no more than the max that are still available
nextLimit = limit.subtract(count).min(AWS_MAX_KEYS_BIG).intValue();
}
if(nextLimit > 0) {
ObjectListing o = list(nextMarker, nextLimit);
for(String dir : o.getCommonPrefixes()) {
printStream.println(String.format(listDirFormat, "DIR", o.getBucketName(), dir));
}
for (S3ObjectSummary os : o.getObjectSummaries()) {
if (limit == null || count.compareTo(limit) <= 0) {
printStream.println(String.format(listFormat,
os.getLastModified(),
os.getSize(),
os.getBucketName(),
os.getKey(),
os.getETag(),
os.getOwner(),
os.getStorageClass()));
nextMarker = o.getNextMarker();
count = count.add(ONE);
} else {
// bail out when we've printed all we can
nextMarker = null;
}
}
}
} while (nextMarker != null && nextLimit > 0);
return 0;
}
示例11: populateMetadata
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public void populateMetadata(DirectoryMetadata directoryMetadata, String bucketName, String prefix) {
String marker = null;
do {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName, prefix, marker, "/", null);
ObjectListing objectListing = this.amazonS3Client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
if (objectSummary.getKey().equals(prefix)) {
continue;
}
FileMetadata file = new FileMetadata();
file.setName(objectSummary.getKey().substring(prefix.length()));
file.setSizeInBytes(objectSummary.getSize());
if (objectSummary.getETag().contains("-")) {
file.addChecksum(ChecksumType.S3_MULTIPART_ETAG, objectSummary.getETag());
} else {
file.addChecksum(ChecksumType.MD5, objectSummary.getETag());
}
directoryMetadata.addFile(file);
}
for (String subdirectoryPath : objectListing.getCommonPrefixes()) {
DirectoryMetadata subdirectory = new DirectoryMetadata();
subdirectory.setName(subdirectoryPath.substring(prefix.length(), subdirectoryPath.length() - 1));
directoryMetadata.addSubdirectory(subdirectory);
populateMetadata(subdirectory, bucketName, subdirectoryPath);
}
marker = objectListing.getNextMarker();
}
while (marker != null);
}