public class ServiceUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
ServiceUtils.RetryableS3DownloadTask
Interface for the task of downloading object from S3 to a specific file,
enabling one-time retry mechanism after integrity check failure on the
downloaded file.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
APPEND_MODE
boolean to enable append mode
|
protected static com.amazonaws.util.DateUtils |
DATE_UTILS
Deprecated.
|
static boolean |
OVERWRITE_MODE
boolean to disable overwrite mode
|
Constructor and Description |
---|
ServiceUtils() |
Modifier and Type | Method and Description |
---|---|
static java.net.URL |
convertRequestToUrl(com.amazonaws.Request<?> request)
Converts the specified request object into a URL, containing all the
specified parameters, the specified request endpoint, etc.
|
static java.net.URL |
convertRequestToUrl(com.amazonaws.Request<?> request,
boolean removeLeadingSlashInResourcePath)
Converts the specified request object into a URL, containing all the
specified parameters, the specified request endpoint, etc.
|
static void |
downloadObjectToFile(S3Object s3Object,
java.io.File destinationFile,
boolean performIntegrityCheck,
boolean appendData)
Downloads an S3Object, as returned from
AmazonS3Client.getObject(com.amazonaws.services.s3.model.GetObjectRequest)
, to the specified file. |
static java.lang.String |
formatIso8601Date(java.util.Date date)
Formats an instance of Date to ISO-8601.
|
static java.lang.String |
formatRfc822Date(java.util.Date date)
Formats an instance of Date to RFC-822.
|
static boolean |
isMultipartUploadETag(java.lang.String eTag)
Returns true if the specified ETag was from a multipart upload.
|
static java.lang.String |
join(java.util.List<java.lang.String> strings)
Returns a new string created by joining each of the strings in the
specified list together, with a comma between them.
|
static java.util.Date |
parseIso8601Date(java.lang.String dateString)
Parses a date in ISO-8601 format to a Date object.
|
static java.util.Date |
parseRfc822Date(java.lang.String dateString)
Parses a date in RFC-822 format to a Date object.
|
static java.lang.String |
removeQuotes(java.lang.String s)
Removes any surrounding quotes from the specified string and returns a
new string.
|
static S3Object |
retryableDownloadS3ObjectToFile(java.io.File file,
ServiceUtils.RetryableS3DownloadTask retryableS3DownloadTask,
boolean appendData)
Gets an object stored in S3 and downloads it into the specified file.
|
static boolean |
skipMd5CheckPerRequest(com.amazonaws.AmazonWebServiceRequest request)
Returns whether the specified request should skip MD5 check on the
requested object content.
|
static boolean |
skipMd5CheckPerRequest(com.amazonaws.AmazonWebServiceRequest request,
S3ClientOptions clientOptions)
Returns whether the specified request should skip MD5 check on the
requested object content.
|
static boolean |
skipMd5CheckPerResponse(ObjectMetadata metadata)
Based on the given metadata of an S3 response, Returns whether the
specified request should skip MD5 check on the requested object content.
|
static boolean |
skipMd5CheckPerResponse(ObjectMetadata metadata,
S3ClientOptions clientOptions)
Based on the given metadata of an S3 response, Returns whether the
specified request should skip MD5 check on the requested object content.
|
static byte[] |
toByteArray(java.lang.String s)
Safely converts a string to a byte array, first attempting to explicitly
use our preferred encoding (UTF-8), and then falling back to the
platform's default encoding if for some reason our preferred encoding
isn't supported.
|
public static final boolean APPEND_MODE
public static final boolean OVERWRITE_MODE
@Deprecated protected static final com.amazonaws.util.DateUtils DATE_UTILS
public static java.util.Date parseIso8601Date(java.lang.String dateString)
dateString
- the date in ISO-8601 format.public static java.lang.String formatIso8601Date(java.util.Date date)
date
- Datepublic static java.util.Date parseRfc822Date(java.lang.String dateString)
dateString
- the date in RFC-822 format.public static java.lang.String formatRfc822Date(java.util.Date date)
date
- Datepublic static boolean isMultipartUploadETag(java.lang.String eTag)
eTag
- The ETag to test.public static byte[] toByteArray(java.lang.String s)
s
- The string to convert to a byte array.public static java.lang.String removeQuotes(java.lang.String s)
s
- The string to check for surrounding quotes.public static java.net.URL convertRequestToUrl(com.amazonaws.Request<?> request)
request
- The request to convert into a URL.com.amazonaws.AmazonClientException
- If the request cannot be converted to a
well formed URL.public static java.net.URL convertRequestToUrl(com.amazonaws.Request<?> request, boolean removeLeadingSlashInResourcePath)
request
- The request to convert into a URL.removeLeadingSlashInResourcePath
- Whether the leading slash in
resource-path should be removed before appending to the
endpoint.com.amazonaws.AmazonClientException
- If the request cannot be converted to a
well formed URL.public static java.lang.String join(java.util.List<java.lang.String> strings)
strings
- The list of strings to join into a single, comma delimited
string list.public static void downloadObjectToFile(S3Object s3Object, java.io.File destinationFile, boolean performIntegrityCheck, boolean appendData)
AmazonS3Client.getObject(com.amazonaws.services.s3.model.GetObjectRequest)
, to the specified file.s3Object
- The S3Object containing a reference to an InputStream
containing the object's data.destinationFile
- The file to store the object's data in.performIntegrityCheck
- Boolean valuable to indicate whether to
perform integrity checkappendData
- appends the data to end of the file.public static S3Object retryableDownloadS3ObjectToFile(java.io.File file, ServiceUtils.RetryableS3DownloadTask retryableS3DownloadTask, boolean appendData)
file
- The file to store the object's data in.retryableS3DownloadTask
- the task for download.appendData
- boolean to indicate if append data is enabled.public static boolean skipMd5CheckPerResponse(ObjectMetadata metadata)
The reason is that when SSE-KMS or SSE-C is involved, the MD5 returned from the server side is the MD5 of the ciphertext, which will by definition mismatch the MD5 on the client side which is computed based on the plaintext.
metadata
- the ObjectMetadata of an S3 response.public static boolean skipMd5CheckPerResponse(ObjectMetadata metadata, S3ClientOptions clientOptions)
The reason is that when SSE-KMS or SSE-C is involved, the MD5 returned from the server side is the MD5 of the ciphertext, which will by definition mismatch the MD5 on the client side which is computed based on the plaintext.
metadata
- the ObjectMetadata of an S3 response.clientOptions
- the S3 client options to see if check can be skippedpublic static boolean skipMd5CheckPerRequest(com.amazonaws.AmazonWebServiceRequest request)
request
- the AmazonWebServiceRequest.public static boolean skipMd5CheckPerRequest(com.amazonaws.AmazonWebServiceRequest request, S3ClientOptions clientOptions)
request
- the AmazonWebServiceRequest.clientOptions
- the S3 client options to see if check can be skipped