本文整理汇总了Java中com.amazonaws.services.s3.model.GetObjectRequest.setResponseHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java GetObjectRequest.setResponseHeaders方法的具体用法?Java GetObjectRequest.setResponseHeaders怎么用?Java GetObjectRequest.setResponseHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.GetObjectRequest
的用法示例。
在下文中一共展示了GetObjectRequest.setResponseHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: testAwsV2SignatureWithOverrideParameters
import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Test
public void testAwsV2SignatureWithOverrideParameters() throws Exception {
client = AmazonS3ClientBuilder.standard()
.withClientConfiguration(V2_SIGNER_CONFIG)
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withEndpointConfiguration(s3EndpointConfig).build();
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, "foo", BYTE_SOURCE.openStream(),
metadata);
String blobName = "foo";
ResponseHeaderOverrides headerOverride = new ResponseHeaderOverrides();
String expectedContentDisposition = "attachment; " + blobName;
headerOverride.setContentDisposition(expectedContentDisposition);
String expectedContentType = "text/plain";
headerOverride.setContentType(expectedContentType);
GetObjectRequest request = new GetObjectRequest(containerName,
blobName);
request.setResponseHeaders(headerOverride);
S3Object object = client.getObject(request);
assertThat(object.getObjectMetadata().getContentLength()).isEqualTo(
BYTE_SOURCE.size());
assertThat(object.getObjectMetadata().getContentDisposition())
.isEqualTo(expectedContentDisposition);
assertThat(object.getObjectMetadata().getContentType()).isEqualTo(
expectedContentType);
try (InputStream actual = object.getObjectContent();
InputStream expected = BYTE_SOURCE.openStream()) {
assertThat(actual).hasContentEqualTo(expected);
}
}
示例3: testOverrideResponseHeader
import com.amazonaws.services.s3.model.GetObjectRequest; //导入方法依赖的package包/类
@Test
public void testOverrideResponseHeader() throws Exception {
String blobName = "foo";
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
client.putObject(containerName, blobName, BYTE_SOURCE.openStream(),
metadata);
String cacheControl = "no-cache";
String contentDisposition = "attachment; filename=foo.html";
String contentEncoding = "gzip";
String contentLanguage = "en";
String contentType = "text/html; charset=UTF-8";
String expires = "Wed, 13 Jul 2016 21:23:51 GMT";
long expiresTime = 1468445031000L;
GetObjectRequest getObjectRequest = new GetObjectRequest(containerName,
blobName);
getObjectRequest.setResponseHeaders(
new ResponseHeaderOverrides()
.withCacheControl(cacheControl)
.withContentDisposition(contentDisposition)
.withContentEncoding(contentEncoding)
.withContentLanguage(contentLanguage)
.withContentType(contentType)
.withExpires(expires));
S3Object object = client.getObject(getObjectRequest);
try (InputStream is = object.getObjectContent()) {
assertThat(is).isNotNull();
ByteStreams.copy(is, ByteStreams.nullOutputStream());
}
ObjectMetadata reponseMetadata = object.getObjectMetadata();
assertThat(reponseMetadata.getCacheControl()).isEqualTo(
cacheControl);
assertThat(reponseMetadata.getContentDisposition()).isEqualTo(
contentDisposition);
assertThat(reponseMetadata.getContentEncoding()).isEqualTo(
contentEncoding);
assertThat(reponseMetadata.getContentLanguage()).isEqualTo(
contentLanguage);
assertThat(reponseMetadata.getContentType()).isEqualTo(
contentType);
assertThat(reponseMetadata.getHttpExpiresDate().getTime())
.isEqualTo(expiresTime);
}