List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client
@SdkInternalApi AmazonS3Client(AmazonS3ClientParams s3ClientParams)
From source file:baldrickv.s3streamingtool.S3StreamingUpload.java
License:Open Source License
public static String upload(InputStream in, String bucket, String file, int block_size, Key secret_key, AWSCredentials creds) throws Exception { S3StreamConfig config = new S3StreamConfig(); config.setInputStream(in);/*from w w w .j a va2 s . c o m*/ config.setS3Bucket(bucket); config.setS3File(file); config.setBlockSize(block_size); config.setSecretKey(secret_key); config.setEncryption(true); config.setS3Client(new AmazonS3Client(creds)); return upload(config); }
From source file:beanstalk.BeanstalkDeployNoGUI.java
License:Apache License
public void upload_file_to_s3(String bucketName, String keyName, String uploadFileName, String AWSKeyId, String AWSSecretKey) throws BeanstalkAdapterException { BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey); AmazonS3 s3client = new AmazonS3Client(basic_credentials); try {//from w w w . j a v a 2s .co m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(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()); throw new BeanstalkAdapterException(ase.getMessage()); } 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()); throw new BeanstalkAdapterException(ace.getMessage()); } }
From source file:beanstalk.BeanstalkFirstDeploymentNoGUI.java
License:Apache License
public void upload_file_to_s3(String bucketName, String keyName, String uploadFileName, String AWSKeyId, String AWSSecretKey) throws BeanstalkAdapterException { BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey); AmazonS3 s3client = new AmazonS3Client(basic_credentials); try {/*from w ww . j a va 2s .c o m*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(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()); throw new BeanstalkAdapterException(ase.getMessage()); } 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()); throw new BeanstalkAdapterException(ace.getMessage()); } }
From source file:biz.neustar.webmetrics.plugins.neustar_s3_maven_plugin.S3UploadMojo.java
License:Apache License
/** */ private static AmazonS3 getS3Client(String accessKey, String secretKey) { AWSCredentialsProvider provider = null; if (accessKey != null && secretKey != null) { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); provider = new StaticCredentialsProvider(credentials); } else {//from w ww . j a v a 2 s. c om provider = new DefaultAWSCredentialsProviderChain(); } return new AmazonS3Client(provider); }
From source file:br.com.tamandua.aws.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*//w w w . ja v a2 s . c o m * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties"))); String bucketName = "test-bucket-everton-" + UUID.randomUUID(); String key = "somekey"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); try { /* * Create a new S3 bucket - Amazon S3 bucket names are globally unique, * so once a bucket name has been taken by any user, you can't create * another bucket with that same name. * * You can optionally specify a location for your bucket if you want to * keep your data closer to your applications or users. */ System.out.println("Creating bucket " + bucketName + "\n"); s3.createBucket(bucketName); /* * List the buckets in your account */ System.out.println("Listing buckets"); for (Bucket bucket : s3.listBuckets()) { System.out.println(" - " + bucket.getName()); } System.out.println(); /* * Upload an object to your bucket - You can easily upload a file to * S3, or upload directly an InputStream if you know the length of * the data in the stream. You can also specify your own metadata * when uploading to S3, which allows you set a variety of options * like content-type and content-encoding, plus additional metadata * specific to your applications. */ System.out.println("Uploading a new object to S3 from a file\n"); s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile())); /* * Download an object - When you download an object, you get all of * the object's metadata and a stream from which to read the contents. * It's important to read the contents of the stream as quickly as * possibly since the data is streamed directly from Amazon S3 and your * network connection will remain open until you read all the data or * close the input stream. * * GetObjectRequest also supports several other options, including * conditional downloading of objects based on modification times, * ETags, and selectively downloading a range of an object. */ System.out.println("Downloading an object"); S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); System.out.println("Content-Type: " + object.getObjectMetadata().getContentType()); displayTextInputStream(object.getObjectContent()); /* * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("some")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println( " - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); /* * Delete an object - Unless versioning has been turned on for your bucket, * there is no way to undelete an object, so use caution when deleting objects. */ System.out.println("Deleting an object\n"); s3.deleteObject(bucketName, key); /* * Delete a bucket - A bucket must be completely empty before it can be * deleted, so remember to delete any objects from your buckets before * you try to delete them. */ System.out.println("Deleting bucket " + bucketName + "\n"); s3.deleteBucket(bucketName); } 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 " + "a serious internal problem 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: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>//from www .jav a2s . c o m * 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 w ww.ja v a 2s . c om _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;/*from w w w .j av a 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.unb.bionimbuz.storage.bucket.methods.CloudMethodsAmazonGoogle.java
@Override public void StorageAuth(StorageProvider sp) throws Exception { switch (sp) { case AMAZON: { byte[] encoded = Files.readAllBytes(Paths.get(authFolder + "AwsCredentials.txt")); String fileContent = new String(encoded, Charset.defaultCharset()); //System.out.println("AuthString: " + fileContent); String accessKeyID, accessKey; int delimiter = fileContent.indexOf(':'); accessKeyID = fileContent.substring(0, delimiter); accessKey = fileContent.substring(delimiter + 1); AWSCredentials credentials = new BasicAWSCredentials(accessKeyID, accessKey); s3client = new AmazonS3Client(credentials); break;/* w w w. j ava 2 s . c o m*/ } case GOOGLE: { String command = gcloudFolder + "gcloud auth activate-service-account --key-file=" + authFolder + "GoogleCredentials.json"; ExecCommand(command); break; } default: { throw new Exception("Provedor incorreto!"); } } }
From source file:br.unb.cic.bionimbuz.services.storage.bucket.methods.CloudMethodsAmazonGoogle.java
@Override public void StorageAuth(StorageProvider sp) throws Exception { switch (sp) { case AMAZON: { // InputStream is = null; // is = new FileInputStream(keyAmazon); // PropertiesCredentials credentials = new PropertiesCredentials(is); final byte[] encoded = Files.readAllBytes(Paths.get(keyAmazon)); final String fileContent = new String(encoded, Charset.defaultCharset()); System.out.println("AuthString: " + fileContent); String accessKeyID, accessKey; final int delimiter = fileContent.indexOf(':'); accessKeyID = fileContent.substring(0, delimiter); accessKey = fileContent.substring(delimiter + 1); final AWSCredentials credentials = new BasicAWSCredentials(accessKeyID, accessKey); s3client = new AmazonS3Client(credentials); break;/*from www . j a v a 2s. c o m*/ } case GOOGLE: { final String command = gcloudFolder + "gcloud auth activate-service-account --key-file=" + keyGoogle; ExecCommand(command); break; } default: { throw new Exception("Provedor incorreto!"); } } }