Example usage for com.amazonaws.services.s3 AmazonS3 setEndpoint

List of usage examples for com.amazonaws.services.s3 AmazonS3 setEndpoint

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3 setEndpoint.

Prototype

public void setEndpoint(String endpoint);

Source Link

Document

Overrides the default endpoint for this client.

Usage

From source file:aot.storage.s3.CustomStorage.java

License:Open Source License

protected static AmazonS3 createS3(String[] ids) {
    AmazonS3 s3;
    if ((ids.length >= 1) && !ids[1].trim().isEmpty()) {
        String[] creds = ids[1].split(":");
        s3 = new AmazonS3Client(new BasicAWSCredentials(creds[0], creds[1]));
    } else {//w  w w  . j  a  v a  2 s . c  o m
        s3 = new AmazonS3Client();
    }
    if ((ids.length >= 2) && !ids[2].trim().isEmpty()) {
        s3.setRegion(Region.getRegion(Regions.fromName(ids[2])));
    }
    if ((ids.length >= 3) && !ids[3].trim().isEmpty()) {
        s3.setEndpoint(ids[3]);
    }
    return s3;
}

From source file:apphub.storage.s3.CustomStorage.java

License:Open Source License

protected static AmazonS3 createS3(URL url) {
    AmazonS3 s3;
    String userInfo = url.getUserInfo();
    if (userInfo != null) {
        String[] creds = userInfo.split(":");
        if (creds.length == 2) {
            s3 = new AmazonS3Client(new BasicAWSCredentials(creds[0], creds[1]));
        } else {//from  w  w  w  . j a va 2  s .c om
            throw new CreateStorageException(url.toString(),
                    "Credentials for S3 storage must be in form of KEY:SECRET");
        }
    } else {
        s3 = new AmazonS3Client();
    }
    Map<String, String> queryParameters = UrlUtil.getQueryParameters(url);
    String region = queryParameters.get("region");
    if (region != null) {
        s3.setRegion(Region.getRegion(Regions.fromName(region)));
    }
    String endpoint = queryParameters.get("endpoint");
    if (endpoint != null) {
        s3.setEndpoint(endpoint);
    }
    return s3;
}

From source file:br.puc_rio.ele.lvc.interimage.common.udf.ROIStorage.java

License:Apache License

/**
  * Method invoked on every tuple during foreach evaluation.
  * @param input tuple<br>//w w  w . j ava  2  s.c om
  * first column is assumed to have the geometry<br>
  * second column is assumed to have the class name<br>
  * third column is assumed to have the output path
  * @exception java.io.IOException
  * @return true if successful, false otherwise
  */
@Override
public Boolean exec(Tuple input) throws IOException {
    if (input == null || input.size() < 3)
        return null;

    try {

        Object objGeometry = input.get(0);
        Geometry geometry = _geometryParser.parseGeometry(objGeometry);
        String className = DataType.toString(input.get(1));
        String path = DataType.toString(input.get(2));

        AWSCredentials credentials = new BasicAWSCredentials(_accessKey, _secretKey);
        AmazonS3 conn = new AmazonS3Client(credentials);
        conn.setEndpoint("https://s3.amazonaws.com");

        /*File temp = File.createTempFile(className, ".wkt");
                
         // Delete temp file when program exits.
         temp.deleteOnExit();
                     
         BufferedWriter out = new BufferedWriter(new FileWriter(temp));
         out.write(new WKTWriter().write(geometry));
         out.close();*/

        /*
                
        File temp = File.createTempFile(className, ".wkt.snappy");
                   
        temp.deleteOnExit();*/

        String geom = new WKTWriter().write(geometry);

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        OutputStream snappyOut = new SnappyOutputStream(out);
        snappyOut.write(geom.getBytes());
        snappyOut.close();

        /*PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, path + className + ".wkt.snappy", temp);
        putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all*/

        PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, path + className + ".wkts",
                new ByteArrayInputStream(out.toByteArray()), new ObjectMetadata());
        putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all

        TransferManager tx = new TransferManager(credentials);
        tx.upload(putObjectRequest);

        return true;

    } catch (Exception e) {
        throw new IOException("Caught exception processing input row ", e);
    }
}

From source file:br.puc_rio.ele.lvc.interimage.core.datamanager.AWSSource.java

License:Apache License

 public AWSSource(String accessKey, String secretKey, String bucket) {
   _accessKey = accessKey;//from www.  j a  va 2s . c  o m
   _secretKey = secretKey;
   _bucket = bucket;
      
   AWSCredentials credentials = new BasicAWSCredentials(_accessKey, _secretKey);
      
   ClientConfiguration conf = new ClientConfiguration();
      
   conf.setConnectionTimeout(0);
   conf.setSocketTimeout(0);
      
   AmazonS3 conn = new AmazonS3Client(credentials);
   conn.setEndpoint("https://s3.amazonaws.com");
      
   _manager = new TransferManager(conn);
            
}

From source file:br.puc_rio.ele.lvc.interimage.core.datamanager.AWSSource.java

License:Apache License

public AWSSource(String accessKey, String secretKey, String bucket) {
        _accessKey = accessKey;/*w ww  . j a  v  a 2  s .c  o m*/
        _secretKey = secretKey;
        _bucket = bucket;

        AWSCredentials credentials = new BasicAWSCredentials(_accessKey, _secretKey);

        ClientConfiguration conf = new ClientConfiguration();

        conf.setConnectionTimeout(0);
        conf.setSocketTimeout(0);

        AmazonS3 conn = new AmazonS3Client(credentials);
        conn.setEndpoint("https://s3.amazonaws.com");

        _manager = new TransferManager(conn);

    }

From source file:ch.admin.isb.hermes5.tools.filebackup.FileBackup.java

License:Apache License

private AmazonS3 s3(String accessKey, String secretKey, String s3Endpoint) {
    AmazonS3 s3 = accessKey == null || "".equals(accessKey) ? new AmazonS3Client()
            : new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
    s3.setEndpoint(s3Endpoint);
    return s3;/*from  ww w  .j a  va2s . c  o m*/
}

From source file:ch.hesso.master.sweetcity.utils.PictureUtils.java

License:Apache License

public static Key uploadPicture(Bitmap picture, GoogleAccountCredential googleCredential) {
    if (picture == null)
        return null;

    try {//  w  w w  .  ja v a 2 s  .c o m
        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.HTTP);
        AmazonS3 s3Connection = new AmazonS3Client(AWS_CREDENTIALS, clientConfig);
        s3Connection.setEndpoint(ConstantsAWS.S3_END_POINT);

        ObjectMetadata pictureMetadata = new ObjectMetadata();

        String key = String.format(ConstantsAWS.S3_PICTURE_NAME_FORMAT,
                googleCredential.getSelectedAccountName(), Constants.DATE_FORMAT_IMAGE.format(new Date()));

        s3Connection.putObject(ConstantsAWS.S3_BUCKET_NAME, key, ImageUtils.bitmapToInputStream(picture),
                pictureMetadata);

        return new Key(key);
    } catch (Exception e) {
        Log.d(Constants.PROJECT_NAME, e.toString());
    }

    return null;
}

From source file:ch.hesso.master.sweetcity.utils.PictureUtils.java

License:Apache License

public static InputStream getPicture(Key key) {
    if (key == null)
        return null;

    try {/*from www .jav a2  s  . c o m*/
        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.HTTP);
        AmazonS3 s3Connection = new AmazonS3Client(AWS_CREDENTIALS, clientConfig);
        s3Connection.setEndpoint(ConstantsAWS.S3_END_POINT);

        S3Object obj = s3Connection.getObject(ConstantsAWS.S3_BUCKET_NAME, key.toString());
        return obj.getObjectContent();
    } catch (Exception e) {
        Log.d(Constants.PROJECT_NAME, e.toString());
    }
    return null;
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void setAccess(String id, int what, String access_key, String secret_key, String endpoint, String bucket) {
    try {/*from w ww  . ja v  a2s  .  c o  m*/

        Collection<Grant> grantCollection = new ArrayList<Grant>();
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        AccessControlList bucketAcl = s3Client.getBucketAcl(bucket);
        Grant grant = null;
        if (what == 0) {

            grant = new Grant(new CanonicalGrantee(id), Permission.Read);
            grantCollection.add(grant);
        }

        if (what == 1) {
            grant = new Grant(new CanonicalGrantee(id), Permission.FullControl);
            grantCollection.add(grant);
        }

        if (what == 3) {
            bucketAcl.getGrants().clear();
        }

        bucketAcl.getGrants().addAll(grantCollection);
        s3Client.setBucketAcl(bucket, bucketAcl);

    } catch (AmazonServiceException ase) {
        NewJFrame.jTextArea1.append("\n\nError: " + ase.getErrorMessage());
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void setACLpublic(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {//from ww w .j a v  a  2 s  .  c  o m
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        s3Client.setObjectAcl(bucket, object, CannedAccessControlList.PublicRead);
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}