public class ServiceUtils extends 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 |
protected static DateUtils |
dateUtils
Deprecated.
|
static boolean |
OVERWRITE_MODE |
Constructor and Description |
---|
ServiceUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
appendFile(File sourceFile,
File destinationFile)
Append the data in sourceFile to destinationFile.
|
static URL |
convertRequestToUrl(Request<?> request)
Deprecated.
No longer used. May be removed in a future major version.
|
static URL |
convertRequestToUrl(Request<?> request,
boolean removeLeadingSlashInResourcePath)
Deprecated.
No longer used. May be removed in a future major version.
|
static URL |
convertRequestToUrl(Request<?> request,
boolean removeLeadingSlashInResourcePath,
boolean urlEncode)
Converts the specified request object into a URL, containing all the
specified parameters, the specified request endpoint, etc.
|
static void |
createParentDirectoryIfNecessary(File file)
Creates the parent directory for a file if it doesn't already exist.
|
static void |
downloadObjectToFile(S3Object s3Object,
File destinationFile,
boolean performIntegrityCheck,
boolean appendData)
Downloads an S3Object, as returned from
AmazonS3Client.getObject(com.ibm.cloud.objectstorage.services.s3.model.GetObjectRequest) ,
to the specified file. |
static void |
downloadToFile(S3Object s3Object,
File dstfile,
boolean performIntegrityCheck,
boolean appendData,
long expectedFileLength)
Same as
ServiceUtils.downloadObjectToFile(S3Object, File, boolean, boolean)
but has an additional expected file length parameter for integrity
checking purposes. |
static String |
formatIso8601Date(Date date) |
static String |
formatRfc822Date(Date date) |
static long |
getLastByteInPart(AmazonS3 s3,
GetObjectRequest getObjectRequest,
Integer partNumber)
Returns the last byte number in a part of an object.
|
static Integer |
getPartCount(GetObjectRequest getObjectRequest,
AmazonS3 s3)
Returns the part count of the object represented by the getObjectRequest.
|
static long |
getPartSize(GetObjectRequest getObjectRequest,
AmazonS3 s3,
int partNumber)
Returns the part size of the part
|
static boolean |
isS3AccelerateEndpoint(String endpoint) |
static boolean |
isS3USEastEndpiont(String endpoint) |
static boolean |
isS3USStandardEndpoint(String endpoint) |
static String |
join(List<String> strings)
Returns a new string created by joining each of the strings in the
specified list together, with a comma between them.
|
static Date |
parseIso8601Date(String dateString) |
static Date |
parseRfc822Date(String dateString) |
static String |
removeQuotes(String s)
Removes any surrounding quotes from the specified string and returns a
new string.
|
static S3Object |
retryableDownloadS3ObjectToFile(File file,
ServiceUtils.RetryableS3DownloadTask retryableS3DownloadTask,
boolean appendData)
Gets an object stored in S3 and downloads it into the specified file.
|
static byte[] |
toByteArray(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 DateUtils dateUtils
public static byte[] toByteArray(String s)
s
- The string to convert to a byte array.public static String removeQuotes(String s)
s
- The string to check for surrounding quotes.@Deprecated public static URL convertRequestToUrl(Request<?> request)
request
- The request to convert into a URL.SdkClientException
- If the request cannot be converted to a well formed URL.@Deprecated public static URL convertRequestToUrl(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.SdkClientException
- If the request cannot be converted to a well formed URL.public static URL convertRequestToUrl(Request<?> request, boolean removeLeadingSlashInResourcePath, boolean urlEncode)
request
- The request to convert into a URL.removeLeadingSlashInResourcePath
- Whether the leading slash in resource-path should be removed
before appending to the endpoint.urlEncode
- True if request resource path should be URL encodedSdkClientException
- If the request cannot be converted to a well formed URL.public static String join(List<String> strings)
strings
- The list of strings to join into a single, comma delimited
string list.public static void downloadObjectToFile(S3Object s3Object, File destinationFile, boolean performIntegrityCheck, boolean appendData)
AmazonS3Client.getObject(com.ibm.cloud.objectstorage.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 void downloadToFile(S3Object s3Object, File dstfile, boolean performIntegrityCheck, boolean appendData, long expectedFileLength)
ServiceUtils.downloadObjectToFile(S3Object, File, boolean, boolean)
but has an additional expected file length parameter for integrity
checking purposes.expectedFileLength
- applicable only when appendData is true; the expected length
of the file to append to.public static void createParentDirectoryIfNecessary(File file)
file
- SdkClientException
- when creation of parent directory failed.public static S3Object retryableDownloadS3ObjectToFile(File file, ServiceUtils.RetryableS3DownloadTask retryableS3DownloadTask, boolean appendData)
file
- The file to store the object's data in.retryableS3DownloadTask
- The implementation of SafeS3DownloadTask interface which allows user to
get access to all the visible variables at the calling site of this method.public static void appendFile(File sourceFile, File destinationFile)
sourceFile
- The file that is to be appended.destinationFile
- The file to append to.public static boolean isS3USStandardEndpoint(String endpoint)
public static boolean isS3USEastEndpiont(String endpoint)
public static boolean isS3AccelerateEndpoint(String endpoint)
public static Integer getPartCount(GetObjectRequest getObjectRequest, AmazonS3 s3)
getObjectRequest
- The request to check.s3
- The Amazon s3 client.public static long getPartSize(GetObjectRequest getObjectRequest, AmazonS3 s3, int partNumber)
getObjectRequest
- the request to checks3
- the s3 clientpartNumber
- the part numberpublic static long getLastByteInPart(AmazonS3 s3, GetObjectRequest getObjectRequest, Integer partNumber)
s3
- The Amazon s3 client.getObjectRequest
- The request to check.partNumber
- The part in which we need the last byte number.Copyright © 2024. All rights reserved.