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


Java ObjectListing.getNextMarker方法代碼示例

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


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

示例1: 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);
}
 
開發者ID:XiaoMi,項目名稱:galaxy-fds-migration-tool,代碼行數:17,代碼來源:S3Source.java

示例2: getAllSummaries

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的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;
}
 
開發者ID:aol,項目名稱:micro-server,代碼行數:23,代碼來源:S3Utils.java

示例3: s3DeleteRecursively

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的package包/類
public static void s3DeleteRecursively(AmazonS3 s3, String bucket, String prefix)
        throws Exception
{
    ListObjectsRequest request = new ListObjectsRequest()
            .withBucketName(bucket)
            .withPrefix(prefix);

    while (true) {
        ObjectListing listing = s3.listObjects(request);
        String[] keys = listing.getObjectSummaries().stream().map(S3ObjectSummary::getKey).toArray(String[]::new);
        for (String key : keys) {
            logger.info("delete s3://{}/{}", bucket, key);
        }
        retryExecutor()
                .retryIf(e -> e instanceof AmazonServiceException)
                .run(() -> s3.deleteObjects(new DeleteObjectsRequest(bucket).withKeys(keys)));
        if (listing.getNextMarker() == null) {
            break;
        }
    }
}
 
開發者ID:treasure-data,項目名稱:digdag,代碼行數:22,代碼來源:TestUtils.java

示例4: doExecute

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的package包/類
@Override
protected void doExecute(Parameters config, Parameters output) {
  String bucketName = this.readAsString(config, "aws.s3.bucketName", null, false, "aws.s3.bucketName not present in config");
  String prefix = this.readAsString(config, "aws.s3.list.prefix", null, false, "aws.s3.list.prefix not present");
  
  AmazonS3 client = new AmazonS3Client(AwsUtils.getCredentialProviderC(config), AwsUtils.getClientConfig(config));
  client.setRegion(AwsUtils.getRegion(config));
  
  ListObjectsRequest listObjectsRequest =
      new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);

  List<S3ObjectSummary> summarys = new ArrayList<S3ObjectSummary>();
  ObjectListing objectListing;
  do {
    objectListing = client.listObjects(listObjectsRequest);
    summarys.addAll(objectListing.getObjectSummaries());
    String marker = objectListing.getNextMarker();
    listObjectsRequest.setMarker(marker);
    
    Detective.info("Reading from S3...current marker:" + marker + " Continue..." );
  } while (objectListing.isTruncated());
  
  output.put("s3ObjectSummaries", summarys);
}
 
開發者ID:detectiveframework,項目名稱:detective,代碼行數:25,代碼來源:S3ListTask.java

示例5: list

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的package包/類
private List<S3ObjectSummary> list(Optional<String> marker) {
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
            .withBucketName(bucket)
            .withPrefix(prefix);

    marker.ifPresent(listObjectsRequest::withMarker);

    ObjectListing objectListing = s3Client.listObjects(listObjectsRequest);

    if (objectListing.getObjectSummaries().size() == 0) {
        return Lists.newArrayList();
    }

    List<S3ObjectSummary> collect = objectListing.getObjectSummaries().stream()
            .filter(summary -> summary.getLastModified().getTime() > (System.currentTimeMillis() - notOlderThanTimeUnit.toMillis(notOlderThanValue)))
            .filter(summary -> summary.getKey().endsWith(suffix))
            .collect(Collectors.toList());

    if (collect.size() > 0) {
        return collect;
    } else if (objectListing.getNextMarker() != null) {
        LOGGER.debug("Getting next page with marker {}", objectListing.getNextMarker());
        return list(Optional.of(objectListing.getNextMarker()));
    } else {
        return Lists.newArrayList();
    }
}
 
開發者ID:sonyxperiadev,項目名稱:lumber-mill,代碼行數:28,代碼來源:S3ScheduledPoll.java

示例6: listTables

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的package包/類
/**
 * Gets all tables available in this stash.
 */
public Iterator<StashTable> listTables() {
    final String root = getRootPath();
    final String prefix = String.format("%s/", root);

    return new AbstractIterator<StashTable>() {
        Iterator<String> _commonPrefixes = Iterators.emptyIterator();
        String _marker = null;
        boolean _truncated = true;

        @Override
        protected StashTable computeNext() {
            String dir = null;

            while (dir == null) {
                if (_commonPrefixes.hasNext()) {
                    dir = _commonPrefixes.next();
                    if (dir.isEmpty()) {
                        // Ignore the empty directory if it comes back
                        dir = null;
                    } else {
                        // Strip the prefix and trailing "/"
                        dir = dir.substring(prefix.length(), dir.length()-1);
                    }
                } else if (_truncated) {
                    ObjectListing response = _s3.listObjects(new ListObjectsRequest()
                            .withBucketName(_bucket)
                            .withPrefix(prefix)
                            .withDelimiter("/")
                            .withMarker(_marker)
                            .withMaxKeys(1000));

                    _commonPrefixes = response.getCommonPrefixes().iterator();
                    _marker = response.getNextMarker();
                    _truncated = response.isTruncated();
                } else {
                    return endOfData();
                }
            }

            String tablePrefix = prefix + dir + "/";
            String tableName = StashUtil.decodeStashTable(dir);
            return new StashTable(_bucket, tablePrefix, tableName);
        }
    };
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:49,代碼來源:StashReader.java

示例7: listTableMetadata

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的package包/類
/**
 * Gets the metadata for all tables in this stash.  This is a heavier operation that just {@link #listTables()}
 * since it also returns full file details for the entire Stash instead of just table names.
 */
public Iterator<StashTableMetadata> listTableMetadata() {
    final String root = getRootPath();
    final String prefix = String.format("%s/", root);
    final int prefixLength = prefix.length();

    return new AbstractIterator<StashTableMetadata>() {
        PeekingIterator<S3ObjectSummary> _listResponse =
                Iterators.peekingIterator(Iterators.<S3ObjectSummary>emptyIterator());
        String _marker = null;
        boolean _truncated = true;

        @Override
        protected StashTableMetadata computeNext() {
            String tableDir = null;
            List<StashFileMetadata> files = Lists.newArrayListWithCapacity(16);
            boolean allFilesRead = false;

            while (!allFilesRead) {
                if (_listResponse.hasNext()) {
                    // Peek at the next record but don't consume it until we verify it's part of the same table
                    S3ObjectSummary s3File = _listResponse.peek();
                    String key = s3File.getKey();

                    // Don't include the _SUCCESS file or any other stray files we may find
                    String[] parentDirAndFile = key.substring(prefixLength).split("/");
                    if (parentDirAndFile.length != 2) {
                        // Consume and skip this row
                        _listResponse.next();
                    } else {
                        String parentDir = parentDirAndFile[0];
                        if (tableDir == null) {
                            tableDir = parentDir;
                        }

                        if (!parentDir.equals(tableDir)) {
                            allFilesRead = true;
                        } else {
                            // Record is part of this table; consume it now
                            _listResponse.next();
                            files.add(new StashFileMetadata(_bucket, key, s3File.getSize()));
                        }
                    }
                } else if (_truncated) {
                    ObjectListing response = _s3.listObjects(new ListObjectsRequest()
                            .withBucketName(_bucket)
                            .withPrefix(prefix)
                            .withMarker(_marker)
                            .withMaxKeys(1000));

                    _listResponse = Iterators.peekingIterator(response.getObjectSummaries().iterator());
                    _marker = response.getNextMarker();
                    _truncated = response.isTruncated();
                } else {
                    allFilesRead = true;
                }
            }

            if (tableDir == null) {
                // No files read this iteration means all files have been read
                return endOfData();
            }

            String tablePrefix = prefix + tableDir + "/";
            String tableName = StashUtil.decodeStashTable(tableDir);
            return new StashTableMetadata(_bucket, tablePrefix, tableName, files);
        }
    };
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:73,代碼來源:StashReader.java

示例8: poll

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的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

示例9: 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;
}
 
開發者ID:rholder,項目名稱:esthree,代碼行數:42,代碼來源:Ls.java

示例10: scanBucket

import com.amazonaws.services.s3.model.ObjectListing; //導入方法依賴的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

示例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);
    }
 
開發者ID:emersonf,項目名稱:binary-diff,代碼行數:44,代碼來源:AmazonS3DirectoryMetadataServiceImpl.java


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