public static S3Object retryableDownloadS3ObjectToFile(File file,
            RetryableS3DownloadTask retryableS3DownloadTask, boolean appendData) {
        boolean hasRetried = false;
        boolean needRetry;
        S3Object s3Object;
        do {
            needRetry = false;
            s3Object = retryableS3DownloadTask.getS3ObjectStream();
            if ( s3Object == null )
                return null;

            try {
                ServiceUtils.downloadObjectToFile(s3Object, file,
                        retryableS3DownloadTask.needIntegrityCheck(),
                        appendData);
            } catch (SdkClientException ace) {
                if (!ace.isRetryable()) {
                    s3Object.getObjectContent().abort();
                    throw ace;
                }
                // Determine whether an immediate retry is needed according to the captured SdkClientException.
                // (There are three cases when downloadObjectToFile() throws SdkClientException:
                //        1) SocketException or SSLProtocolException when writing to disk (e.g. when user aborts the download)
                //        2) Other IOException when writing to disk
                //        3) MD5 hashes don't match
                // The current code will retry the download only when case 2) or 3) happens.
                if (ace.getCause() instanceof SocketException || ace.getCause() instanceof SSLProtocolException) {
                    throw ace;
                } else {
                    needRetry = true;
                    if ( hasRetried ) {
                        s3Object.getObjectContent().abort();
                        throw ace;
                    } else {
                        LOG.info("Retry the download of object " + s3Object.getKey() + " (bucket " + s3Object.getBucketName() + ")", ace);
                        hasRetried = true;
                    }
                }
            }
        } while ( needRetry );
        return s3Object;
    }
public static S3Object retryableDownloadS3ObjectToFile ( File file , RetryableS3DownloadTask retryableS3DownloadTask , boolean appendData ) { boolean hasRetried = false ; boolean needRetry ; S3Object s3Object ; do { needRetry = false ; s3Object = retryableS3DownloadTask . getS3ObjectStream ( ) ; if ( s3Object == null ) return null ; try { ServiceUtils . downloadObjectToFile ( s3Object , file , retryableS3DownloadTask . needIntegrityCheck ( ) , appendData ) ; } catch ( SdkClientException ace ) { if ( ! ace . isRetryable ( ) ) { s3Object . getObjectContent ( ) . abort ( ) ; throw ace ; } if ( ace . getCause ( ) instanceof SocketException || ace . getCause ( ) instanceof SSLProtocolException ) { throw ace ; } else { needRetry = true ; if ( hasRetried ) { s3Object . getObjectContent ( ) . abort ( ) ; throw ace ; } else { LOG . info ( "Retry the download of object " + s3Object . getKey ( ) + " (bucket " + s3Object . getBucketName ( ) + ")" , ace ) ; hasRetried = true ; } } } } while ( needRetry ) ; return s3Object ; }
Gets an object stored in S3 and downloads it into the specified file.
This method includes the one-time retry mechanism after integrity check failure
on the downloaded file. It will also return immediately after getting null valued
S3Object (when getObject request does not meet the specified constraints).

@param file
The file to store the object's data in.
@param retryableS3DownloadTask
The implementation of SafeS3DownloadTask interface which allows user to
get access to all the visible variables at the calling site of this method.