本文整理汇总了Java中com.amazonaws.services.s3.model.GetObjectRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetObjectRequest类的具体用法?Java GetObjectRequest怎么用?Java GetObjectRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetObjectRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了GetObjectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGet
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
@Test
public void testGet() {
AmazonS3 client = mock(AmazonS3.class);
S3StoreService service = new S3StoreService(client, S3_BUCKET, S3_PREFIX);
String path = "path";
String value = "value";
ArgumentCaptor<GetObjectRequest> request = ArgumentCaptor.forClass(GetObjectRequest.class);
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new S3ObjectInputStream(IOUtils.toInputStream(value), mock(HttpRequestBase.class)));
when(client.getObject(request.capture())).thenReturn(s3Object);
// invoke method under test
Optional<String> result = service.get(path);
assertTrue(result.isPresent());
assertEquals(value, result.get());
assertEquals(S3_BUCKET, request.getValue().getBucketName());
assertEquals(S3_PREFIX + "/" + path, request.getValue().getKey());
}
示例2: getObject
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
@Override
public S3Object getObject(GetObjectRequest getObjectRequest)
throws AmazonClientException, AmazonServiceException {
// in ESBlobStoreContainerTestCase.java, the prefix is empty,
// so the key and blobName are equivalent to each other
String blobName = getObjectRequest.getKey();
if (!blobs.containsKey(blobName)) {
throw new AmazonS3Exception("[" + blobName + "] does not exist.");
}
// the HTTP request attribute is irrelevant for reading
S3ObjectInputStream stream = new S3ObjectInputStream(
blobs.get(blobName), null, false);
S3Object s3Object = new S3Object();
s3Object.setObjectContent(stream);
return s3Object;
}
示例3: doGetS3Object
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
private S3Object doGetS3Object(URI uri, boolean isLightWeight) {
S3RegionalResource s3RegionalResource = new S3RegionalResource(uri);
String bucketName = s3RegionalResource.getBucketName();
String s3BucketKey = s3RegionalResource.getKey();
configureClient(s3RegionalResource);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, s3BucketKey);
if (isLightWeight) {
//Skip content download
getObjectRequest.setRange(0, 0);
}
try {
return amazonS3Client.getObject(getObjectRequest);
} catch (AmazonServiceException e) {
String errorCode = e.getErrorCode();
if (null != errorCode && errorCode.equalsIgnoreCase("NoSuchKey")) {
return null;
}
throw ResourceExceptions.getFailed(uri, e);
}
}
示例4: getFileByLocationId
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Performs a {@link GetObjectRequest} to the S3 bucket by file id for the file
*
* @param fileLocationId Id of the file to search for
* @return file found from S3
*/
@Override
public InputStream getFileByLocationId(String fileLocationId) {
final String bucketName = environment.getProperty(Constants.BUCKET_NAME_ENV_VARIABLE);
if (Strings.isNullOrEmpty(bucketName)) {
API_LOG.warn("No bucket name is specified.");
return null;
}
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, fileLocationId);
S3Object s3Object = amazonS3.getObject(getObjectRequest);
API_LOG.info("Successfully retrieved the file from S3 bucket {}", getObjectRequest.getBucketName());
return s3Object.getObjectContent();
}
示例5: getInventoryReportToString
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Get the original inventory report from S3, unzip it, and transfer it into a String format.
* @return inventReport String
* @throws IOException when getting object from S3 fails
* or the checksum of the inventory report and the checksum specified in the manifest file not match
*/
public String getInventoryReportToString() throws IOException {
String inventReportKey = locator.getKey();
String bucketName = inventoryManifest.getSourceBucket();
try (S3Object s3InventoryReport = s3Client.getObject(
new GetObjectRequest(bucketName, inventReportKey))) {
InputStream objectData = s3InventoryReport.getObjectContent();
byte[] zippedData = IOUtils.toByteArray(objectData);
String actualChecksum = DigestUtils.md5Hex(zippedData);
String expectedChecksum = locator.getMD5checksum();
if (!actualChecksum.equals(expectedChecksum)) {
throw new ChecksumMismatchException (expectedChecksum, actualChecksum);
}
return IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(zippedData)));
}
}
示例6: getInventoryManifest
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Check if the MD5s of manifest.json and manifest.checksum equal
* if so, pull out the manifest file and map it into a POJO
* @return inventoryManifestStorage InventoryManifest, which stores all the elements of the manifest.json file
*/
public InventoryManifest getInventoryManifest() throws Exception {
// Get manifest.json and transfer it to String
GetObjectRequest requestJson = new GetObjectRequest(bucketName, bucketKeyJson);
S3Object jsonObject = s3Client.getObject(requestJson);
String jsonFile = inputStreamToString(jsonObject.getObjectContent());
jsonObject.close();
// Get manifest.checksum and transfer it to String with no whitespace
GetObjectRequest requestChecksum = new GetObjectRequest(bucketName, bucketKeyChecksum);
S3Object checksumObject = s3Client.getObject(requestChecksum);
String expectedChecksum = inputStreamToString(checksumObject.getObjectContent())
.replaceAll("\\s","");
checksumObject.close();
// Compare manifest.json and manifest.checksum's MD5 value
String actualChecksum = DigestUtils.md5Hex(jsonFile);
if (!actualChecksum.equals(expectedChecksum)) {
throw new ChecksumMismatchException (expectedChecksum, actualChecksum);
}
return mapper.readValue(jsonFile, InventoryManifest.class);
}
示例7: getInventReportSuccess
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
@Test
public void getInventReportSuccess() throws Exception {
testLocator.setMD5checksum(testMD5);
testManifest.setFileSchema("storageClass, size");
reportRetriever = new InventoryReportRetriever(mockS3Client, testLocator, testManifest);
String expectedInventoryReportString = "testString";
byte[] expectedInventoryReportBytes = inventReportBytes(expectedInventoryReportString);
when(mockS3Object.getObjectContent()).thenReturn(new S3ObjectInputStream(
new ByteArrayInputStream(expectedInventoryReportBytes), null));
when(mockS3Client.getObject(getObjectRequestCaptor.capture())).thenReturn(mockS3Object);
String result = reportRetriever.getInventoryReportToString();
assertThat(result, is(expectedInventoryReportString));
GetObjectRequest request = getObjectRequestCaptor.getValue();
assertThat(request.getBucketName(), is("testBucket"));
assertThat(request.getKey(), is("testInventReportKey"));
}
示例8: getInventoryManifestSuccess
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
@Test
public void getInventoryManifestSuccess() throws Exception {
InventoryManifest expectedManifest = manifest();
byte[] expectedManifestBytes = manifestBytes(expectedManifest);
when(mockS3JsonObject.getObjectContent()).thenReturn(new S3ObjectInputStream(
new ByteArrayInputStream(expectedManifestBytes), null));
String expectedChecksum = "a6121a6a788be627a68d7e9def9f6968";
byte[] expectedChecksumBytes = expectedChecksum.getBytes(StandardCharsets.UTF_8);
when(mockS3ChecksumObject.getObjectContent()).thenReturn(new S3ObjectInputStream(
new ByteArrayInputStream(expectedChecksumBytes), null));
when(mockS3Client.getObject(getObjectRequestCaptor.capture()))
.thenReturn(mockS3JsonObject)
.thenReturn(mockS3ChecksumObject);
InventoryManifest result = retriever.getInventoryManifest();
assertThat(result, is(expectedManifest));
List<GetObjectRequest> request = getObjectRequestCaptor.getAllValues();
assertThat(request.get(0).getBucketName(), is("testBucketName"));
assertThat(request.get(0).getKey(), is("testBucketKey/manifest.json"));
assertThat(request.get(1).getBucketName(), is("testBucketName"));
assertThat(request.get(1).getKey(), is("testBucketKey/manifest.checksum"));
}
示例9: getS3Value
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Attempt to fetch a secret from S3.
*
* @param s3path where to fetch it from
* @return the content of the file found on S3
* @throws IOException on problems streaming the content of the file
* @throws AmazonS3Exception on problems communicating with amazon
*/
private String getS3Value(final SecretPath s3path) throws IOException, AmazonS3Exception {
LOG.info("Fetching secret from s3://" + s3path.bucket + "/" + s3path.key);
if (s3Client == null) {
if (awsCredentialsProvider != null) {
s3Client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider)
.build();
} else {
s3Client = AmazonS3ClientBuilder.standard().build();
}
}
final S3Object s3object
= s3Client.getObject(new GetObjectRequest(s3path.bucket, s3path.key));
final BufferedReader reader
= new BufferedReader(new InputStreamReader(s3object.getObjectContent()));
final StringBuilder b = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
b.append(line);
}
LOG.info("Found secret");
reader.close();
return b.toString();
}
示例10: getObject
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
@Override
public ObjectMetadata getObject(final GetObjectRequest getObjectRequest, File destinationFile)
throws SdkClientException, AmazonServiceException {
rejectNull(destinationFile,
"The destination file parameter must be specified when downloading an object directly to a file");
S3Object s3Object = ServiceUtils.retryableDownloadS3ObjectToFile(destinationFile, new ServiceUtils.RetryableS3DownloadTask() {
@Override
public S3Object getS3ObjectStream() {
return getObject(getObjectRequest);
}
@Override
public boolean needIntegrityCheck() {
return !skipMd5CheckStrategy.skipClientSideValidationPerRequest(getObjectRequest);
}
}, ServiceUtils.OVERWRITE_MODE);
// getObject can return null if constraints were specified but not met
if (s3Object == null) return null;
return s3Object.getObjectMetadata();
}
示例11: DownloadCallable
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
DownloadCallable(AmazonS3 s3, CountDownLatch latch,
GetObjectRequest req, boolean resumeExistingDownload,
DownloadImpl download, File dstfile, long origStartingByte,
long expectedFileLength, long timeout,
ScheduledExecutorService timedExecutor,
ExecutorService executor,
Integer lastFullyDownloadedPartNumber, boolean isDownloadParallel, boolean resumeOnRetry)
{
if (s3 == null || latch == null || req == null || dstfile == null || download == null)
throw new IllegalArgumentException();
this.s3 = s3;
this.latch = latch;
this.req = req;
this.resumeExistingDownload = resumeExistingDownload;
this.download = download;
this.dstfile = dstfile;
this.origStartingByte = origStartingByte;
this.expectedFileLength = expectedFileLength;
this.timeout = timeout;
this.timedExecutor = timedExecutor;
this.executor = executor;
this.futureFiles = new ArrayList<Future<File>>();
this.lastFullyMergedPartNumber = lastFullyDownloadedPartNumber;
this.isDownloadParallel = isDownloadParallel;
this.resumeOnRetry = resumeOnRetry;
}
示例12: downloadInParallel
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Downloads each part of the object into a separate file synchronously and
* combines all the files into a single file.
*/
private void downloadInParallel(int partCount) throws Exception {
if (lastFullyMergedPartNumber == null) {
lastFullyMergedPartNumber = 0;
}
for (int i = lastFullyMergedPartNumber + 1; i <= partCount; i++) {
GetObjectRequest getPartRequest = new GetObjectRequest(req.getBucketName(), req.getKey(),
req.getVersionId()).withUnmodifiedSinceConstraint(req.getUnmodifiedSinceConstraint())
.withModifiedSinceConstraint(req.getModifiedSinceConstraint())
.withResponseHeaders(req.getResponseHeaders()).withSSECustomerKey(req.getSSECustomerKey())
.withGeneralProgressListener(req.getGeneralProgressListener());
getPartRequest.setMatchingETagConstraints(req.getMatchingETagConstraints());
getPartRequest.setNonmatchingETagConstraints(req.getNonmatchingETagConstraints());
getPartRequest.setRequesterPays(req.isRequesterPays());
futureFiles.add(
executor.submit(new DownloadPartCallable(s3, getPartRequest.withPartNumber(i), dstfile)));
}
truncateDestinationFileIfNecessary();
Future<File> future = executor.submit(new CompleteMultipartDownload(futureFiles, dstfile, download, ++lastFullyMergedPartNumber));
((DownloadMonitor) download.getMonitor()).setFuture(future);
}
示例13: resumeDownload
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Resumes an download operation. This download operation uses the same
* configuration as the original download. Any data already fetched will be
* skipped, and only the remaining data is retrieved from Amazon S3.
*
* @param persistableDownload
* the download to resume.
* @return A new <code>Download</code> object to use to check the state of
* the download, listen for progress notifications, and otherwise
* manage the download.
*
* @throws AmazonClientException
* If any errors are encountered in the client while making the
* request or handling the response.
* @throws AmazonServiceException
* If any errors occurred in Amazon S3 while processing the
* request.
*/
public Download resumeDownload(PersistableDownload persistableDownload) {
assertParameterNotNull(persistableDownload,
"PausedDownload is mandatory to resume a download.");
GetObjectRequest request = new GetObjectRequest(
persistableDownload.getBucketName(), persistableDownload.getKey(),
persistableDownload.getVersionId());
if (persistableDownload.getRange() != null
&& persistableDownload.getRange().length == 2) {
long[] range = persistableDownload.getRange();
request.setRange(range[0], range[1]);
}
request.setRequesterPays(persistableDownload.isRequesterPays());
request.setResponseHeaders(persistableDownload.getResponseHeaders());
return doDownload(request, new File(persistableDownload.getFile()), null, null,
APPEND_MODE, 0,
persistableDownload.getLastFullyDownloadedPartNumber(),
persistableDownload.getlastModifiedTime());
}
示例14: decipherWithInstFileSuffix
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Same as {@link #decipher(GetObjectRequest, long[], long[], S3Object)}
* but makes use of an instruction file with the specified suffix.
* @param instFileSuffix never null or empty (which is assumed to have been
* sanitized upstream.)
*/
private S3Object decipherWithInstFileSuffix(GetObjectRequest req,
long[] desiredRange, long[] cryptoRange, S3Object retrieved,
String instFileSuffix) {
final S3ObjectId id = req.getS3ObjectId();
// Check if encrypted info is in an instruction file
final S3ObjectWrapper ifile = fetchInstructionFile(id, instFileSuffix);
if (ifile == null) {
throw new SdkClientException("Instruction file with suffix "
+ instFileSuffix + " is not found for " + retrieved);
}
try {
return decipherWithInstructionFile(req, desiredRange,
cryptoRange, new S3ObjectWrapper(retrieved, id), ifile);
} finally {
closeQuietly(ifile, log);
}
}
示例15: checkRangeDownloads
import com.amazonaws.services.s3.model.GetObjectRequest; //导入依赖的package包/类
/**
* Verify that range-downloads work.
*
* @throws Exception not expected
*/
@Test
public void checkRangeDownloads() throws Exception {
final File uploadFile = new File(UPLOAD_FILE_NAME);
s3Client.createBucket(BUCKET_NAME);
final TransferManager transferManager = createDefaultTransferManager();
final Upload upload =
transferManager.upload(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
upload.waitForUploadResult();
final File downloadFile = File.createTempFile(UUID.randomUUID().toString(), null);
transferManager
.download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(1, 2),
downloadFile)
.waitForCompletion();
assertThat("Invalid file length", downloadFile.length(), is(2L));
transferManager
.download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(0, 1000),
downloadFile)
.waitForCompletion();
assertThat("Invalid file length", downloadFile.length(), is(uploadFile.length()));
}