Example usage for com.amazonaws.services.s3 AmazonS3Client doesBucketExist

List of usage examples for com.amazonaws.services.s3 AmazonS3Client doesBucketExist

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client doesBucketExist.

Prototype

@Override
    public boolean doesBucketExist(String bucketName) throws SdkClientException, AmazonServiceException 

Source Link

Usage

From source file:org.geowebcache.s3.S3BlobStoreInfo.java

License:Open Source License

/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */
public AmazonS3Client buildClient() {
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (null != useHTTPS) {
        clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP);
    }// w w  w.  j  av a  2s.co  m
    if (null != maxConnections && maxConnections > 0) {
        clientConfig.setMaxConnections(maxConnections);
    }
    clientConfig.setProxyDomain(proxyDomain);
    clientConfig.setProxyWorkstation(proxyWorkstation);
    clientConfig.setProxyHost(proxyHost);
    if (null != proxyPort) {
        clientConfig.setProxyPort(proxyPort);
    }
    clientConfig.setProxyUsername(proxyUsername);
    clientConfig.setProxyPassword(proxyPassword);
    if (null != useGzip) {
        clientConfig.setUseGzip(useGzip);
    }
    log.debug("Initializing AWS S3 connection");
    AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig);
    if (endpoint != null && !"".equals(endpoint)) {
        S3ClientOptions s3ClientOptions = new S3ClientOptions();
        s3ClientOptions.setPathStyleAccess(true);
        client.setS3ClientOptions(s3ClientOptions);
        client.setEndpoint(endpoint);
    }
    if (!client.doesBucketExist(bucket)) {
        client.createBucket(bucket);
    }
    return client;
}

From source file:org.opendedup.sdfs.filestore.cloud.BatchAwsS3ChunkStore.java

License:Open Source License

public static boolean checkBucketUnique(String awsAccessKey, String awsSecretKey, String bucketName) {
    AWSCredentials creds = null;/*  w w  w. j  a v a  2  s  .  c o m*/
    try {
        creds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
        AmazonS3Client s3Service = new AmazonS3Client(creds);
        return s3Service.doesBucketExist(bucketName);
    } catch (Exception e) {
        SDFSLogger.getLog().fatal("Unable to create aws bucket", e);
        return false;
    }
}