Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.s3.model;
 
 import java.util.Date;
 import java.util.List;
 

Provides options for downloading an Amazon S3 object.

All GetObjectRequests must specify a bucket name and key. Beyond that, requests can also specify:

  • The range of bytes within the object to download,
  • Constraints controlling if the object will be downloaded or not.

If you are uploading or accessing KMS-encrypted objects, you need to specify the correct region of the bucket on your client and configure AWS Signature Version 4 for added security. For more information on how to do this, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html#specify -signature-version

 
 public class GetObjectRequest extends AmazonWebServiceRequest implements
         SSECustomerKeyProvider {
    
Builder of an S3 object identifier. This member field is never null.
 
     private S3ObjectIdBuilder s3ObjectIdBuilder = new S3ObjectIdBuilder();

    
Optional member indicating the byte range of data to retrieve
 
     private long[] range;

    
Optional list of ETag values that constrain this request to only be executed if the object's ETag matches one of the specified ETag values.
 
     private List<StringmatchingETagConstraints = new ArrayList<String>();

    
Optional list of ETag values that constrain this request to only be executed if the object's ETag does not match any of the specified ETag constraint values.
 
     private List<StringnonmatchingEtagConstraints = new ArrayList<String>();

    
Optional field that constrains this request to only be executed if the object has not been modified since the specified date.
 
     private Date unmodifiedSinceConstraint;

    
Optional field that constrains this request to only be executed if the object has been modified since the specified date.
 
     private Date modifiedSinceConstraint;

    
Optional field that overrides headers on the response.
 
     private ResponseHeaderOverrides responseHeaders;

    
If enabled, the requester is charged for downloading the data from Requester Pays Buckets.
 
     private boolean isRequesterPays;

    
The optional customer-provided server-side encryption key to use to decrypt this object.
    private SSECustomerKey sseCustomerKey;


    
Constructs a new GetObjectRequest with all the required parameters.

Parameters:
bucketName The name of the bucket containing the desired object.
key The key in the specified bucket under which the object is stored.
See also:
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String,java.lang.String)
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String,boolean)
    public GetObjectRequest(String bucketNameString key) {
        this(bucketNamekeynull);
    }

    
Constructs a new GetObjectRequest with all the required parameters.

Parameters:
bucketName The name of the bucket containing the desired object.
key The key in the specified bucket under which the object is stored.
versionId The Amazon S3 version ID specifying a specific version of the object to download.
See also:
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String)
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String,boolean)
    public GetObjectRequest(String bucketNameString keyString versionId) {
        setBucketName(bucketName);
        setKey(key);
        setVersionId(versionId);
    }
    public GetObjectRequest(S3ObjectId s3ObjectId) {
        this. = new S3ObjectIdBuilder(s3ObjectId);
    }

    
Constructs a new GetObjectRequest with all the required parameters.

Parameters:
bucketName The name of the bucket containing the desired object.
key The key in the specified bucket under which the object is stored.
isRequesterPays If enabled, the requester is charged for downloading the data from Requester Pays Buckets.
See also:
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String)
GetObjectRequest.GetObjectRequest(java.lang.String,java.lang.String,java.lang.String)
    public GetObjectRequest(String bucketNameString key,
            boolean isRequesterPays) {
        this.
            .withBucket(bucketName)
            .withKey(key)
            ;
        this. = isRequesterPays;
    }

    
Gets the name of the bucket containing the object to be downloaded.

Returns:
The name of the bucket containing the object to be downloaded.
See also:
setBucketName(java.lang.String)
withBucketName(java.lang.String)
    public String getBucketName() {
        return .getBucket();
    }

    
Sets the name of the bucket containing the object to be downloaded.

Parameters:
bucketName The name of the bucket containing the object to be downloaded.
See also:
getBucketName()
withBucketName(java.lang.String)
    public void setBucketName(String bucketName) {
        .setBucket(bucketName);
    }

    
Sets the name of the bucket containing the object to be downloaded. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Parameters:
bucketName The name of the bucket containing the object to be downloaded.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getBucketName()
setBucketName(java.lang.String)
    public GetObjectRequest withBucketName(String bucketName) {
        setBucketName(bucketName);
        return this;
    }

    
Gets the key under which the object to be downloaded is stored.

Returns:
The key under which the object to be downloaded is stored.
See also:
setKey(java.lang.String)
withKey(java.lang.String)
    public String getKey() {
        return .getKey();
    }

    
Sets the key under which the object to be downloaded is stored.

Parameters:
key The key under which the object to be downloaded is stored.
See also:
getKey()
withKey(java.lang.String)
    public void setKey(String key) {
        .setKey(key);
    }

    
Sets the key under which the object to be downloaded is stored. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Parameters:
key The key under which the object to be downloaded is stored.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getKey()
setKey(java.lang.String)
    public GetObjectRequest withKey(String key) {
        setKey(key);
        return this;
    }

    

Gets the optional version ID specifying which version of the object to download. If not specified, the most recent version will be downloaded.

Objects created before versioning was enabled or when versioning is suspended are given the default null version ID (see com.amazonaws.services.s3.internal.Constants.NULL_VERSION_ID). Note that the null version ID is a valid version ID and is not the same as not having a version ID.

For more information about enabling versioning for a bucket, see com.amazonaws.services.s3.AmazonS3.setBucketVersioningConfiguration(com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest).

Returns:
The optional version ID specifying which version of the object to download. If not specified, the most recent version will be downloaded.
See also:
setVersionId(java.lang.String)
withVersionId(java.lang.String)
    public String getVersionId() {
        return .getVersionId();
    }

    
Sets the optional version ID specifying which version of the object to download. If not specified, the most recent version will be downloaded.

Objects created before versioning was enabled or when versioning is suspended will be given the default null version ID (see com.amazonaws.services.s3.internal.Constants.NULL_VERSION_ID). Note that the null version ID is a valid version ID and is not the same as not having a version ID.

For more information about enabling versioning for a bucket, see com.amazonaws.services.s3.AmazonS3.setBucketVersioningConfiguration(com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest).

Parameters:
versionId The optional version ID specifying which version of the object to download.
See also:
getVersionId()
withVersionId(java.lang.String)
    public void setVersionId(String versionId) {
        .setVersionId(versionId);
    }

    

Sets the optional version ID specifying which version of the object to download and returns this object, enabling additional method calls to be chained together. If not specified, the most recent version will be downloaded.

Objects created before versioning was enabled or when versioning is suspended will be given the default or null version ID (see com.amazonaws.services.s3.internal.Constants.NULL_VERSION_ID). Note that the null version ID is a valid version ID and is not the same as not having a version ID.

For more information about enabling versioning for a bucket, see com.amazonaws.services.s3.AmazonS3.setBucketVersioningConfiguration(com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest).

Parameters:
versionId The optional version ID specifying which version of the object to download.
Returns:
The updated request object, enabling additional method calls to be chained together.
See also:
getVersionId()
setVersionId(java.lang.String)
    public GetObjectRequest withVersionId(String versionId) {
        setVersionId(versionId);
        return this;
    }
    /*
     * Optional Request Parameters
     */

    

Gets the optional inclusive byte range within the desired object that will be downloaded by this request.

The range is returned as a two element array, containing the start and end index of the byte range. If no byte range has been specified, the entire object is downloaded and this method returns null.

Returns:
A two element array indicating the inclusive start index and end index within the object being downloaded by this request. Returns null if no range has been specified, and the whole object is to be downloaded.
See also:
setRange(long,long)
withRange(long,long)
    public long[] getRange() {
        return  == null ? null : .clone();
    }

    

Sets the optional inclusive byte range within the desired object that will be downloaded by this request.

The first byte in an object has position 0; as an example, the first ten bytes of an object can be downloaded by specifying a range of 0 to 9.

If no byte range is specified, this request downloads the entire object from Amazon S3.

Parameters:
start The start of the inclusive byte range to download.
end The end of the inclusive byte range to download.
See also:
getRange()
withRange(long,long)
    public void setRange(long startlong end) {
         = new long[] {startend};
    }

    

Sets the optional inclusive byte range within the desired object that will be downloaded by this request. Returns this GetObjectRequest, enabling additional method calls to be chained together.

The first byte in an object has position 0; as an example, the first ten bytes of an object can be downloaded by specifying a range of 0 to 9.

If no byte range is specified, this request downloads the entire object from Amazon S3.

Parameters:
start The start of the inclusive byte range to download.
end The end of the inclusive byte range to download.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getRange()
setRange(long,long)
    public GetObjectRequest withRange(long startlong end) {
        setRange(startend);
        return this;
    }

    
Gets the optional list of ETag constraints that, when present, must include a match for the object's current ETag in order for this request to be executed. Only one ETag in the list needs to match for this request to be executed by Amazon S3.

Returns:
The optional list of ETag constraints that when present must include a match for the object's current ETag in order for this request to be executed.
See also:
setMatchingETagConstraints(java.util.List)
withMatchingETagConstraint(java.lang.String)
        return ;
    }

    
Sets the optional list of ETag constraints that when present must include a match for the object's current ETag in order for this request to be executed. If none of the specified ETags match the object's current ETag, this request will not be executed. Only one ETag in the list needs to match for the request to be executed by Amazon S3.

Parameters:
eTagList The optional list of ETag constraints that must include a match for the object's current ETag in order for this request to be executed.
See also:
getMatchingETagConstraints()
withMatchingETagConstraint(java.lang.String)
    public void setMatchingETagConstraints(List<StringeTagList) {
        this. = eTagList;
    }

    
Sets a single ETag constraint to this request. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Multiple ETag constraints can be added to a request, but one must match the object's current ETag in order for this request to be executed. If none of the ETag constraints added to this request match the object's current ETag, this request will not be executed by Amazon S3.

Parameters:
eTag The matching ETag constraint to add to this request.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getMatchingETagConstraints()
setMatchingETagConstraints(java.util.List)
        this..add(eTag);
        return this;
    }

    
Gets the optional list of ETag constraints that when present, must not include a match for the object's current ETag in order for this request to be executed. If any entry in the non-matching ETag constraint list matches the object's current ETag, this request will not be executed by Amazon S3.

Returns:
The optional list of ETag constraints that when present, must not include a match for the object's current ETag in order for this request to be executed.
See also:
setNonmatchingETagConstraints(java.util.List)
withNonmatchingETagConstraint(java.lang.String)
        return ;
    }

    
Sets the optional list of ETag constraints that when present must not include a match for the object's current ETag in order for this request to be executed. If any entry in the non-matching ETag constraint list matches the object's current ETag, this request will not be executed by Amazon S3.

Parameters:
eTagList The list of ETag constraints that, when present, must not include a match for the object's current ETag in order for this request to be executed.
See also:
getNonmatchingETagConstraints()
withNonmatchingETagConstraint(java.lang.String)
    public void setNonmatchingETagConstraints(List<StringeTagList) {
        this. = eTagList;
    }

    
Sets a single ETag constraint to this request. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Multiple ETag constraints can be added to a request, but all ETag constraints must not match the object's current ETag in order for this request to be executed. If any entry in the non-matching ETag constraint list matches the object's current ETag, this request will not be executed by Amazon S3.

Parameters:
eTag The non-matching ETag constraint to add to this request.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getNonmatchingETagConstraints()
setNonmatchingETagConstraints(java.util.List)
        this..add(eTag);
        return this;
    }

    
Gets the optional unmodified constraint that restricts this request to executing only if the object has not been modified after the specified date.

Returns:
The optional unmodified constraint that restricts this request to executing only if the object has not been modified after the specified date.
See also:
setUnmodifiedSinceConstraint(java.util.Date)
withUnmodifiedSinceConstraint(java.util.Date)
        return ;
    }

    
Sets the optional unmodified constraint that restricts this request to executing only if the object has not been modified after the specified date.

Note that Amazon S3 will ignore any dates occurring in the future.

Parameters:
date The unmodified constraint that restricts this request to executing only if the object has not been modified after this date.
See also:
getUnmodifiedSinceConstraint()
withUnmodifiedSinceConstraint(java.util.Date)
    public void setUnmodifiedSinceConstraint(Date date) {
        this. = date;
    }

    
Sets the optional unmodified constraint that restricts this request to executing only if the object has not been modified after the specified date. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Note that Amazon S3 will ignore any dates occurring in the future.

Parameters:
date The unmodified constraint that restricts this request to executing only if the object has not been modified after this date.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getUnmodifiedSinceConstraint()
setUnmodifiedSinceConstraint(java.util.Date)
        setUnmodifiedSinceConstraint(date);
        return this;
    }

    
Gets the optional modified constraint that restricts this request to executing only if the object has been modified after the specified date.

Returns:
The optional modified constraint that restricts this request to executing only if the object has been modified after the specified date.
See also:
setModifiedSinceConstraint(java.util.Date)
withModifiedSinceConstraint(java.util.Date)
    public Date getModifiedSinceConstraint() {
        return ;
    }

    
Sets the optional modified constraint that restricts this request to executing only if the object has been modified after the specified date.

Note that Amazon S3 will ignore any dates occurring in the future.

Parameters:
date The modified constraint that restricts this request to executing only if the object has been modified after the specified date.
See also:
getModifiedSinceConstraint()
withModifiedSinceConstraint(java.util.Date)
    public void setModifiedSinceConstraint(Date date) {
        this. = date;
    }

    
Sets the optional modified constraint that restricts this request to executing only if the object has been modified after the specified date. Returns this GetObjectRequest, enabling additional method calls to be chained together.

Note that Amazon S3 will ignore any dates occurring in the future.

Parameters:
date The modified constraint that restricts this request to executing only if the object has been modified after the specified date.
Returns:
This GetObjectRequest, enabling additional method calls to be chained together.
See also:
getModifiedSinceConstraint()
setModifiedSinceConstraint(java.util.Date)
        setModifiedSinceConstraint(date);
        return this;
    }

    
Returns the headers to be overridden in the service response.

Returns:
the headers to be overridden in the service response.
        return ;
    }

    
Sets the headers to be overridden in the service response.

Parameters:
responseHeaders The headers to be overridden in the service response.
    public void setResponseHeaders(ResponseHeaderOverrides responseHeaders) {
        this. = responseHeaders;
    }

    
Sets the headers to be overridden in the service response and returns this object, for method chaining.

Parameters:
responseHeaders The headers to be overridden in the service response.
Returns:
This GetObjectRequest for method chaining.
        setResponseHeaders(responseHeaders);
        return this;
    }

    
Sets the optional progress listener for receiving updates about object download status.

Deprecated:
use com.amazonaws.AmazonWebServiceRequest.setGeneralProgressListener(com.amazonaws.event.ProgressListener) instead.
Parameters:
progressListener The legacy progress listener that is used exclusively for Amazon S3 client.
    @Deprecated
    public void setProgressListener(com.amazonaws.services.s3.model.ProgressListener progressListener) {
        setGeneralProgressListener(new LegacyS3ProgressListener(progressListener));
    }

    
Returns the optional progress listener for receiving updates about object download status.

Deprecated:
use com.amazonaws.AmazonWebServiceRequest.getGeneralProgressListener() instead.
Returns:
the optional progress listener for receiving updates about object download status.
    @Deprecated
        ProgressListener generalProgressListener = getGeneralProgressListener();
        if (generalProgressListener instanceof LegacyS3ProgressListener) {
            return ((LegacyS3ProgressListener)generalProgressListener).unwrap();
        } else {
             return null;
        }
    }

    
Sets the optional progress listener for receiving updates about object download status, and returns this updated object so that additional method calls can be chained together.

Deprecated:
use com.amazonaws.AmazonWebServiceRequest.withGeneralProgressListener(com.amazonaws.event.ProgressListener) instead.
Parameters:
progressListener The legacy progress listener that is used exclusively for Amazon S3 client.
Returns:
This updated GetObjectRequest object.
    @Deprecated
        setProgressListener(progressListener);
        return this;
    }

    
Returns true if the user has enabled Requester Pays option when downloading an object from Requester Pays Bucket; else false.

If a bucket is enabled for Requester Pays, then any attempt to read an object from it without Requester Pays enabled will result in a 403 error and the bucket owner will be charged for the request.

Enabling Requester Pays disables the ability to have anonymous access to this bucket

Returns:
true if the user has enabled Requester Pays option for downloading an object from Requester Pays Bucket.
    public boolean isRequesterPays() {
        return ;
    }

    
Used for downloading an Amazon S3 Object from a Requester Pays Bucket. If set the requester is charged for downloading the data from the bucket.

If a bucket is enabled for Requester Pays, then any attempt to read an object from it without Requester Pays enabled will result in a 403 error and the bucket owner will be charged for the request.

Enabling Requester Pays disables the ability to have anonymous access to this bucket

Parameters:
isRequesterPays Enable Requester Pays option for the operation.
    public void setRequesterPays(boolean isRequesterPays) {
        this. = isRequesterPays;
    }
    @Override
    public SSECustomerKey getSSECustomerKey() {
        return ;
    }

    
Sets the optional customer-provided server-side encryption key to use to decrypt this object.

Parameters:
sseKey The optional customer-provided server-side encryption key to use to decrypt this object.
    public void setSSECustomerKey(SSECustomerKey sseKey) {
        this. = sseKey;
    }

    
Sets the optional customer-provided server-side encryption key to use to decrypt this object, and returns the updated GetObjectRequest so that additional method calls may be chained together.

Parameters:
sseKey The optional customer-provided server-side encryption key to use to decrypt this object.
Returns:
The optional customer-provided server-side encryption key to use to decrypt this object.
        setSSECustomerKey(sseKey);
        return this;
    }

    
Returns an immutable S3 object id.
    public S3ObjectId getS3ObjectId() {
        return .build();
    }

    
Sets the S3 object id for this request.
    public void setS3ObjectId(S3ObjectId s3ObjectId) {
        this. = new S3ObjectIdBuilder(s3ObjectId);
    }

    
Fluent API to set the S3 object id for this request.
    public GetObjectRequest withS3ObjectId(S3ObjectId s3ObjectId) {
        setS3ObjectId(s3ObjectId);
        return this;
    }
New to GrepCode? Check out our FAQ X