Ejemplo n.º 1
0
  /**
   * Reads next key from S3
   *
   * @return {@link S3ObjectSummary} of the key or <code>null</code> if there are no more keys to
   *     read
   */
  public S3ObjectSummary getNextKey() {
    if (objectListing == null) {
      LOG.debug("Listing objects");
      objectListing = s3Client.listObjects(listObjectsRequest);
    }

    // we have more elements in list
    if (currentPosition < objectListing.getObjectSummaries().size()) {
      currentObject = objectListing.getObjectSummaries().get(currentPosition++);
    } else if (objectListing.isTruncated()) {
      LOG.debug("Current batch reached its end. Fetching next page.");
      // when we're at the end, check if there's more data to read
      listObjectsRequest.setMarker(objectListing.getNextMarker());
      LOG.debug("New marker is set to {}", listObjectsRequest.getMarker());

      objectListing = s3Client.listObjects(listObjectsRequest);
      currentPosition = 0;

      if (currentPosition < objectListing.getObjectSummaries().size()) {
        currentObject = objectListing.getObjectSummaries().get(currentPosition++);
      } else {
        LOG.debug("No more objects to read");
        currentObject = null;
      }
    } else {
      currentObject = null;
    }

    return currentObject;
  }
Ejemplo n.º 2
0
 @Override
 public boolean matches(final Object arg) {
   boolean result = false;
   if (arg instanceof ListObjectsRequest) {
     final ListObjectsRequest obj = (ListObjectsRequest) arg;
     result = true;
     if (!this.bucket.equals(obj.getBucketName())) {
       result = false;
     }
     if (!this.prefix.equals(obj.getPrefix())) {
       result = false;
     }
     if (this.marker == null && obj.getMarker() != null) {
       result = false;
     }
     if (this.marker != null && !this.marker.equals(obj.getMarker())) {
       result = false;
     }
   }
   return result;
 }