當前位置: 首頁>>代碼示例>>Java>>正文


Java ListObjectsRequest.setMaxKeys方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.ListObjectsRequest.setMaxKeys方法的典型用法代碼示例。如果您正苦於以下問題:Java ListObjectsRequest.setMaxKeys方法的具體用法?Java ListObjectsRequest.setMaxKeys怎麽用?Java ListObjectsRequest.setMaxKeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.model.ListObjectsRequest的用法示例。


在下文中一共展示了ListObjectsRequest.setMaxKeys方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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();
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:17,代碼來源:S3Objects.java

示例2: shouldListObjectWithMaxKeysLimit

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
@Test
public void shouldListObjectWithMaxKeysLimit() throws IOException {
    // Given
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucketName);
    request.setPrefix("COUNTRY_BY_DATE/2014/");
    request.setMaxKeys(2);

    // When
    Observable<ObjectListing> listing = client.listObjects(request);
    ObjectListing amazonListing = amazonS3Client.listObjects(request);

    // Then
    assertThat(listing)
            .ignoreFields(fieldsToIgnore)
            .isEqualTo(amazonListing)
            .isTruncated()
            .hasSize(2);
}
 
開發者ID:codewise,項目名稱:RxS3,代碼行數:20,代碼來源:AsyncS3ClientTest.java

示例3: shouldListObjectBatchesWhenUsingRequest

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
@Test
public void shouldListObjectBatchesWhenUsingRequest() throws IOException {
    // Given
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucketName);
    request.setMaxKeys(2);
    request.setPrefix("COUNTRY_BY_DATE/2014/");

    // When & Then
    Observable<ObjectListing> listing = client.listObjects(request);
    ObjectListing amazonListing = amazonS3Client.listObjects(request);

    while (amazonListing.isTruncated()) {
        assertThat(listing)
                .ignoreFields(fieldsToIgnore)
                .isEqualTo(amazonListing);

        listing = client.listNextBatchOfObjects(listing.toBlocking().single());
        amazonListing = amazonS3Client.listNextBatchOfObjects(amazonListing);
    }

    assertThat(listing)
            .ignoreFields(fieldsToIgnore)
            .isEqualTo(amazonListing)
            .isNotTruncated();
}
 
開發者ID:codewise,項目名稱:RxS3,代碼行數:27,代碼來源:AsyncS3ClientTest.java

示例4: shouldListCommonPrefixesInBatches_ContainingFiles

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
@Test
public void shouldListCommonPrefixesInBatches_ContainingFiles() throws IOException {
    // Given
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucketName);
    request.setPrefix("COUNTRY_BY_DATE/2014/05/");
    request.setMaxKeys(1);
    request.setDelimiter("/");

    // When
    ObjectListing amazonListing = amazonS3Client.listObjects(request);
    Observable<ObjectListing> listing = client.listObjects(request);

    // Then
    while (amazonListing.isTruncated()) {
        ObjectListing objectListing = listing.toBlocking().single();

        assertThat(objectListing)
                .ignoreFields(fieldsToIgnore)
                .isEqualTo(amazonListing)
                .isTruncated();

        amazonListing = amazonS3Client.listNextBatchOfObjects(amazonListing);
        listing = client.listNextBatchOfObjects(objectListing);
    }

    assertThat(listing)
            .ignoreFields(fieldsToIgnore)
            .isEqualTo(amazonListing)
            .isNotTruncated();
}
 
開發者ID:codewise,項目名稱:RxS3,代碼行數:32,代碼來源:AsyncS3ClientTest.java

示例5: shouldListCommonPrefixesInBatches_ContainingDirectories

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
@Test
public void shouldListCommonPrefixesInBatches_ContainingDirectories() throws IOException {
    // Given
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucketName);
    request.setPrefix("COUNTRY_BY_DATE/2014/");
    request.setMaxKeys(1);
    request.setDelimiter("/");

    // When
    Observable<ObjectListing> listing = client.listObjects(request);
    ObjectListing amazonListing = amazonS3Client.listObjects(request);

    // Then
    while (amazonListing.isTruncated()) {
        ObjectListing objectListing = listing.toBlocking().single();

        assertThat(objectListing)
                .ignoreFields(fieldsToIgnore)
                .isEqualTo(amazonListing)
                .isTruncated();

        amazonListing = amazonS3Client.listNextBatchOfObjects(amazonListing);
        listing = client.listNextBatchOfObjects(objectListing);
    }

    assertThat(listing)
            .ignoreFields(fieldsToIgnore)
            .isEqualTo(amazonListing)
            .isNotTruncated();
}
 
開發者ID:codewise,項目名稱:RxS3,代碼行數:32,代碼來源:AsyncS3ClientTest.java

示例6: poll

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
@Override
protected int poll() throws Exception {
    // must reset for each poll
    shutdownRunningTask = null;
    pendingExchanges = 0;
    
    String fileName = getConfiguration().getFileName();
    String bucketName = getConfiguration().getBucketName();
    Queue<Exchange> exchanges;
    
    if (fileName != null) {
        LOG.trace("Getting object in bucket [{}] with file name [{}]...", bucketName, fileName);

        S3Object s3Object = getAmazonS3Client().getObject(new GetObjectRequest(bucketName, fileName));
        exchanges = createExchanges(s3Object);
    } else {
        LOG.trace("Queueing objects in bucket [{}]...", bucketName);

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
        listObjectsRequest.setBucketName(bucketName);
        listObjectsRequest.setPrefix(getConfiguration().getPrefix());
        if (maxMessagesPerPoll > 0) {
            listObjectsRequest.setMaxKeys(maxMessagesPerPoll);
        }
        // if there was a marker from previous poll then use that to continue from where we left last time
        if (marker != null) {
            LOG.trace("Resuming from marker: {}", marker);
            listObjectsRequest.setMarker(marker);
        }

        ObjectListing listObjects = getAmazonS3Client().listObjects(listObjectsRequest);
        if (listObjects.isTruncated()) {
            marker = listObjects.getNextMarker();
            LOG.trace("Returned list is truncated, so setting next marker: {}", marker);
        } else {
            // no more data so clear marker
            marker = null;
        }
        if (LOG.isTraceEnabled()) {
            LOG.trace("Found {} objects in bucket [{}]...", listObjects.getObjectSummaries().size(), bucketName);
        }

        exchanges = createExchanges(listObjects.getObjectSummaries());
    }
    return processBatch(CastUtils.cast(exchanges));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:47,代碼來源:S3Consumer.java

示例7: listObjectsLexicographically

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
/**
 * Lists objects from AmazonS3 in lexicographical order
 *
 * @param s3Client
 * @param s3ConfigBean
 * @param pathMatcher glob patterns to match file name against
 * @param s3Offset current offset which provides the key name of the previous object
 * @param fetchSize number of objects to fetch in one go
 * @return
 * @throws AmazonClientException
 */
static List<S3ObjectSummary> listObjectsLexicographically(
    AmazonS3 s3Client,
    S3ConfigBean s3ConfigBean,
    AntPathMatcher pathMatcher,
    AmazonS3Source.S3Offset s3Offset,
    int fetchSize
) {
  // Incrementally scan objects after the marker (s3Offset).
  List<S3ObjectSummary> list = new ArrayList<>(fetchSize);

  ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
  listObjectsRequest.setBucketName(s3ConfigBean.s3Config.bucket);
  listObjectsRequest.setPrefix(s3ConfigBean.s3Config.commonPrefix);
  listObjectsRequest.setMaxKeys(BATCH_SIZE);
  if (s3Offset.getKey() != null) {
    listObjectsRequest.setMarker(s3Offset.getKey());
  }

  ObjectListing objectListing = s3Client.listObjects(listObjectsRequest);

  while (true) {
    for (S3ObjectSummary s : objectListing.getObjectSummaries()) {
      String fullPrefix = s.getKey();
      String remainingPrefix = fullPrefix.substring(s3ConfigBean.s3Config.commonPrefix.length(), fullPrefix.length());
      if (!remainingPrefix.isEmpty()) {
        if (pathMatcher.match(s3ConfigBean.s3FileConfig.prefixPattern, remainingPrefix)) {
          list.add(s);
        }
        // We've got enough objects.
        if (list.size() == fetchSize) {
          return list;
        }
      }
    }
    // Listing is complete. No more objects to be listed.
    if (!objectListing.isTruncated()) {
      break;
    }
    objectListing = s3Client.listNextBatchOfObjects(objectListing);
  }

  return list;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:55,代碼來源:AmazonS3Util.java

示例8: calculateSize

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
/**
 * Calculate the total size of all objects in the indicated bucket
 *
 * @param path to use
 * @return calculated size
 * @throws IOException
 */
@Override
public long calculateSize(Path path) throws IOException {
  long totalBucketSize = 0L;

  if (s3Enabled) {
    String key = pathToKey(path);

    final FileStatus fileStatus =  fs.getFileStatus(path);

    if (fileStatus.isDirectory()) {
      if (!key.isEmpty()) {
        key = key + "/";
      }

      ListObjectsRequest request = new ListObjectsRequest();
      request.setBucketName(uri.getHost());
      request.setPrefix(key);
      request.setMaxKeys(maxKeys);

      if (LOG.isDebugEnabled()) {
        LOG.debug("listStatus: doing listObjects for directory " + key);
      }

      ObjectListing objects = s3.listObjects(request);

      while (true) {
        for (S3ObjectSummary summary : objects.getObjectSummaries()) {
          Path keyPath = keyToPath(summary.getKey()).makeQualified(uri, fs.getWorkingDirectory());

          // Skip over keys that are ourselves and old S3N _$folder$ files
          if (keyPath.equals(path) || summary.getKey().endsWith(S3N_FOLDER_SUFFIX)) {
            if (LOG.isDebugEnabled()) {
              LOG.debug("Ignoring: " + keyPath);
            }
            continue;
          }

          if (!objectRepresentsDirectory(summary.getKey(), summary.getSize())) {
            totalBucketSize += summary.getSize();
          }
        }

        if (objects.isTruncated()) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("listStatus: list truncated - getting next batch");
          }
          objects = s3.listNextBatchOfObjects(objects);
        } else {
          break;
        }
      }
    } else {
      return fileStatus.getLen();
    }
  } else {
    totalBucketSize = fs.getContentSummary(path).getLength();
  }

  return totalBucketSize;
}
 
開發者ID:apache,項目名稱:tajo,代碼行數:68,代碼來源:S3TableSpace.java

示例9: scanBucket

import com.amazonaws.services.s3.model.ListObjectsRequest; //導入方法依賴的package包/類
private void scanBucket(Set<TocInfo> toc, Queue<TocInfo> tocQueue) throws Exception {
	
	ListObjectsRequest listRequest = new ListObjectsRequest();
	listRequest.setBucketName(s3BucketName);
	// listRequest.setGeneralProgressListener(this);
	listRequest.setMaxKeys(1000);
	
	String nextMarker = null;
	ObjectListing objectListing = null;
	
	while(true) {
		
		objectListing = s3Client.listObjects(listRequest);
		
		List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
		
		for (S3ObjectSummary objSummary : objectSummaries) {
			String key = objSummary.getKey();
			
			TocInfo tocInfo = new TocInfo(key, objSummary.getSize());
			
			// is it a "dir/" ?
			if (key.lastIndexOf("/") == (key.length() - 1)) {
				tocInfo.isDirectory = true;
			} else {
				tocInfo.isDirectory = false;
			}
			
			toc.add(tocInfo);
			tocQueue.add(tocInfo);
			tocInfosGenerated++; // increment for logging

		}
		
		// for pagination
		nextMarker = objectListing.getNextMarker();
		if (nextMarker == null) {
			break;
		} else {
			listRequest.setMarker(nextMarker);
			logger.debug("scanBucket() nextMarker we will request listing for => " + nextMarker);
		}
	}
	
}
 
開發者ID:bitsofinfo,項目名稱:s3-bucket-loader,代碼行數:46,代碼來源:S3BucketObjectLister.java


注:本文中的com.amazonaws.services.s3.model.ListObjectsRequest.setMaxKeys方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。