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


Java Bucket類代碼示例

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


Bucket類屬於com.amazonaws.services.s3.model包,在下文中一共展示了Bucket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createS3BucketIfNotExists

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
public synchronized void createS3BucketIfNotExists(String p_bucket_name) {
    _logger.debug("Searching for bucket " + p_bucket_name);
    if (!s3Client.doesBucketExist(p_bucket_name)) {
        Bucket bucket = s3Client.createBucket(p_bucket_name);
       _logger.info("Created bucket: " + bucket.getName());
    } else {
        _logger.debug("Bucket detected. Verifying permissions.");
        try {
            s3Client.getBucketAcl(p_bucket_name);
        } catch (AmazonClientException ex) {
            _logger.warn("Permission check failed. Randomizing.");
            ConfigFacade.set(Configuration.S3_BUCKET_FORMAT, p_bucket_name + "-" + Security.getRandomHash(8));
            _logger.debug("Reiterating with: " + p_bucket_name);
            createS3BucketIfNotExists(getConfiguredBucketName());
        }
    }
}
 
開發者ID:awslabs,項目名稱:aws-photosharing-example,代碼行數:18,代碼來源:ContentHelper.java

示例2: LambdaConfig

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
private LambdaConfig() {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("env.properties")) {
        this.props.load(is);
        this.repository = new FileRepository(new File(System.getProperty("java.io.tmpdir"), "s3"));
    }
    catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    overwriteWithSystemProperty(ENV_BRANCH);
    overwriteWithSystemProperty(ENV_BUCKET);
    overwriteWithSystemProperty(ENV_GITHUB);

    this.remote = new Remote(Constants.DEFAULT_REMOTE_NAME);
    this.branch = new Branch(props.getProperty(ENV_BRANCH, Constants.MASTER));
    this.authentication = new SecureShellAuthentication(new Bucket(props.getProperty(ENV_BUCKET)), client);
}
 
開發者ID:berlam,項目名稱:github-bucket,代碼行數:17,代碼來源:LambdaConfig.java

示例3: listBuckets

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
@Override
public List<Bucket> listBuckets(ListBucketsRequest listBucketsRequest)
        throws SdkClientException, AmazonServiceException {
    listBucketsRequest = beforeClientExecution(listBucketsRequest);
    rejectNull(listBucketsRequest, "The request object parameter listBucketsRequest must be specified.");
    Request<ListBucketsRequest> request = createRequest(null, null, listBucketsRequest, HttpMethodName.GET);
    
    //Add IBM Service Instance Id to headers
	if ((null != this.awsCredentialsProvider ) && (this.awsCredentialsProvider.getCredentials() instanceof IBMOAuthCredentials)) {
		IBMOAuthCredentials oAuthCreds = (IBMOAuthCredentials)this.awsCredentialsProvider.getCredentials();
		if (oAuthCreds.getServiceInstanceId() != null) {
        	request.addHeader(Headers.IBM_SERVICE_INSTANCE_ID, oAuthCreds.getServiceInstanceId());	
		}
	}
    
    return invoke(request, new Unmarshallers.ListBucketsUnmarshaller(), null, null);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:AmazonS3Client.java

示例4: cleanupFilestore

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
/**
 * Deletes all existing buckets
 */
@After
public void cleanupFilestore() {
  for (final Bucket bucket : s3Client.listBuckets()) {
    if (!INITIAL_BUCKET_NAMES.contains(bucket.getName())) {
      s3Client.listMultipartUploads(new ListMultipartUploadsRequest(bucket.getName()))
          .getMultipartUploads()
          .forEach(upload ->
              s3Client.abortMultipartUpload(
                  new AbortMultipartUploadRequest(bucket.getName(), upload.getKey(),
                      upload.getUploadId()))
          );
      s3Client.deleteBucket(bucket.getName());
    }
  }
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:19,代碼來源:AmazonClientUploadIT.java

示例5: shouldCreateBucketAndListAllBuckets

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
/**
 * Verify that buckets can be created and listed
 */
@Test
public void shouldCreateBucketAndListAllBuckets() {
  // the returned creation date might strip off the millisecond-part, resulting in rounding down
  // and account for a clock-skew in the Docker container of up to a minute.
  final Date creationDate = new Date((System.currentTimeMillis() / 1000) * 1000 - 60000);

  final Bucket bucket = s3Client.createBucket(BUCKET_NAME);
  assertThat(
      String.format("Bucket name should match '%s'!", BUCKET_NAME), bucket.getName(),
      equalTo(BUCKET_NAME));

  final List<Bucket> buckets =
      s3Client.listBuckets().stream().filter(b -> BUCKET_NAME.equals(b.getName()))
          .collect(Collectors.toList());

  assertThat("Expecting one bucket", buckets, hasSize(1));
  final Bucket createdBucket = buckets.get(0);

  assertThat(createdBucket.getCreationDate(), greaterThanOrEqualTo(creationDate));
  final Owner bucketOwner = createdBucket.getOwner();
  assertThat(bucketOwner.getDisplayName(), equalTo("s3-mock-file-store"));
  assertThat(bucketOwner.getId(), equalTo("123"));
}
 
開發者ID:adobe,項目名稱:S3Mock,代碼行數:27,代碼來源:AmazonClientUploadIT.java

示例6: testThatHandlerCanDeriveS3BucketAndGetConfig

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
@Test
public void testThatHandlerCanDeriveS3BucketAndGetConfig() {
    String arn = "arn:aws:lambda:us-west-2:1111111:function:dev-gateway-fas342452-6d86-LambdaWAFBlacklistingFun-1LSORI5GUP95H";
    String bucketName = "dev-cerberusconfigbucket";
    String confJson = "{\n" +
            "  \"manual_white_list_ip_set_id\" : \"11111-a3be-41ee-2222-33f708dd939e\",\n" +
            "  \"manual_black_list_ip_set_id\" : \"11111-569d-4924-22222-33333\",\n" +
            "  \"rate_limit_auto_black_list_ip_set_id\" : \"33333-5195-4b32-44444-71d8fbb9ff4d\",\n" +
            "  \"rate_limit_violation_blacklist_period_in_minutes\" : 10,\n" +
            "  \"request_per_minute_limit\" : 10\n" +
            "}";

    List<Bucket> bucketList = Lists.newLinkedList();
    bucketList.add(new Bucket(bucketName));

    when(amazonS3Client.listBuckets()).thenReturn(bucketList);

    S3Object object = new S3Object();
    object.setObjectContent(new ByteArrayInputStream(confJson.getBytes()));

    when(amazonS3Client.getObject(any())).thenReturn(object);

    CloudFrontLogHandlerConfig config = handler.getConfiguration(arn);

    assertTrue(config.getRequestPerMinuteLimit() == 10);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-serverless-components,代碼行數:27,代碼來源:CloudFrontLogEventHandlerTest.java

示例7: testThatHandlerErrorsWhenWeCantFindTheConfigFile

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
@Test(expected = RuntimeException.class)
public void testThatHandlerErrorsWhenWeCantFindTheConfigFile() {
    String arn = "arn:aws:lambda:us-west-2:1111111:function:dev-gateway-fas342452-6d86-LambdaWAFBlacklistingFun-1LSORI5GUP95H";
    String bucketName = "dev-cerberusconfigbucket";

    List<Bucket> bucketList = Lists.newLinkedList();
    bucketList.add(new Bucket(bucketName));

    AmazonS3Exception e = new AmazonS3Exception("foo");
    e.setErrorCode("NoSuchKey");

    when(amazonS3Client.getObject(any())).thenThrow(e);

    when(amazonS3Client.listBuckets()).thenReturn(bucketList);

    handler.getConfiguration(arn);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-serverless-components,代碼行數:18,代碼來源:CloudFrontLogEventHandlerTest.java

示例8: main

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
public static void main(String[] args)
{
    final String USAGE = "\n" +
        "CreateBucket - create an S3 bucket\n\n" +
        "Usage: CreateBucket <bucketname>\n\n" +
        "Where:\n" +
        "  bucketname - the name of the bucket to create.\n\n" +
        "The bucket name must be unique, or an error will result.\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucket_name = args[0];

    System.out.format("\nCreating S3 bucket: %s\n", bucket_name);
    Bucket b = createBucket(bucket_name);
    if (b == null) {
        System.out.println("Error creating bucket!\n");
    } else {
        System.out.println("Done!\n");
    }
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:25,代碼來源:CreateBucket.java

示例9: findBucket

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
private Optional<String> findBucket(final String environmentName) {
    AmazonS3Client s3Client = new AmazonS3Client();
    List<Bucket> buckets = s3Client.listBuckets();

    String envBucket = null;
    for (final Bucket bucket : buckets) {
        if (StringUtils.contains(bucket.getName(), ConfigConstants.CONFIG_BUCKET_KEY)) {
            String[] parts = bucket.getName().split("-");
            if (StringUtils.equalsIgnoreCase(environmentName, parts[0])) {
                envBucket = bucket.getName();
                break;
            }
        }
    }

    return Optional.ofNullable(envBucket);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:18,代碼來源:CerberusModule.java

示例10: validateBucketName

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
public BucketNameValidationDTO validateBucketName(String bucketName) {
    if (!bucketName.startsWith(enhancedSnapshotBucketPrefix002)) {
        return new BucketNameValidationDTO(false, "Bucket name should start with " + enhancedSnapshotBucketPrefix002);
    }
    if (amazonS3.doesBucketExist(bucketName)) {
        // check whether we own this bucket
        List<Bucket> buckets = amazonS3.listBuckets();
        for (Bucket bucket : buckets) {
            if (bucket.getName().equals(bucketName)) {
                return new BucketNameValidationDTO(true, "");
            }
        }
        return new BucketNameValidationDTO(false, "The requested bucket name is not available.Please select a different name.");
    }
    try {
        BucketNameUtils.validateBucketName(bucketName);
        return new BucketNameValidationDTO(true, "");
    } catch (IllegalArgumentException e) {
        return new BucketNameValidationDTO(false, e.getMessage());
    }
}
 
開發者ID:SungardAS,項目名稱:enhanced-snapshots,代碼行數:22,代碼來源:InitConfigurationServiceImpl.java

示例11: checkNewlyAddedBuckets

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
@Test
public void checkNewlyAddedBuckets() {
    Instant addedTime1 = LocalDateTime.of(2015, 10, 15, 12, 25).toInstant(ZoneOffset.UTC);
    Instant addedTime2 = LocalDateTime.of(2015, 10, 15, 13, 30).toInstant(ZoneOffset.UTC);
    when(clock.instant()).thenReturn(addedTime1, addedTime2);

    s3.createBucket("new_bucket_1");
    s3.createBucket("new_bucket_2");
    List<Bucket> buckets = s3.listBuckets();

    assertThat(buckets).hasSize(2);
    assertThat(getBucketWithName("new_bucket_1", buckets).getCreationDate()).isEqualTo(Date.from(addedTime1));
    assertThat(getBucketWithName("new_bucket_2", buckets).getCreationDate()).isEqualTo(Date.from(addedTime2));

    buckets.forEach(bucket -> {
        Owner owner = bucket.getOwner();
        assertThat(owner.getDisplayName()).isEqualTo("test");
        assertThat(owner.getId()).isNotEmpty();
    });
}
 
開發者ID:OpenG,項目名稱:aws-java-sdk,代碼行數:21,代碼來源:AmazonS3FakeServiceTest.java

示例12: createBucket

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
private static void createBucket(TransferManager tm, String bucketName) throws AmazonClientException {

        boolean existsBucket = false;
        for (Bucket bucket : tm.getAmazonS3Client().listBuckets()) {
            if (bucket.getName().equals(bucketName)) {
                existsBucket = true;
            }
        }

        if (!existsBucket) {
            LOGGER.info("Creating Amazon S3 bucket " + bucketName);
            try {
                tm.getAmazonS3Client().createBucket(bucketName);
            } catch (AmazonClientException e) {
                LOGGER.error("Amazon S3 bucket creation for bucket " + bucketName + " failed");
                throw new AmazonClientException(e.getMessage());
            }

            LOGGER.info("Amazon S3 bucket creation for bucket " + bucketName + " completed successfully");
        }
    }
 
開發者ID:ktenzer,項目名稱:snap2cloud,代碼行數:22,代碼來源:S3Backup.java

示例13: prepareMockForTestWildcardInBucketName

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
private AmazonS3 prepareMockForTestWildcardInBucketName() {
    AmazonS3 amazonS3 = mock(AmazonS3.class);
    when(amazonS3.listBuckets()).thenReturn(Arrays.asList(new Bucket("myBucketOne"), new Bucket("myBucketTwo"),
            new Bucket("anotherBucket"), new Bucket("myBuckez")));

    // Mocks for the '**' case
    ObjectListing objectListingWithOneFile = createObjectListingMock(Collections.singletonList(createS3ObjectSummaryWithKey("test.txt")), Collections.emptyList(), false);
    ObjectListing emptyObjectListing = createObjectListingMock(Collections.emptyList(), Collections.emptyList(), false);
    when(amazonS3.listObjects(argThat(new ListObjectsRequestMatcher("myBucketOne", null, null)))).thenReturn(objectListingWithOneFile);
    when(amazonS3.listObjects(argThat(new ListObjectsRequestMatcher("myBucketTwo", null, null)))).thenReturn(emptyObjectListing);
    when(amazonS3.listObjects(argThat(new ListObjectsRequestMatcher("anotherBucket", null, null)))).thenReturn(objectListingWithOneFile);
    when(amazonS3.listObjects(argThat(new ListObjectsRequestMatcher("myBuckez", null, null)))).thenReturn(emptyObjectListing);

    when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))).thenReturn(new ObjectMetadata());
    return amazonS3;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:17,代碼來源:PathMatchingSimpleStorageResourcePatternResolverTest.java

示例14: createBucketForInstance

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
public Bucket createBucketForInstance(String instanceId, ServiceDefinition service, String planId,
        String organizationGuid, String spaceGuid) {
    String bucketName = getBucketNameForInstance(instanceId);
    logger.info("Creating bucket '{}' for serviceInstanceId '{}'", bucketName, instanceId);
    Bucket bucket = s3.createBucket(bucketName, Region.fromValue(region));

    // TODO allow for additional, custom tagging options
    BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration();
    TagSet tagSet = new TagSet();
    tagSet.setTag("serviceInstanceId", instanceId);
    tagSet.setTag("serviceDefinitionId", service.getId());
    tagSet.setTag("planId", planId);
    tagSet.setTag("organizationGuid", organizationGuid);
    tagSet.setTag("spaceGuid", spaceGuid);
    bucketTaggingConfiguration.withTagSets(tagSet);
    s3.setBucketTaggingConfiguration(bucket.getName(), bucketTaggingConfiguration);

    return bucket;
}
 
開發者ID:cloudfoundry-community,項目名稱:s3-cf-service-broker,代碼行數:20,代碼來源:S3.java

示例15: listBucketsShouldReturnExpectedBuckets

import com.amazonaws.services.s3.model.Bucket; //導入依賴的package包/類
@Test
public void listBucketsShouldReturnExpectedBuckets() throws Exception {
    removeDefaultBucket();
    client.createBucket("bucket-1");
    client.createBucket("bucket-2");
    client.createBucket("bucket-3");
    client.createBucket("bucket-4");
    client.createBucket("bucket-5");

    List<com.amazonaws.services.s3.model.Bucket> buckets = client.listBuckets();
    List<String> bucketNames = new ArrayList<>();
    for(Bucket bucket : buckets) {
        bucketNames.add(bucket.getName());
    }

    assertEquals(5, bucketNames.size());
    assertTrue(bucketNames.contains("bucket-1"));
    assertTrue(bucketNames.contains("bucket-2"));
    assertTrue(bucketNames.contains("bucket-3"));
    assertTrue(bucketNames.contains("bucket-4"));
    assertTrue(bucketNames.contains("bucket-5"));

}
 
開發者ID:michaeltandy,項目名稱:s3test,代碼行數:24,代碼來源:ListBucketsTest.java


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