예제 #1
0
  private List<String> getResourceNames(ObjectListing objectListing, Pattern pattern) {
    List<String> resourceNames = new ArrayList<String>();

    for (String commonPrefix : objectListing.getCommonPrefixes()) {
      resourceNames.add(getResourceName(commonPrefix, pattern));
    }

    for (S3ObjectSummary s3ObjectSummary : objectListing.getObjectSummaries()) {
      resourceNames.add(getResourceName(s3ObjectSummary.getKey(), pattern));
    }

    return resourceNames;
  }
예제 #2
0
  public static void main(final String[] args) {
    DesktopSetup.deploy();
    final RelativePath target = JUtils.newRelativePath();

    final AmazonS3 s3 = new AmazonS3Client(new ProfileCredentialsProvider());
    final ListObjectsRequest request = new ListObjectsRequest().withBucketName("jfix.by");

    final String prefix = "/";
    request.withPrefix("wp-content");
    request.setDelimiter("");

    final ObjectListing objectListing = s3.listObjects(request);
    final List<String> prefixes = Collections.newList(objectListing.getCommonPrefixes());
    prefixes.print("prefixes");

    final List<S3ObjectSummary> summs = Collections.newList(objectListing.getObjectSummaries());
  }
 @Override
 public List<String> list(String prefix, boolean files) throws IOException {
   boolean truncated = true;
   String marker = null;
   List<String> result = Lists.newArrayList();
   while (truncated) {
     if (marker != null) {
       log.info("Next page after {}", marker);
     }
     ListObjectsRequest listRequest =
         new ListObjectsRequest(Namespaces.get().getBucket(), prefix, marker, "/", null);
     ObjectListing listing;
     try {
       listing = s3Client.listObjects(listRequest);
     } catch (AmazonClientException ace) {
       throw new IOException(ace);
     }
     truncated = listing.isTruncated();
     marker = listing.getNextMarker();
     if (!truncated) {
       if (files) {
         for (S3ObjectSummary summary : listing.getObjectSummaries()) {
           String key = summary.getKey();
           if (!key.endsWith("_SUCCESS")) {
             result.add(key);
           }
         }
       } else {
         for (String key : listing.getCommonPrefixes()) {
           if (!key.endsWith("_SUCCESS")) {
             result.add(key);
           }
         }
       }
     }
   }
   Collections.sort(result);
   return result;
 }
예제 #4
0
 private Iterator<LocatedFileStatus> statusFromListing(ObjectListing listing) {
   return Iterators.concat(
       statusFromPrefixes(listing.getCommonPrefixes()),
       statusFromObjects(listing.getObjectSummaries()));
 }