forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create file and test with snippets to use on this page of the Java De…
…v Guide: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/transfer-manager.html checkstyle test added, which required modifying other existing files dependencies updated
- Loading branch information
1 parent
9eb886e
commit 4e56eb4
Showing
8 changed files
with
260 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
javav2/example_code/s3/src/main/java/com/example/s3/transfermanager/FileUpDownOps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//snippet-sourcedescription:[FileUpDownOps.java demonstrates how to upload and download an object to an Amazon Simple Storage Service (Amazon S3) bucket.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-service:[Amazon S3] | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.example.s3.transfermanager; | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.import] | ||
|
||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.transfer.s3.CompletedFileDownload; | ||
import software.amazon.awssdk.transfer.s3.CompletedFileUpload; | ||
import software.amazon.awssdk.transfer.s3.FileDownload; | ||
import software.amazon.awssdk.transfer.s3.FileUpload; | ||
import software.amazon.awssdk.transfer.s3.S3ClientConfiguration; | ||
import software.amazon.awssdk.transfer.s3.S3TransferManager; | ||
|
||
import java.nio.file.Paths; | ||
|
||
import static software.amazon.awssdk.transfer.s3.SizeConstant.MB; | ||
|
||
public class FileUpDownOps { | ||
|
||
private String bucketName; | ||
private String key; | ||
private String filePath; | ||
private String downloadedFileName; | ||
|
||
public FileUpDownOps(String bucketName, String key, String filePath, String downloadedFileName) { | ||
this.bucketName = bucketName; | ||
this.key = key; | ||
this.filePath = filePath; | ||
this.downloadedFileName = downloadedFileName; | ||
} | ||
|
||
public String fileUploadDownload() { | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.createclients] | ||
S3ClientConfiguration s3ClientConfiguration = | ||
S3ClientConfiguration.builder() | ||
.region(Region.US_EAST_1) | ||
.minimumPartSizeInBytes(10 * MB) | ||
.targetThroughputInGbps(20.0) | ||
.build(); | ||
|
||
S3TransferManager s3TransferManager = S3TransferManager.builder() | ||
.s3ClientConfiguration(s3ClientConfiguration) | ||
.build(); | ||
// snippet-end:[s3.tm.java2.file_up_down_ops.createclients] | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.fileupload] | ||
FileUpload fileUpload = s3TransferManager.uploadFile(uploadFileRequestBuilder -> | ||
uploadFileRequestBuilder | ||
.putObjectRequest( | ||
putObjectRequestBuilder -> putObjectRequestBuilder.bucket(bucketName).key(key)) | ||
.source(Paths.get(filePath))); | ||
// snippet-end:[s3.tm.java2.file_up_down_ops.fileupload] | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.fileuploadresult] | ||
CompletedFileUpload uploadResult = fileUpload.completionFuture().join(); | ||
System.out.println("Etag: " + uploadResult.response().eTag()); | ||
// snippet-end:[s3.tm.java2.file_up_down_ops.fileuploadresult] | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.filedownload] | ||
FileDownload downloadFile = s3TransferManager.downloadFile( | ||
downloadFileRequestBuilder -> downloadFileRequestBuilder | ||
.getObjectRequest(getObjectRequestBuilder -> | ||
getObjectRequestBuilder.bucket(bucketName).key(key)) | ||
.destination(Paths.get(downloadedFileName))); | ||
// snippet-end:[s3.tm.java2.file_up_down_ops.filedownload] | ||
|
||
// snippet-start:[s3.tm.java2.file_up_down_ops.filedownloadresult] | ||
CompletedFileDownload downloadResult = downloadFile.completionFuture().join(); | ||
System.out.println("Content length: " + downloadResult.response().contentLength()); | ||
// snippet-end:[s3.tm.java2.file_up_down_ops.filedownloadresult] | ||
|
||
return uploadResult.response().eTag() + "|" + downloadResult.response().contentType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<!DOCTYPE module PUBLIC | ||
"-//Checkstyle//DTD Checkstyle Configuration 1.2//EN" | ||
"https://checkstyle.org/dtds/configuration_1_2.dtd"> | ||
|
||
<module name="Checker"> | ||
<module name="TreeWalker"> | ||
|
||
<module name="IllegalCatch"/> | ||
<module name="EmptyStatement"/> | ||
<module name="AvoidStarImport"/> | ||
<module name="UnusedImports"/> | ||
<module name="ParameterAssignment"/> | ||
<module name="LocalVariableName"/> | ||
<module name="NoLineWrap"/> | ||
<module name="SingleSpaceSeparator"/> | ||
<module name="MethodName"/> | ||
<module name="MemberName"/> | ||
<module name="LocalVariableName"/> | ||
<module name="LeftCurly"/> | ||
<module name="RightCurly"/> | ||
<module name="DeclarationOrder"/> | ||
</module> | ||
</module> |
Empty file.
Oops, something went wrong.