Example usage for com.amazonaws.services.s3 AmazonS3URI getURI

List of usage examples for com.amazonaws.services.s3 AmazonS3URI getURI

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3URI getURI.

Prototype

public URI getURI() 

Source Link

Usage

From source file:com.nextdoor.bender.config.BenderConfig.java

License:Apache License

public static BenderConfig load(AmazonS3ClientFactory s3ClientFactory, AmazonS3URI s3Uri) {
    AmazonS3Client s3 = s3ClientFactory.newInstance();
    S3Object s3object = s3.getObject(s3Uri.getBucket(), s3Uri.getKey());

    StringWriter writer = new StringWriter();

    try {//from  w  ww . j  a  va 2s .  c  om
        IOUtils.copy(s3object.getObjectContent(), writer, "UTF-8");
    } catch (IOException e) {
        throw new ConfigurationException("Unable to read file from s3", e);
    }
    BenderConfig config = load(s3Uri.getKey().toString(), writer.toString());
    config.setConfigFile(s3Uri.getURI().toString());

    return config;
}

From source file:org.ow2.proactive.scheduler.examples.S3ConnectorDownloader.java

License:Open Source License

/**
 * Parse an Amazon S3 Uri to extract four elements: scheme, host, bucket name and key name.
 *
 * @param s3Uri//from w  w  w . j  a va  2 s  .  co  m
 */
private void parseAmazonS3URI(String s3Uri) {
    AmazonS3URI amazonS3URI = new AmazonS3URI(s3Uri);
    if ((scheme = amazonS3URI.getURI().getScheme()) == null) {
        throw new IllegalArgumentException(
                "You have to specify a valid scheme in the provided s3 uri. Empty value is not allowed.");
    }
    if ((host = amazonS3URI.getURI().getHost()) == null) {
        throw new IllegalArgumentException(
                "You have to specify a valid host in the provided s3 uri. Empty value is not allowed.");
    }
    if ((bucketName = amazonS3URI.getBucket()) == null) {
        throw new IllegalArgumentException(
                "You have to specify a valid bucket name in the provided s3 uri. Empty value is not allowed.");
    }
    if ((s3RemoteRelativePath = amazonS3URI.getKey()) == null) {
        throw new IllegalArgumentException(
                "You have to specify a valid key name in the provided s3 uri. Empty value is not allowed.");
    }

}