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

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

Introduction

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

Prototype

@SdkInternalApi
AmazonS3Client(AmazonS3ClientParams s3ClientParams) 

Source Link

Document

Constructs a new client to invoke service methods on S3 using the specified parameters.

Usage

From source file:com.neu.cloud.Controller.SecondUseCaseController.java

private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) {
    String bucketName = "reports-sppard";
    String keyName = "UseCase2-" + dateForFolder + "/" + uploadFileName;
    AmazonS3 s3client = new AmazonS3Client(
            new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma"));
    try {/*w w  w. j a  v a 2  s . c o  m*/
        System.out.println("Uploading a new object to S3 from a file\n");
        File file = new File(uploadFilePath + uploadFileName);
        s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.neu.cloud.Controller.ThirdUseCaseController.java

private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) {
    String bucketName = "reports-sppard";
    String keyName = "UseCase3-" + dateForFolder + "/" + uploadFileName;
    AmazonS3 s3client = new AmazonS3Client(
            new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma"));
    try {/*from   w ww.j av a 2 s.c  o  m*/
        System.out.println("Uploading a new object to S3 from a file\n");
        File file = new File(uploadFilePath + uploadFileName);
        s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.neu.Spark.MainFrame.java

/**
 * Creates new form MainFrame//from ww  w  . j a  v a  2s . c  o  m
 */
public MainFrame() {
    initComponents();

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setProtocol(Protocol.HTTP);

    conn = new AmazonS3Client(credentials);
    conn.setEndpoint("s3.amazonaws.com");

}

From source file:com.ninetoseven.inmuebles.AmazonClientManager.java

License:Open Source License

private void initClients() {
    AWSCredentials credentials = AmazonSharedPreferencesWrapper
            .getCredentialsFromSharedPreferences(this.sharedPreferences);

    Region region = Region.getRegion(Regions.US_EAST_1);

    s3Client = new AmazonS3Client(credentials);
    s3Client.setRegion(region);/*from   w w  w.  j  a  v a 2 s  .c  o m*/

    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setRegion(region);

    sdbClient = new AmazonSimpleDBClient(credentials);
    sdbClient.setRegion(region);

    snsClient = new AmazonSNSClient(credentials);
    snsClient.setRegion(region);
}

From source file:com.openkm.util.backup.RepositoryS3Backup.java

License:Open Source License

/**
 * Performs a recursive repository content export with metadata
 *///from w  w  w .j a v  a  2  s.  c om
public static ImpExpStats backup(String token, String fldPath, String bucket, boolean metadata, Writer out,
        InfoDecorator deco)
        throws PathNotFoundException, AccessDeniedException, RepositoryException, FileNotFoundException,
        ParseException, NoSuchGroupException, IOException, DatabaseException, GeneralException {
    log.debug("backup({}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, bucket, metadata, out, deco });
    ImpExpStats stats = null;

    if (running) {
        throw new GeneralException("Backup in progress");
    } else {
        running = true;

        try {
            if (!Config.AMAZON_ACCESS_KEY.equals("") && !Config.AMAZON_SECRET_KEY.equals("")) {
                AmazonS3 s3 = new AmazonS3Client(
                        new BasicAWSCredentials(Config.AMAZON_ACCESS_KEY, Config.AMAZON_SECRET_KEY));

                if (!s3.doesBucketExist(bucket)) {
                    s3.createBucket(bucket, Region.EU_Ireland);
                }

                stats = backupHelper(token, fldPath, s3, bucket, metadata, out, deco);
                log.info("Backup finished!");
            } else {
                throw new GeneralException("Missing Amazon Web Service keys");
            }
        } finally {
            running = false;
        }
    }

    log.debug("exportDocuments: {}", stats);
    return stats;
}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void populateS3() throws AmazonClientException {
    AmazonS3Client client = new AmazonS3Client(credentials.getCredentials());
    client.setRegion(regions.get(0));/*from  w  ww . ja v a  2s .  c  om*/
    List<Bucket> buckets = client.listBuckets();
    for (Bucket bucket : buckets) {
        Service temp = new LocalS3Service(bucket.getName(), credentials, regions.get(0), bucket, logger);
        services.add(temp);
    }
}

From source file:com.pinterest.terrapin.TerrapinUtil.java

License:Apache License

static public List<Pair<Path, Long>> getS3FileList(AWSCredentials credentials, String s3Bucket,
        String s3KeyPrefix) {//from www  .j a v a  2 s  .  co  m
    List<Pair<Path, Long>> fileSizePairList = Lists.newArrayListWithCapacity(Constants.MAX_ALLOWED_SHARDS);
    AmazonS3Client s3Client = new AmazonS3Client(credentials);
    // List files and build the path using the s3n: prefix.
    // Note that keys > marker are retrieved where the > is by lexicographic order.
    String prefix = s3KeyPrefix;
    String marker = prefix;
    while (true) {
        boolean reachedEnd = false;
        ObjectListing listing = s3Client
                .listObjects(new ListObjectsRequest().withBucketName(s3Bucket).withMarker(marker));
        List<S3ObjectSummary> summaries = listing.getObjectSummaries();

        if (summaries.isEmpty()) {
            break;
        }

        for (S3ObjectSummary summary : summaries) {
            if (summary.getKey().startsWith(prefix)) {
                fileSizePairList.add(new ImmutablePair(new Path("s3n", s3Bucket, "/" + summary.getKey()),
                        summary.getSize()));
                if (fileSizePairList.size() > Constants.MAX_ALLOWED_SHARDS) {
                    throw new RuntimeException("Too many files " + fileSizePairList.size());
                }
            } else {
                // We found a key which does not match the prefix, stop.
                reachedEnd = true;
                break;
            }
        }
        if (reachedEnd) {
            break;
        }
        marker = summaries.get(summaries.size() - 1).getKey();
    }
    return fileSizePairList;
}

From source file:com.projectlaver.batch.FacebookListingPostingItemProcessor.java

License:Open Source License

void copyS3ObjectToTempFile(File tempFile, String filename) throws IOException, FileNotFoundException {
    AWSCredentials myCredentials = new BasicAWSCredentials(this.s3accessKey, this.s3secretKey);
    AmazonS3 s3 = new AmazonS3Client(myCredentials);
    S3Object object = s3.getObject(this.s3publicBucketName, filename);

    IOUtils.copy(object.getObjectContent(), new FileOutputStream(tempFile));
}

From source file:com.projectlaver.service.ListingService.java

License:Open Source License

void streamAwsContentToResponse(String contentFilename, String bucketName, OutputStream outputStream)
        throws IOException {
    AWSCredentials myCredentials = new BasicAWSCredentials(this.s3accessKey, this.s3secretKey);
    AmazonS3 s3 = new AmazonS3Client(myCredentials);
    S3Object object = s3.getObject(bucketName, contentFilename);

    FileCopyUtils.copy(object.getObjectContent(), outputStream);
}

From source file:com.proofpoint.event.collector.MainModule.java

License:Apache License

@Provides
@Singleton
private AmazonS3 provideAmazonS3(AWSCredentials credentials) {
    return new AmazonS3Client(credentials);
}