List of usage examples for com.amazonaws AmazonServiceException getErrorMessage
public String getErrorMessage()
From source file:aws.example.s3.GetBucketPolicy.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " GetBucketPolicy <bucket>\n\n" + "Where:\n" + " bucket - the bucket to get the policy from.\n\n" + "Example:\n" + " GetBucketPolicy testbucket\n\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1);/*from ww w .ja va 2 s. c o m*/ } String bucket_name = args[0]; String policy_text = null; System.out.format("Getting policy for bucket: \"%s\"\n\n", bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try { BucketPolicy bucket_policy = s3.getBucketPolicy(bucket_name); policy_text = bucket_policy.getPolicyText(); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } if (policy_text == null) { System.out.println("The specified bucket has no bucket policy."); } else { System.out.println("Returned policy:"); System.out.println("----"); System.out.println(policy_text); System.out.println("----\n"); } System.out.println("Done!"); }
From source file:aws.example.s3.GetObject.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and object to\n" + "download from it.\n" + "\n" + "Ex: GetObject <bucketname> <filename>\n"; if (args.length < 2) { System.out.println(USAGE); System.exit(1);/*w ww.j a v a 2s .c o m*/ } String bucket_name = args[0]; String key_name = args[1]; System.out.format("Downloading %s from S3 bucket %s...\n", key_name, bucket_name); final AmazonS3 s3 = new AmazonS3Client(); try { S3Object o = s3.getObject(bucket_name, key_name); S3ObjectInputStream s3is = o.getObjectContent(); FileOutputStream fos = new FileOutputStream(new File(key_name)); byte[] read_buf = new byte[1024]; int read_len = 0; while ((read_len = s3is.read(read_buf)) > 0) { fos.write(read_buf, 0, read_len); } s3is.close(); fos.close(); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done!"); }
From source file:aws.example.s3.GetWebsiteConfiguration.java
License:Open Source License
public static void getWebsiteConfig(String bucket_name) { final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {//from w ww . ja va 2 s . co m BucketWebsiteConfiguration config = s3.getBucketWebsiteConfiguration(bucket_name); if (config == null) { System.out.println("No website configuration found!"); } else { System.out.format("Index document: %s\n", config.getIndexDocumentSuffix()); System.out.format("Error document: %s\n", config.getErrorDocument()); } } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.out.println("Failed to get website configuration!"); System.exit(1); } }
From source file:aws.example.s3.PutObject.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and a file to\n" + "upload to it.\n" + "\n" + "Ex: PutObject <bucketname> <filename>\n"; if (args.length < 2) { System.out.println(USAGE); System.exit(1);//from w w w . j av a 2 s. c o m } String bucket_name = args[0]; String file_path = args[1]; String key_name = Paths.get(file_path).getFileName().toString(); System.out.format("Uploading %s to S3 bucket %s...\n", file_path, bucket_name); final AmazonS3 s3 = new AmazonS3Client(); try { s3.putObject(bucket_name, key_name, file_path); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } System.out.println("Done!"); }
From source file:aws.example.s3.SetAcl.java
License:Open Source License
public static void setBucketAcl(String bucket_name, String email, String access) { System.out.format("Setting %s access for %s\n", access, email); System.out.println("on bucket: " + bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {/*from www.j a va 2 s .c om*/ // get the current ACL AccessControlList acl = s3.getBucketAcl(bucket_name); // set access for the grantee EmailAddressGrantee grantee = new EmailAddressGrantee(email); Permission permission = Permission.valueOf(access); acl.grantPermission(grantee, permission); s3.setBucketAcl(bucket_name, acl); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
From source file:aws.example.s3.SetAcl.java
License:Open Source License
public static void setObjectAcl(String bucket_name, String object_key, String email, String access) { System.out.format("Setting %s access for %s\n", access, email); System.out.println("for object: " + object_key); System.out.println(" in bucket: " + bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {/*from w ww . j ava 2 s . c o m*/ // get the current ACL AccessControlList acl = s3.getObjectAcl(bucket_name, object_key); // set access for the grantee EmailAddressGrantee grantee = new EmailAddressGrantee(email); Permission permission = Permission.valueOf(access); acl.grantPermission(grantee, permission); s3.setObjectAcl(bucket_name, object_key, acl); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
From source file:aws.example.s3.SetBucketPolicy.java
License:Open Source License
public static void setBucketPolicy(String bucket_name, String policy_text) { final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {//from w w w . j a v a2 s . c o m s3.setBucketPolicy(bucket_name, policy_text); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
From source file:aws.example.s3.SetWebsiteConfiguration.java
License:Open Source License
public static void setWebsiteConfig(String bucket_name, String index_doc, String error_doc) { BucketWebsiteConfiguration website_config = null; if (index_doc == null) { website_config = new BucketWebsiteConfiguration(); } else if (error_doc == null) { website_config = new BucketWebsiteConfiguration(index_doc); } else {/*from w ww. ja va 2 s.c o m*/ website_config = new BucketWebsiteConfiguration(index_doc, error_doc); } final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try { s3.setBucketWebsiteConfiguration(bucket_name, website_config); } catch (AmazonServiceException e) { System.out.format("Failed to set website configuration for bucket '%s'!\n", bucket_name); System.err.println(e.getErrorMessage()); System.exit(1); } }
From source file:aws.example.s3.XferMgrCopy.java
License:Open Source License
public static void copyObjectSimple(String from_bucket, String from_key, String to_bucket, String to_key) { System.out.println("Copying s3 object: " + from_key); System.out.println(" from bucket: " + from_bucket); System.out.println(" to s3 object: " + to_bucket); System.out.println(" in bucket: " + to_key); TransferManager xfer_mgr = new TransferManager(); try {//from w w w.ja va2s . c o m Copy xfer = xfer_mgr.copy(from_bucket, from_key, to_bucket, to_key); // loop with Transfer.isDone() XferMgrProgress.showTransferProgress(xfer); // or block with Transfer.waitForCompletion() XferMgrProgress.waitForCompletion(xfer); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } xfer_mgr.shutdownNow(); }
From source file:aws.example.s3.XferMgrDownload.java
License:Open Source License
public static void downloadDir(String bucket_name, String key_prefix, String dir_path, boolean pause) { System.out.println("downloading to directory: " + dir_path + (pause ? " (pause)" : "")); TransferManager xfer_mgr = new TransferManager(); try {// w ww . j a va 2 s .c o m MultipleFileDownload xfer = xfer_mgr.downloadDirectory(bucket_name, key_prefix, new File(dir_path)); // loop with Transfer.isDone() XferMgrProgress.showTransferProgress(xfer); // or block with Transfer.waitForCompletion() XferMgrProgress.waitForCompletion(xfer); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } xfer_mgr.shutdownNow(); }