• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java S3Objects类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazonaws.services.s3.iterable.S3Objects的典型用法代码示例。如果您正苦于以下问题:Java S3Objects类的具体用法?Java S3Objects怎么用?Java S3Objects使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



S3Objects类属于com.amazonaws.services.s3.iterable包,在下文中一共展示了S3Objects类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getCachedConfigurations

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
public Stream<WriteableConfiguration> getCachedConfigurations() throws IOException {

  Iterable<S3ObjectSummary> objectSummaries = S3Objects.withPrefix(s3, bucket, prefix);
  Stream<S3ObjectSummary> objectStream = StreamSupport.stream(objectSummaries.spliterator(), false);

  return objectStream.map(p -> {
    Integer version = getVersionIfMatch(p.getKey());
    if (version == null) {
      return null;
    }
    return new Pair<>(version, p);
  }).filter(Objects::nonNull)
      .sorted(Comparator.comparing(pair -> ((Pair<Integer, S3ObjectSummary>) pair).getFirst())
            .reversed()).map(pair -> new S3WritableConfiguration(s3, pair.getSecond(), Integer.toString(pair.getFirst())));

}
 
开发者ID:apache,项目名称:nifi-minifi,代码行数:18,代码来源:S3CacheFileInfoImpl.java


示例2: deletePrefix

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
static void deletePrefix(AmazonS3 s3Client, String bucketName, String prefix) {
    List<DeleteObjectsRequest.KeyVersion> trashKeys = new ArrayList<>();
    DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
    for (S3ObjectSummary summary: S3Objects.withPrefix(s3Client, bucketName, prefix)) {
        trashKeys.add(new DeleteObjectsRequest.KeyVersion(summary.getKey()));
        if (trashKeys.size() == BULK_DELETE_SIZE) {
            deleteObjectsRequest.setKeys(trashKeys);
            s3Client.deleteObjects(deleteObjectsRequest);
            trashKeys.clear();
        }
    }
    if (!trashKeys.isEmpty()) {
        deleteObjectsRequest.setKeys(trashKeys);
        s3Client.deleteObjects(deleteObjectsRequest);
    }
}
 
开发者ID:cloudkeeper-project,项目名称:cloudkeeper,代码行数:17,代码来源:S3Utilities.java


示例3: copy

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
protected void copy(RuntimeExecutionTrace source, RuntimeExecutionTrace target,
        RuntimeAnnotatedExecutionTrace absoluteSource, RuntimeAnnotatedExecutionTrace absoluteTarget)
        throws IOException {
    String sourcePrefix = toS3Path(source).getPrefixForChildren();
    String targetPrefix = toS3Path(target).getPrefixForChildren();
    for (S3ObjectSummary summary: S3Objects.withPrefix(s3Client, bucketName, sourcePrefix)) {
        if (summary.getKey().startsWith(sourcePrefix)) {
            String relativeKey = summary.getKey().substring(sourcePrefix.length());
            s3Client.copyObject(bucketName, summary.getKey(), bucketName, targetPrefix + relativeKey);
        } else {
            log.error(String.format(
                "S3Objects.withPrefix() returned unexpected key '%s' when asked for prefix '%s'.",
                summary.getKey(), sourcePrefix
            ));
        }
    }
}
 
开发者ID:cloudkeeper-project,项目名称:cloudkeeper,代码行数:19,代码来源:S3StagingArea.java


示例4: getAllBinaryKeys

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
public Iterable<BinaryKey> getAllBinaryKeys() throws BinaryStoreException {
    try {
        final Iterator<S3ObjectSummary> objectsIterator =
            S3Objects.inBucket(s3Client, bucketName).iterator();
        // Lambda to hand back BinaryKeys rather than S3ObjectSummaries
        return () -> {
            return new Iterator<BinaryKey>() {
                @Override
                public boolean hasNext() {
                    return objectsIterator.hasNext();
                }

                @Override
                public BinaryKey next() {
                    S3ObjectSummary object = objectsIterator.next();
                    return new BinaryKey(object.getKey());
                }
            };
        };
    } catch (AmazonClientException e) {
        throw new BinaryStoreException(e);
    }
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:25,代码来源:S3BinaryStore.java


示例5: createRecordsForWholeFileFromS3

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private static List<Record> createRecordsForWholeFileFromS3() throws Exception {
  Iterator<S3ObjectSummary> s3ObjectSummaryIterator = S3Objects.inBucket(s3client, SOURCE_BUCKET_NAME).iterator();
  List<Record> records = new ArrayList<>();
  while (s3ObjectSummaryIterator.hasNext()) {
    S3ObjectSummary s3ObjectSummary = s3ObjectSummaryIterator.next();
    Map<String, Object> metadata = getS3Metadata(s3client.getObject(SOURCE_BUCKET_NAME, s3ObjectSummary.getKey()));
    Record record = RecordCreator.create();
    record.getHeader().setAttribute("bucket", TARGET_BUCKET_NAME);
    record.set(
        FileRefUtil.getWholeFileRecordRootField(
            new S3FileRef.Builder()
                .s3Client(s3client)
                .s3ObjectSummary(s3ObjectSummary)
                .useSSE(false)
                .verifyChecksum(false)
                .bufferSize(1024)
                .build(),
            metadata
        )
    );
    records.add(record);
  }
  return records;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:25,代码来源:TestAmazonS3TargetForWholeFile.java


示例6: main

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	DeleteBucketRequest deleteBucketRequest=new DeleteBucketRequest(AWSResources.S3_BUCKET_NAME);
	if(AWSResources.S3.doesBucketExist(AWSResources.S3_BUCKET_NAME))
		try {
				AWSResources.S3.deleteBucket(deleteBucketRequest);
				System.out.println("Bucket Deleted...");
		}
	catch (AmazonS3Exception ex) {
		if(!ex.getErrorCode().equals("BucketNotEmpty"))
			throw ex;
	}
	//List<KeyVersion> keys = new ArrayList<KeyVersion>();
	for(S3ObjectSummary obj : S3Objects.withPrefix(AWSResources.S3, AWSResources.S3_BUCKET_NAME, "")) {
    // Add the keys to our list of object.
    AWSResources.S3.deleteObject(AWSResources.S3_BUCKET_NAME, obj.getKey());
	}
	//DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(AWSResources.S3_BUCKET_NAME);
	//AWSResources.S3.deleteObjects(deleteObjectsRequest);
	AWSResources.S3.deleteBucket(deleteBucketRequest);
	if(!AWSResources.S3.doesBucketExist(AWSResources.S3_BUCKET_NAME))
		System.out.println("Deleted");
}
 
开发者ID:snehangshuk,项目名称:aws,代码行数:23,代码来源:DeleteObject.java


示例7: TaxiEventReader

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
public TaxiEventReader(AmazonS3 s3, String bucketName, String prefix) {
  this.s3 = s3;
  this.s3Objects = S3Objects.withPrefix(s3, bucketName, prefix).iterator();

  //initialize next and hasNext fields
  next();
}
 
开发者ID:awslabs,项目名称:flink-stream-processing-refarch,代码行数:8,代码来源:TaxiEventReader.java


示例8: getBlobIdStream

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
public Stream<BlobId> getBlobIdStream() {
  Iterable<S3ObjectSummary> summaries = S3Objects.withPrefix(s3, getConfiguredBucket(), CONTENT_PREFIX);
  return StreamSupport.stream(summaries.spliterator(), false)
    .map(S3ObjectSummary::getKey)
    .map(key -> key.substring(key.lastIndexOf('/') + 1, key.length()))
    .filter(filename -> filename.endsWith(BLOB_ATTRIBUTE_SUFFIX) && !filename.startsWith(TEMPORARY_BLOB_ID_PREFIX))
    .map(filename -> filename.substring(0, filename.length() - BLOB_ATTRIBUTE_SUFFIX.length()))
    .map(BlobId::new);
}
 
开发者ID:sonatype,项目名称:nexus-blobstore-s3,代码行数:11,代码来源:S3BlobStore.java


示例9: getObjectSummary

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
static S3ObjectSummary getObjectSummary(AmazonS3 s3Client, String bucket, String objectKey) {
  S3ObjectSummary s3ObjectSummary = null;
  S3Objects s3ObjectSummaries = S3Objects.withPrefix(s3Client, bucket, objectKey);
  for (S3ObjectSummary s : s3ObjectSummaries) {
    if (s.getKey().equals(objectKey)) {
      s3ObjectSummary = s;
      break;
    }
  }
  return s3ObjectSummary;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:12,代码来源:AmazonS3Util.java


示例10: getObjectCount

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private int getObjectCount(AmazonS3 s3Client, String bucket) {
  int count = 0;
  for(S3ObjectSummary ignored : S3Objects.inBucket(s3Client, bucket)) {
    count++;
  }
  return count;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:8,代码来源:TestAmazonS3Source2.java


示例11: getObjectCount

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private int getObjectCount(AmazonS3 s3Client, String bucket) {
  int count = 0;
  for(S3ObjectSummary s : S3Objects.inBucket(s3Client, bucket)) {
    count++;
  }
  return count;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:8,代码来源:TestAmazonS3SourceDataFormats.java


示例12: getObjectSummaries

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private Map<Pair<String, String>, S3ObjectSummary> getObjectSummaries(AmazonS3 s3Client, String bucket, String prefix) {
  Map<Pair<String, String>, S3ObjectSummary> s3ObjectSummaries = new HashMap<>();
  for(S3ObjectSummary s : S3Objects.withPrefix(s3Client, bucket, prefix)) {
    s3ObjectSummaries.put(Pair.of(bucket, s.getKey()), s);
  }
  return s3ObjectSummaries;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:8,代码来源:TestAmazonS3Source.java


示例13: createBucket

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
public static void createBucket(AmazonS3 s3client, String bucketName) {
  if(s3client.doesBucketExist(bucketName)) {
    for(S3ObjectSummary s : S3Objects.inBucket(s3client, bucketName)) {
      s3client.deleteObject(bucketName, s.getKey());
    }
    s3client.deleteBucket(bucketName);
  }
  Assert.assertFalse(s3client.doesBucketExist(bucketName));
  // Note that CreateBucketRequest does not specify region. So bucket is
  // bucketName
  s3client.createBucket(new CreateBucketRequest(bucketName));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:13,代码来源:TestUtil.java


示例14: verifyAndReturnNoOfObjects

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private int verifyAndReturnNoOfObjects() throws Exception {
  int numberOfObjects = 0;
  for (S3ObjectSummary s3ObjectSummary : S3Objects.inBucket(s3client, TARGET_BUCKET_NAME)) {
    String fileNameOrKey = s3ObjectSummary.getKey();
    if (withFileNamePrefix) {
      //strip out the filePrefix sdc-
      fileNameOrKey = fileNameOrKey.substring(4);
    }
    switch (source) {
      case LOCAL:
        verifyStreamCorrectness(
            new FileInputStream(testDir.getAbsolutePath() + "/" + fileNameOrKey),
            s3client.getObject(TARGET_BUCKET_NAME, s3ObjectSummary.getKey()).getObjectContent()
        );
        break;
      case S3:
        verifyStreamCorrectness(
            s3client.getObject(SOURCE_BUCKET_NAME, fileNameOrKey).getObjectContent(),
            s3client.getObject(TARGET_BUCKET_NAME, s3ObjectSummary.getKey()).getObjectContent()
        );
        break;
    }
    deleteObjectsAfterVerificationInTarget(s3ObjectSummary.getKey());
    numberOfObjects++;
  }
  return numberOfObjects;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:28,代码来源:TestAmazonS3TargetForWholeFile.java


示例15: createsFile

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Test
public void createsFile() {
  List<String> names = newArrayList(
      S3Objects.inBucket(subject.getAmazonS3Client(), "bucket-name").iterator())
      .stream().map(
      S3ObjectSummary::getKey).sorted().collect(Collectors.toList());

  assertThat(names, is(Arrays.asList("fileName", "fileName2")));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:10,代码来源:S3MockRuleTest.java


示例16: start

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
private void start() throws IOException, InterruptedException {
    AmazonS3Client s3Client = new AmazonS3Client();

    S3Objects s3Objects = S3Objects.withPrefix(s3Client, config.getS3Bucket(), config.getS3Key());

    final ElasticWriter elasticWriter = new ElasticWriter(config.getElasticIndexName(), config.getElasticHost(), config.getElasticPort());

    int count = 0;
    for (S3ObjectSummary s3ObjectSummary : s3Objects) {
        s3ObjectSummary.getKey();

        S3Object object = s3Client.getObject(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey());
        log.info("Downloading content of: {}", object.getKey());

        S3ObjectInputStream objectContentStream = object.getObjectContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(objectContentStream));

        String line = null;
        while ((line = reader.readLine()) != null) {
            Scanner scanner = new Scanner(line).useDelimiter("\t");

            String t1 = scanner.next();
            String t2 = scanner.next();
            Integer value = scanner.nextInt();

            elasticWriter.write(t1, t2, value);
            count++;
        }

        log.info("Wrote {} pairs", count);
    }
}
 
开发者ID:FutureProcessing,项目名称:what-should-i-learn-next,代码行数:34,代码来源:PopulateElastic.java


示例17: getBlobIdStream

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
public Stream<BlobId> getBlobIdStream() {
  Iterable<S3ObjectSummary> summaries = S3Objects.withPrefix(s3, getConfiguredBucket(), CONTENT_PREFIX);
  return blobIdStream(summaries);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:6,代码来源:S3BlobStore.java


示例18: getDirectPathBlobIdStream

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
@Override
public Stream<BlobId> getDirectPathBlobIdStream(final String prefix) {
  String subpath = format("%s/%s/%s", CONTENT_PREFIX, DIRECT_PATH_ROOT, prefix);
  Iterable<S3ObjectSummary> summaries = S3Objects.withPrefix(s3, getConfiguredBucket(), subpath);
  return blobIdStream(summaries);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:7,代码来源:S3BlobStore.java


示例19: listObjectsChronologically

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
/**
 * Lists objects from AmazonS3 in chronological order [lexicographical order if 2 files have same timestamp] which are
 * later than or equal to the timestamp of the previous offset object
 *
 * @param s3Client
 * @param s3ConfigBean
 * @param pathMatcher glob patterns to match file name against
 * @param s3Offset current offset which provides the timestamp of the previous object
 * @param fetchSize number of objects to fetch in one go
 * @return
 * @throws AmazonClientException
 */
static List<S3ObjectSummary> listObjectsChronologically(
    AmazonS3 s3Client,
    S3ConfigBean s3ConfigBean,
    AntPathMatcher pathMatcher,
    AmazonS3Source.S3Offset s3Offset,
    int fetchSize
) {

  //Algorithm:
  // - Full scan all objects that match the file name pattern and which are later than the file in the offset
  // - Select the oldest "fetchSize" number of files and return them.
  TreeSet<S3ObjectSummary> treeSet = new TreeSet<>((o1, o2) -> {
    int result = o1.getLastModified().compareTo(o2.getLastModified());
    if(result != 0) {
      //same modified time. Use name to sort
      return result;
    }
    return o1.getKey().compareTo(o2.getKey());
  });

  S3Objects s3ObjectSummaries = S3Objects
    .withPrefix(s3Client, s3ConfigBean.s3Config.bucket, s3ConfigBean.s3Config.commonPrefix)
    .withBatchSize(BATCH_SIZE);
  for (S3ObjectSummary s : s3ObjectSummaries) {
    String fullPrefix = s.getKey();
    String remainingPrefix = fullPrefix.substring(s3ConfigBean.s3Config.commonPrefix.length(), fullPrefix.length());
    if (!remainingPrefix.isEmpty()) {
      // remainingPrefix can be empty.
      // If the user manually creates a prefix "myFolder/mySubFolder" in bucket "myBucket" and uploads "myObject",
      // then the first objects returned here are:
      // myFolder/mySubFolder
      // myFolder/mySubFolder/myObject
      //
      // All is good when pipeline is run but preview returns with no data. So we should ignore the empty file as it
      // has no data
      if (pathMatcher.match(s3ConfigBean.s3FileConfig.prefixPattern, remainingPrefix) && isEligible(s, s3Offset)) {
        treeSet.add(s);
      }
      if (treeSet.size() > fetchSize) {
        treeSet.pollLast();
      }
    }
  }

  return new ArrayList<>(treeSet);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:59,代码来源:AmazonS3Util.java


示例20: main

import com.amazonaws.services.s3.iterable.S3Objects; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	for (S3ObjectSummary summary : S3Objects.withPrefix(AWSResources.S3, AWSResources.S3_BUCKET_NAME, "photos/")) {
		System.out.printf("Object with key '%s'\n", summary.getKey());
	}
}
 
开发者ID:snehangshuk,项目名称:aws,代码行数:6,代码来源:ListFilesInBucket.java



注:本文中的com.amazonaws.services.s3.iterable.S3Objects类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SingleResultCallback类代码示例发布时间:2022-05-22
下一篇:
Java DescribeGlobalSObjectResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap