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

Java ObjectTagging类代码示例

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

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



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

示例1: urlEncodeTags

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
private String urlEncodeTags(ObjectTagging tagging) {
    if (tagging == null || tagging.getTagSet() == null) return null;

    StringBuilder sb = new StringBuilder();

    Iterator<Tag> tagIter = tagging.getTagSet().iterator();
    while (tagIter.hasNext()) {
        Tag tag = tagIter.next();
        sb.append(SdkHttpUtils.urlEncode(tag.getKey(), false)).append('=').append(SdkHttpUtils.urlEncode(tag.getValue(), false));
        if (tagIter.hasNext()) {
            sb.append("&");
        }
    }

    return sb.toString();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:17,代码来源:AmazonS3Client.java


示例2: testTagObjectsOtherTagKeyAlreadyExists

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
@Test
public void testTagObjectsOtherTagKeyAlreadyExists()
{
    // Create two S3 object tags having different tag keys.
    List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY_2, S3_OBJECT_TAG_VALUE_2));

    // Put a file in S3 that is already tagged with the first S3 object tag.
    PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata());
    putObjectRequest.setTagging(new ObjectTagging(Arrays.asList(tags.get(0))));
    s3Operations.putObject(putObjectRequest, null);

    // Validate that the S3 object is tagged with the first tag only.
    GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null);
    assertEquals(Arrays.asList(tags.get(0)), getObjectTaggingResult.getTagSet());

    // Tag the S3 file with the second S3 object tag.
    S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
    params.setS3BucketName(S3_BUCKET_NAME);
    params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
    s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), tags.get(1));

    // Validate that the S3 object is now tagged with both tags.
    getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null);
    assertEquals(tags.size(), getObjectTaggingResult.getTagSet().size());
    assertTrue(getObjectTaggingResult.getTagSet().containsAll(tags));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:27,代码来源:S3DaoTest.java


示例3: testTagObjectsTargetTagKeyAlreadyExists

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
@Test
public void testTagObjectsTargetTagKeyAlreadyExists()
{
    // Create two S3 object tags having the same tag key.
    List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE_2));

    // Put a file in S3 that is already tagged with the first S3 object tag.
    PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata());
    putObjectRequest.setTagging(new ObjectTagging(Arrays.asList(tags.get(0))));
    s3Operations.putObject(putObjectRequest, null);

    // Validate that the S3 object is tagged with the first tag.
    GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null);
    assertEquals(Arrays.asList(tags.get(0)), getObjectTaggingResult.getTagSet());

    // Tag the S3 file with the second S3 object tag.
    S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto();
    params.setS3BucketName(S3_BUCKET_NAME);
    params.setFiles(Arrays.asList(new File(TARGET_S3_KEY)));
    s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), tags.get(1));

    // Validate that the S3 object is tagged with the second tag now.
    getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null);
    assertEquals(Arrays.asList(tags.get(1)), getObjectTaggingResult.getTagSet());
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:26,代码来源:S3DaoTest.java


示例4: changeExistingObject

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
private void changeExistingObject(
  Record record,
  ELVars variables,
  String bucket,
  String objectPath
) throws OnRecordErrorException {
  // Tag application
  if(!config.taskConfig.tags.isEmpty()) {
    List<Tag> newTags = new ArrayList<>();

    // Evaluate each tag separately
    for (Map.Entry<String, String> entry : config.taskConfig.tags.entrySet()) {
      newTags.add(new Tag(
        evaluate(record, "tags", variables, entry.getKey()),
        evaluate(record, "tags", variables, entry.getValue())
      ));
    }

    // Apply all tags at once
    config.s3Config.getS3Client().setObjectTagging(new SetObjectTaggingRequest(
      bucket,
      objectPath,
      new ObjectTagging(newTags)
    ));
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:AmazonS3Executor.java


示例5: convertToXmlByteArray

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
public byte[] convertToXmlByteArray(ObjectTagging tagging) {
    XmlWriter writer = new XmlWriter();
    writer.start("Tagging").start("TagSet");
    for (Tag tag : tagging.getTagSet()) {
        writer.start("Tag");
        writer.start("Key").value(tag.getKey()).end();
        writer.start("Value").value(tag.getValue()).end();
        writer.end(); // </Tag>
    }
    writer.end(); // </TagSet>
    writer.end(); // </Tagging>

    return writer.getBytes();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:ObjectTaggingXmlFactory.java


示例6: process

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
@Override
public void process(List<Label> labels, String path) {
    Processor.PathSplit components = new Processor.PathSplit(path);
    String bucket = components.bucket;
    String key = components.key;

    // fetch the current set
    GetObjectTaggingResult tagging = s3.getObjectTagging(new GetObjectTaggingRequest(bucket, key));
    List<Tag> origTags = tagging.getTagSet();
    List<Tag> updateTags = new ArrayList<>();

    // copy the existing tags, but drop the ones matched by prefix (∴ leaves non-Rekognition label tags alone)
    for (Tag tag : origTags) {
        if (!tag.getKey().startsWith(tagPrefix))
            updateTags.add(tag);
    }
    
    // add the new ones
    for (Label label : labels) {
        if (updateTags.size() < maxTags)
            updateTags.add(new Tag(tagPrefix + label.getName(), label.getConfidence().toString()));
        else
            break;
    }

    // save it back
    s3.setObjectTagging(new SetObjectTaggingRequest(bucket, key, new ObjectTagging(updateTags)));
}
 
开发者ID:jhy,项目名称:RekognitionS3Batch,代码行数:29,代码来源:S3ObjectTagger.java


示例7: withDeletedTag

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
SetObjectTaggingRequest withDeletedTag(final String key) {
  return new SetObjectTaggingRequest(
      getConfiguredBucket(),
      key,
      new ObjectTagging(singletonList(DELETED_TAG))
  );
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:8,代码来源:S3BlobStore.java


示例8: delete

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
@Override
@Guarded(by = STARTED)
public boolean delete(final BlobId blobId, String reason) {
  checkNotNull(blobId);

  final S3Blob blob = liveBlobs.getUnchecked(blobId);

  Lock lock = blob.lock();
  try {
    log.debug("Soft deleting blob {}", blobId);

    S3BlobAttributes blobAttributes = new S3BlobAttributes(s3, getConfiguredBucket(), attributePath(blobId).toString());

    boolean loaded = blobAttributes.load();
    if (!loaded) {
      // This could happen under some concurrent situations (two threads try to delete the same blob)
      // but it can also occur if the deleted index refers to a manually-deleted blob.
      log.warn("Attempt to mark-for-delete non-existent blob {}", blobId);
      return false;
    }
    else if (blobAttributes.isDeleted()) {
      log.debug("Attempt to delete already-deleted blob {}", blobId);
      return false;
    }

    blobAttributes.setDeleted(true);
    blobAttributes.setDeletedReason(reason);
    blobAttributes.store();

    // set "deleted=true" tag on the object, let S3 take care of deleting the blob after it expires
    s3.setObjectTagging(
        new SetObjectTaggingRequest(
            getConfiguredBucket(),
            contentPath(blobId),
            new ObjectTagging(Arrays.asList(DELETED_TAG))
        )
    );
    blob.markStale();

    return true;
  }
  catch (Exception e) {
    throw new BlobStoreException(e, blobId);
  }
  finally {
    lock.unlock();
  }
}
 
开发者ID:sonatype,项目名称:nexus-blobstore-s3,代码行数:49,代码来源:S3BlobStore.java


示例9: populateRequestWithCopyObjectParameters

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
/**
 * <p>
 * Populates the specified request with the numerous options available in
 * <code>CopyObjectRequest</code>.
 * </p>
 *
 * @param request
 *            The request to populate with headers to represent all the
 *            options expressed in the <code>CopyObjectRequest</code> object.
 * @param copyObjectRequest
 *            The object containing all the options for copying an object in
 *            Amazon S3.
 */
private void populateRequestWithCopyObjectParameters(Request<? extends AmazonWebServiceRequest> request, CopyObjectRequest copyObjectRequest) {
    String copySourceHeader =
         "/" + SdkHttpUtils.urlEncode(copyObjectRequest.getSourceBucketName(), true)
       + "/" + SdkHttpUtils.urlEncode(copyObjectRequest.getSourceKey(), true);
    if (copyObjectRequest.getSourceVersionId() != null) {
        copySourceHeader += "?versionId=" + copyObjectRequest.getSourceVersionId();
    }
    request.addHeader("x-amz-copy-source", copySourceHeader);

    addDateHeader(request, Headers.COPY_SOURCE_IF_MODIFIED_SINCE,
            copyObjectRequest.getModifiedSinceConstraint());
    addDateHeader(request, Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE,
            copyObjectRequest.getUnmodifiedSinceConstraint());

    addStringListHeader(request, Headers.COPY_SOURCE_IF_MATCH,
            copyObjectRequest.getMatchingETagConstraints());
    addStringListHeader(request, Headers.COPY_SOURCE_IF_NO_MATCH,
            copyObjectRequest.getNonmatchingETagConstraints());

    if (copyObjectRequest.getAccessControlList() != null) {
        addAclHeaders(request, copyObjectRequest.getAccessControlList());
    } else if (copyObjectRequest.getCannedAccessControlList() != null) {
        request.addHeader(Headers.S3_CANNED_ACL,
                copyObjectRequest.getCannedAccessControlList().toString());
    }

    if (copyObjectRequest.getStorageClass() != null) {
        request.addHeader(Headers.STORAGE_CLASS, copyObjectRequest.getStorageClass());
    }

    if (copyObjectRequest.getRedirectLocation() != null) {
        request.addHeader(Headers.REDIRECT_LOCATION, copyObjectRequest.getRedirectLocation());
    }

    populateRequesterPaysHeader(request, copyObjectRequest.isRequesterPays());

    ObjectMetadata newObjectMetadata = copyObjectRequest.getNewObjectMetadata();
    if (newObjectMetadata != null) {
        request.addHeader(Headers.METADATA_DIRECTIVE, "REPLACE");
        populateRequestMetadata(request, newObjectMetadata);
    }

    ObjectTagging newObjectTagging = copyObjectRequest.getNewObjectTagging();
    if (newObjectTagging != null) {
        request.addHeader(Headers.TAGGING_DIRECTIVE, "REPLACE");
        request.addHeader(Headers.S3_TAGGING, urlEncodeTags(newObjectTagging));
    }

    // Populate the SSE-C parameters for the destination object
    populateSourceSSE_C(request, copyObjectRequest.getSourceSSECustomerKey());
    populateSSE_C(request, copyObjectRequest.getDestinationSSECustomerKey());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:66,代码来源:AmazonS3Client.java


示例10: tagObjects

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
@Override
public void tagObjects(final S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto, final S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto,
    final Tag tag)
{
    LOGGER.info("Tagging objects in S3... s3BucketName=\"{}\" s3KeyCount={} s3ObjectTagKey=\"{}\" s3ObjectTagValue=\"{}\"",
        s3FileTransferRequestParamsDto.getS3BucketName(), s3FileTransferRequestParamsDto.getFiles().size(), tag.getKey(), tag.getValue());

    if (!CollectionUtils.isEmpty(s3FileTransferRequestParamsDto.getFiles()))
    {
        // Initialize a key value pair for the error message in the catch block.
        String s3Key = s3FileTransferRequestParamsDto.getFiles().get(0).getPath().replaceAll("\\\\", "/");

        // Amazon S3 client to access S3 objects.
        AmazonS3Client s3Client = null;

        // Amazon S3 client for S3 object tagging.
        AmazonS3Client s3ObjectTaggerClient = null;

        try
        {
            // Create an S3 client to access S3 objects.
            s3Client = getAmazonS3(s3FileTransferRequestParamsDto);

            // Create an S3 client for S3 object tagging.
            s3ObjectTaggerClient = getAmazonS3(s3ObjectTaggerParamsDto);

            // Create a get object tagging request.
            GetObjectTaggingRequest getObjectTaggingRequest = new GetObjectTaggingRequest(s3FileTransferRequestParamsDto.getS3BucketName(), null);

            // Create a restore object request.
            SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(s3FileTransferRequestParamsDto.getS3BucketName(), null, null);

            for (File file : s3FileTransferRequestParamsDto.getFiles())
            {
                // Prepare an S3 key.
                s3Key = file.getPath().replaceAll("\\\\", "/");

                // Retrieve the current tagging information for the S3 key.
                getObjectTaggingRequest.setKey(s3Key);
                GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(getObjectTaggingRequest, s3Client);

                // Update the list of tags to include the specified S3 object tag.
                List<Tag> updatedTags = new ArrayList<>();
                updatedTags.add(tag);
                if (CollectionUtils.isNotEmpty(getObjectTaggingResult.getTagSet()))
                {
                    for (Tag currentTag : getObjectTaggingResult.getTagSet())
                    {
                        if (!StringUtils.equals(tag.getKey(), currentTag.getKey()))
                        {
                            updatedTags.add(currentTag);
                        }
                    }
                }

                // Update the tagging information.
                setObjectTaggingRequest.setKey(s3Key);
                setObjectTaggingRequest.setTagging(new ObjectTagging(updatedTags));
                s3Operations.setObjectTagging(setObjectTaggingRequest, s3ObjectTaggerClient);
            }
        }
        catch (Exception e)
        {
            throw new IllegalStateException(String
                .format("Failed to tag S3 object with \"%s\" key in \"%s\" bucket. Reason: %s", s3Key, s3FileTransferRequestParamsDto.getS3BucketName(),
                    e.getMessage()), e);
        }
        finally
        {
            if (s3Client != null)
            {
                s3Client.shutdown();
            }

            if (s3ObjectTaggerClient != null)
            {
                s3ObjectTaggerClient.shutdown();
            }
        }
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:82,代码来源:S3DaoImpl.java


示例11: provideObjectTags

import com.amazonaws.services.s3.model.ObjectTagging; //导入依赖的package包/类
/**
 * This method is called for every file that is uploaded by <code>TransferManager</code>
 * and gives an opportunity to specify the tags for the file.
 *
 * @param uploadContext
 *          The context object providing information about the file being uploaded.
 *
 * @return ObjectTagging
 *          The ObjectTagging to be used in the PutObjectRequest withTagging call.
 *
 */
public ObjectTagging provideObjectTags(UploadContext uploadContext);
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:13,代码来源:ObjectTaggingProvider.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Header类代码示例发布时间:2022-05-22
下一篇:
Java DOMSerializer类代码示例发布时间: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