Boolean VersioningStatus(String access_key, String secret_key, String bucket, String endpoint, Boolean enable) { String message = null; boolean result = false; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { message = s3Client.getBucketVersioningConfiguration(bucket).getStatus().toString(); if (message.contains("Enabled") || message.contains("Suspended")) { result = true; } else { result = false; } } catch (Exception versioning) { } return result; }
Boolean LifeCycleStatus(String access_key, String secret_key, String bucket, String endpoint, Boolean enable) { String message = null; boolean result = false; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { message = s3Client.getBucketLifecycleConfiguration(bucket).getRules().toString(); if (message == null) { result = false; } else { result = true; } } catch (Exception lifecyclestatus) { } return result; }
void setBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) { try { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } BucketWebsiteConfiguration bucketWebsiteConfiguration = s3Client.getBucketWebsiteConfiguration(bucket); s3Client.setBucketAcl(bucket, CannedAccessControlList.PublicRead); s3Client.setBucketWebsiteConfiguration(bucket, new BucketWebsiteConfiguration("index.html", "error.html")); } catch (Exception setACLpublic) { mainFrame.jTextArea1.append("\nException occurred in ACL"); } }
String setACLurl(String object, String access_key, String secret_key, String endpoint, String bucket) { String URL = null; try { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } java.util.Date expiration = new java.util.Date(); long milliSeconds = expiration.getTime(); milliSeconds += 1000 * 60 * 1000; // Add 1 hour. expiration.setTime(milliSeconds); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, object); generatePresignedUrlRequest.setMethod(HttpMethod.GET); generatePresignedUrlRequest.setExpiration(expiration); URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest); URL = ("Pre-Signed URL = " + url.toString()); StringSelection stringSelection = new StringSelection(url.toString()); } catch (Exception setACLpublic) { } return URL; }
@Override public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws AmazonClientException, AmazonServiceException { return delegate.getBucketLocation(getBucketLocationRequest); }
@Override public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().getBucketLocation(getBucketLocationRequest)); }
@Override public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws AmazonClientException { return null; }
public void run() { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } int converted_days = 0; if (!disabled) { converted_days = Integer.parseInt(days); } Transition transToArchive = new Transition() .withDays(converted_days) .withStorageClass(StorageClass.Glacier); BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = null; if (!disabled) { ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule() .withPrefix(prefix) .withTransition(transToArchive) // .withExpirationInDays(converted_days + 1) .withStatus(BucketLifecycleConfiguration.ENABLED.toString()); } else { ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule() .withPrefix(prefix) .withTransition(transToArchive) //.withExpirationInDays(100) .withStatus(BucketLifecycleConfiguration.DISABLED.toString()); } List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>(); rules.add(ruleArchiveAndExpire); try { BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration() .withRules(rules); s3Client.setBucketLifecycleConfiguration(bucket, configuration); } catch (Exception get) { mainFrame.jTextArea1.append("\n" + get.getMessage()); } if (!disabled) { mainFrame.jTextArea1.append("\nSent request to set bucket life cycle to tier to Glacier after: " + converted_days + " day(s). Please observe for any errors."); } else { mainFrame.jTextArea1.append("\nSent request to disable the bucket life cycle. Please observe for any errors."); } calibrate(); }
public void run() { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { if (version != null) { s3Client.deleteVersion(new DeleteVersionRequest(bucket, what, version)); } else { s3Client.deleteObject(new DeleteObjectRequest(bucket, what)); } if (!debug) { NewJFrame.jTextArea1.append("\nDeleted file: " + what); } calibrate(); } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception delete) { } }
String makeBucket(String access_key, String secret_key, String bucket, String endpoint, String region) { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { s3Client.setEndpoint(endpoint); if (region.length() > 5) { if (region.contains("us-east-1")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (region.contains("us-west")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("ap-")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + region + ".amazonaws.com"); } } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } message = ("\nAttempting to create the bucket. Please view the Bucket list window for an update."); try { if (!(s3Client.doesBucketExist(bucket))) { s3Client.createBucket(new CreateBucketRequest(bucket)); } String bucketLocation = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); } catch (AmazonServiceException ase) { if (ase.getMessage().contains("InvalidLocationConstraint")) { s3Client.createBucket(new CreateBucketRequest(bucket, region)); } else { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } } return message; }
String abortMPUploads(String access_key, String secret_key, String bucket, String endpoint) { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); try { if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } TransferManager tm = new TransferManager(s3Client); int month = 1000 * 60 * 60 * 24 * 30; Date oneWeekAgo = new Date(System.currentTimeMillis() - month); tm.abortMultipartUploads(bucket, oneWeekAgo); message = ("\nSent request to delete all the multi-part uploads in the past month"); } catch (AmazonServiceException multipart) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + multipart.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + multipart.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + multipart.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + multipart.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + multipart.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + multipart.getMessage()); System.out.print("\nHTTP Status Code: " + multipart.getStatusCode()); System.out.print("\nAWS Error Code: " + multipart.getErrorCode()); System.out.print("\nError Type: " + multipart.getErrorType()); System.out.print("\nRequest ID: " + multipart.getRequestId()); } } if (message == null) { message = "Failed to list multi-part uploads."; } return message; }
String getObjectInfo(String key, String access_key, String secret_key, String bucket, String endpoint, String process ) { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } objectlist = null; try { ObjectListing current = s3Client.listObjects((bucket)); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket); ObjectListing objectListing; do { objectListing = s3Client.listObjects(listObjectsRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { if (process.contains("checkmd5")) { if (objectSummary.getKey().contains(key)) { objectlist = objectSummary.getETag(); break; } } if (process.contains("objectsize")) { if (objectSummary.getKey().contains(key)) { objectlist = String.valueOf(objectSummary.getSize()); break; } } if (process.contains("objectdate")) { if (objectSummary.getKey().contains(key)) { objectlist = String.valueOf(objectSummary.getLastModified()); break; } } } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); } catch (Exception listBucket) { // mainFrame.jTextArea1.append("\n" + listBucket.getMessage()); } return objectlist; }
String deleteBucket(String access_key, String secret_key, String bucket, String endpoint ) { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } message = ("\nDeleting bucket: " + bucket); try { s3Client.deleteBucket(new DeleteBucketRequest(bucket)); } catch (Exception Delete) { if (terminal) { System.out.print("\n\n\n" + Delete.getMessage() + "\n\n\n"); } else { message = message + "\n" + Delete.getMessage(); } } if (message == null) { message = "\nDelete operation failed."; } return message; }
public void run() { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucket, what, 2); s3Client.restoreObject(requestRestore); GetObjectMetadataRequest requestCheck = new GetObjectMetadataRequest(bucket, what); ObjectMetadata response = s3Client.getObjectMetadata(requestCheck); Boolean restoreFlag = response.getOngoingRestore(); mainFrame.jTextArea1.append("\nRestoration in progress. Please try to access the file again in a few hours."); calibrate(); } catch (AmazonS3Exception amazonS3Exception) { mainFrame.jTextArea1.append("\nAn Amazon S3 error occurred. Exception: %s" + amazonS3Exception.toString()); calibrate(); } catch (Exception ex) { mainFrame.jTextArea1.append("\nException: %s" + ex.toString()); calibrate(); } calibrate(); }
public void run() { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { long t1 = System.currentTimeMillis(); S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, what, version)); InputStream objectData = s3object.getObjectContent(); this.writeFile(objectData, destination); long t2 = System.currentTimeMillis(); long diff = t2 - t1; if (!mainFrame.perf) { if (terminal) { System.out.print("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).\n"); } else { mainFrame.jTextArea1.append("\nDownloaded: " + what + " in " + diff / 1000 + " second(s)."); mainFrame.calibrateTextArea(); } } } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception get) { } calibrate(); }
public void run() { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } int converted_days = 0; if (!disabled) { converted_days = Integer.parseInt(days); } BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = null; if (!disabled) { ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule() .withPrefix(prefix) .withExpirationInDays(converted_days) .withStatus(BucketLifecycleConfiguration.ENABLED.toString()); } else { ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule() .withPrefix(prefix) .withExpirationInDays(100) .withStatus(BucketLifecycleConfiguration.DISABLED.toString()); } List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>(); rules.add(ruleArchiveAndExpire); try { BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration() .withRules(rules); s3Client.setBucketLifecycleConfiguration(bucket, configuration); } catch (Exception get) { mainFrame.jTextArea1.append("\n" + get.getMessage()); } if (!disabled) { mainFrame.jTextArea1.append("\nSent request to change bucket life cycle to " + converted_days + " day(s). Please observe for any errors."); } else { mainFrame.jTextArea1.append("\nSent request to disable the bucket life cycle. Please observe for any errors."); } calibrate(); mainFrame.jPanel9.setVisible(true); }
@Override public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub return null; }