public class ServiceUtils extends Object
Constructor and Description |
---|
ServiceUtils() |
Modifier and Type | Method and Description |
---|---|
static S3Object |
buildObjectFromUrl(String host,
String urlPath,
String s3Endpoint)
Builds an object based on the bucket name and object key information
available in the components of a URL.
|
static Map<String,Object> |
cleanRestMetadataMap(Map<String,Object> metadata,
String headerPrefix,
String metadataPrefix)
From a map of metadata returned from a REST GET or HEAD request, returns a map
of metadata with the HTTP-connection-specific metadata items removed.
|
static byte[] |
computeMD5Hash(byte[] data)
Computes the MD5 hash of the given data and returns it as a hex string.
|
static byte[] |
computeMD5Hash(InputStream is)
Computes the MD5 hash of the data in the given input stream and returns it as a hex string.
|
static long |
countBytesInObjects(S3Object[] objects)
Counts the total number of bytes in a set of S3Objects by summing the
content length of each.
|
static String |
findBucketNameInHostname(String host,
String s3Endpoint)
Identifies the name of a bucket from a given host name, if available.
|
static String |
formatIso8601Date(Date date) |
static String |
formatRfc822Date(Date date) |
static byte[] |
fromBase64(String b64Data)
Converts a Base64-encoded string to the original byte data.
|
static byte[] |
fromHex(String hexData)
Converts a Hex-encoded data string to the original byte data.
|
static String |
generateS3HostnameForBucket(String bucketName,
boolean isDnsBucketNamingDisabled,
String s3Endpoint) |
static String |
getUserAgentDescription(String applicationDescription)
Returns a user agent string describing the jets3t library, and optionally the application
using it, to server-side services.
|
static boolean |
isBucketNameValidDNSName(String bucketName)
Returns true if the given bucket name can be used as a component of a valid
DNS name.
|
static boolean |
isEtagAlsoAnMD5Hash(String etag)
Guess whether the given ETag value is also an MD5 hash of an underlying object
in a storage service, as opposed to being some other kind of opaque hash.
|
static String |
join(int[] ints,
String delimiter)
Joins a list of ints into a delimiter-separated string.
|
static String |
join(List<?> items,
String delimiter)
Joins a list of items into a delimiter-separated string.
|
static String |
join(Object[] items,
String delimiter)
Joins a list of items into a delimiter-separated string.
|
static XMLReader |
loadXMLReader()
Find a SAX XMLReader by hook or by crook, with work-arounds for
non-standard platforms.
|
static Date |
parseIso8601Date(String dateString) |
static Date |
parseRfc822Date(String dateString) |
static String |
readInputStreamLineToString(InputStream is,
String encoding)
Reads from an input stream until a newline character or the end of the stream is reached.
|
static byte[] |
readInputStreamToBytes(InputStream is)
Reads binary data from an input stream and returns it as a byte array.
|
static String |
readInputStreamToString(InputStream is,
String encoding)
Reads text data from an input stream and returns it as a String.
|
static String |
signWithHmacSha1(String awsSecretKey,
String canonicalString)
Calculate the HMAC/SHA1 on a string.
|
static String |
toBase64(byte[] data)
Converts byte data to a Base64-encoded string.
|
static String |
toHex(byte[] data)
Converts byte data to a Hex-encoded string.
|
public static Date parseIso8601Date(String dateString) throws ParseException
ParseException
public static Date parseRfc822Date(String dateString) throws ParseException
ParseException
public static String signWithHmacSha1(String awsSecretKey, String canonicalString) throws ServiceException
awsSecretKey
- AWS secret key.canonicalString
- canonical string representing the request to sign.ServiceException
public static String readInputStreamToString(InputStream is, String encoding) throws IOException
is
- input stream from which text data is read.encoding
- the character encoding of the textual data in the input stream. If this
parameter is null, the default system encoding will be used.IOException
public static String readInputStreamLineToString(InputStream is, String encoding) throws IOException
is
- IOException
public static byte[] readInputStreamToBytes(InputStream is) throws IOException
is
- input stream from which data is read.IOException
public static long countBytesInObjects(S3Object[] objects)
objects
- public static Map<String,Object> cleanRestMetadataMap(Map<String,Object> metadata, String headerPrefix, String metadataPrefix)
metadata
- public static String toHex(byte[] data)
data
- data to hex encode.public static byte[] fromHex(String hexData)
hexData
- hex-encoded data to decode.public static String toBase64(byte[] data)
data
- data to Base64 encode.public static String join(List<?> items, String delimiter)
items
- the items to include in a delimited stringdelimiter
- the delimiter character or string to insert between each item in the listpublic static String join(Object[] items, String delimiter)
items
- the items to include in a delimited stringdelimiter
- the delimiter character or string to insert between each item in the listpublic static String join(int[] ints, String delimiter)
ints
- the ints to include in a delimited stringdelimiter
- the delimiter character or string to insert between each item in the listpublic static byte[] fromBase64(String b64Data)
b64Data
- a Base64-encoded string to decode.public static byte[] computeMD5Hash(InputStream is) throws NoSuchAlgorithmException, IOException
is
- NoSuchAlgorithmException
IOException
public static byte[] computeMD5Hash(byte[] data) throws NoSuchAlgorithmException, IOException
data
- NoSuchAlgorithmException
IOException
public static boolean isEtagAlsoAnMD5Hash(String etag)
This test was made necessary by Amazon S3's multipart upload feature, where the ETag value returned after a re-assembled multipart upload is completed is no longer the same as an MD5 hash of the assembled data.
An ETag is considered also an MD5 when:
These rules are drawn from the post by Carl@AWS on Nov 11, 2010 10:40 AM here: https://forums.aws.amazon.com/thread.jspa?messageID=222158&tstart=0
public static String findBucketNameInHostname(String host, String s3Endpoint)
host
- the host name component of a URL that may include the bucket name,
if an alternative host name is in use.public static S3Object buildObjectFromUrl(String host, String urlPath, String s3Endpoint) throws UnsupportedEncodingException
host
- the host name component of a URL that may include the bucket name,
if an alternative host name is in use.urlPath
- the path of a URL that references an S3 object, and which may or may
not include the bucket name.UnsupportedEncodingException
public static boolean isBucketNameValidDNSName(String bucketName)
bucketName
- the name of the bucket to test for DNS compatibility.public static String generateS3HostnameForBucket(String bucketName, boolean isDnsBucketNamingDisabled, String s3Endpoint)
public static String getUserAgentDescription(String applicationDescription)
applicationDescription
- a description of the application using the jets3t toolkit, included at the end of the
user agent string. This value may be null.Constants.JETS3T_VERSION
(os.name/os.version; os.arch; user.region;
user.region; user.language) applicationDescriptionpublic static XMLReader loadXMLReader() throws ServiceException
ServiceException