public final class Utility extends Object
| Modifier and Type | Field and Description |
|---|---|
static TimeZone |
GMT_ZONE
Stores a reference to the GMT time zone.
|
static Locale |
LOCALE_US
Stores a reference to the US locale.
|
static TimeZone |
UTC_ZONE
Stores a reference to the UTC time zone.
|
| Modifier and Type | Method and Description |
|---|---|
static StreamMd5AndLength |
analyzeStream(InputStream sourceStream,
long writeLength,
long abandonLength,
boolean rewindSourceStream,
boolean calculateMD5)
Determines the size of an input stream, and optionally calculates the MD5 hash for the stream.
|
static void |
assertContinuationType(ResultContinuation continuationToken,
ResultContinuationType continuationType)
Asserts a continuation token is of the specified type.
|
static void |
assertGreaterThanOrEqual(String param,
long value,
long min)
Asserts that the specified value is greater than or equal to the min value.
|
static void |
assertInBounds(String param,
long value,
long min,
long max)
Asserts that the specified integer is in the valid range.
|
static void |
assertNotNull(String param,
Object value)
Asserts that a value is not
null. |
static void |
assertNotNullOrEmpty(String param,
String value)
Asserts that the specified string is not
null or empty. |
static byte[] |
binaryAppend(byte[] arr1,
byte[] arr2)
Appends 2 byte arrays.
|
static void |
checkNullaryCtor(Class<?> clazzType) |
static XMLStreamWriter |
createXMLStreamWriter(StringWriter outWriter)
Returns a
XMLStreamWriter with the specified StringWriter. |
static boolean |
determinePathStyleFromUri(URI baseURI)
Returns a value that indicates whether a specified URI is a path-style URI.
|
static long |
encryptStreamIfUnderThreshold(InputStream sourceStream,
ByteArrayOutputStream targetStream,
Cipher cipher,
long writeLength,
long abandonLength)
Encrypts an input stream up to a given length.
|
static String |
formatETag(String etag)
Reads character data for the Etag element from an XML stream reader.
|
static StorageException |
generateNewUnexpectedStorageException(Exception cause)
Returns an unexpected storage exception.
|
static String |
getGMTTime()
Returns the current GMT date/time String using the RFC1123 pattern.
|
static String |
getGMTTime(Date date)
Returns the GTM date/time String for the specified value using the RFC1123 pattern.
|
static String |
getJavaISO8601Time(Date date)
Returns the UTC date/time String for the specified value using Java's version of the ISO8601 pattern,
which is limited to millisecond precision.
|
static com.fasterxml.jackson.core.JsonGenerator |
getJsonGenerator(OutputStream outStream)
Returns a
JsonGenerator with the specified OutputStream. |
static com.fasterxml.jackson.core.JsonGenerator |
getJsonGenerator(StringWriter strWriter)
Returns a
JsonGenerator with the specified StringWriter. |
static com.fasterxml.jackson.core.JsonParser |
getJsonParser(InputStream inStream)
Returns a
JsonParser with the specified InputStream. |
static com.fasterxml.jackson.core.JsonParser |
getJsonParser(String jsonString)
Returns a
JsonParser with the specified String. |
static RequestLocationMode |
getListingLocationMode(ResultContinuation token)
Determines which location can the listing command target by looking at the
continuation token.
|
static int |
getRemainingTimeout(Long operationExpiryTimeInMs,
Integer timeoutIntervalInMs)
Returns a value representing the remaining time before the operation expires.
|
static SAXParser |
getSAXParser()
Returns a namespace aware
SAXParser. |
static String |
getStandardHeaderValue(HttpURLConnection conn,
String headerName)
Returns the standard header value from the specified connection request, or an empty string if no header value
has been specified for the request.
|
static String |
getUTCTimeOrEmpty(Date value)
Returns the UTC date/time for the specified value using the ISO8601 pattern.
|
static IOException |
initIOException(Exception ex)
Creates an instance of the
IOException class using the specified exception. |
static boolean |
isNullOrEmpty(String value)
Returns a value that indicates whether the specified string is
null or empty. |
static boolean |
isNullOrEmptyOrWhitespace(String value)
Returns a value that indicates whether the specified string is
null, empty, or whitespace. |
static void |
logHttpError(StorageException ex,
OperationContext opContext)
Serializes the parsed StorageException.
|
static void |
logHttpRequest(HttpURLConnection conn,
OperationContext opContext)
Logs the HttpURLConnection request.
|
static void |
logHttpResponse(HttpURLConnection conn,
OperationContext opContext)
Logs the HttpURLConnection response.
|
static HashMap<String,String> |
parseAccountString(String parseString)
Parses a connection string and returns its values as a hash map of key/value pairs.
|
static Date |
parseDate(String dateString)
Given a String representing a date in a form of the ISO8601 pattern, generates a Date representing it
with up to millisecond precision.
|
static Date |
parseDate(String dateString,
boolean dateBackwardCompatibility)
Given a String representing a date in a form of the ISO8601 pattern, generates a Date representing it
with up to millisecond precision.
|
static Date |
parseRFC1123DateFromStringInGMT(String value)
Returns a GMT date for the specified string in the RFC1123 pattern.
|
static String |
safeDecode(String stringToDecode)
Performs safe decoding of the specified string, taking care to preserve each
+ character, rather
than replacing it with a space character. |
static String |
safeEncode(String stringToEncode)
Performs safe encoding of the specified string, taking care to insert
%20 for each space character,
instead of inserting the + character. |
static String |
safeRelativize(URI baseURI,
URI toUri)
Determines the relative difference between the two specified URIs.
|
protected static String |
trimEnd(String value,
char trimChar)
Trims the specified character from the end of a string.
|
static String |
trimStart(String value)
Trims whitespace from the beginning of a string.
|
static boolean |
validateMaxExecutionTimeout(Long operationExpiryTimeInMs)
Returns a value representing whether the maximum execution time would be surpassed.
|
static boolean |
validateMaxExecutionTimeout(Long operationExpiryTimeInMs,
long additionalInterval)
Returns a value representing whether the maximum execution time would be surpassed.
|
static StreamMd5AndLength |
writeToOutputStream(InputStream sourceStream,
OutputStream outStream,
long writeLength,
boolean rewindSourceStream,
boolean calculateMD5,
OperationContext opContext,
RequestOptions options)
Reads data from an input stream and writes it to an output stream, calculates the length of the data written, and
optionally calculates the MD5 hash for the data.
|
static StreamMd5AndLength |
writeToOutputStream(InputStream sourceStream,
OutputStream outStream,
long writeLength,
boolean rewindSourceStream,
boolean calculateMD5,
OperationContext opContext,
RequestOptions options,
Boolean shouldFlush)
Reads data from an input stream and writes it to an output stream, calculates the length of the data written, and
optionally calculates the MD5 hash for the data.
|
static StreamMd5AndLength |
writeToOutputStream(InputStream sourceStream,
OutputStream outStream,
long writeLength,
boolean rewindSourceStream,
boolean calculateMD5,
OperationContext opContext,
RequestOptions options,
Boolean shouldFlush,
StorageRequest<?,?,Integer> request,
StreamMd5AndLength descriptor)
Reads data from an input stream and writes it to an output stream, calculates the length of the data written, and
optionally calculates the MD5 hash for the data.
|
public static final TimeZone GMT_ZONE
public static final TimeZone UTC_ZONE
public static final Locale LOCALE_US
public static StreamMd5AndLength analyzeStream(InputStream sourceStream, long writeLength, long abandonLength, boolean rewindSourceStream, boolean calculateMD5) throws IOException, StorageException
sourceStream - A InputStream object that represents the stream to measure.writeLength - The number of bytes to read from the stream.abandonLength - The number of bytes to read before the analysis is abandoned. Set this value to -1 to
force the entire stream to be read. This parameter is provided to support upload thresholds.rewindSourceStream - true if the stream should be rewound after it is read; otherwise, false.calculateMD5 - true if an MD5 hash will be calculated; otherwise, false.StreamMd5AndLength object that contains the stream length, and optionally the MD5 hash.IOException - If an I/O error occurs.StorageException - If a storage service error occurred.public static long encryptStreamIfUnderThreshold(InputStream sourceStream, ByteArrayOutputStream targetStream, Cipher cipher, long writeLength, long abandonLength) throws IOException
sourceStream - A InputStream object that represents the stream to measure.targetStream - A ByteArrayOutputStream object that represents the stream to write the encrypted data.cipher - The Cipher to use to encrypt the data.writeLength - The number of bytes to read and encrypt from the sourceStream.abandonLength - The number of bytes to read before the analysis is abandoned. Set this value to -1 to
force the entire stream to be read. This parameter is provided to support upload thresholds.IOException - If an I/O error occurs.public static void assertContinuationType(ResultContinuation continuationToken, ResultContinuationType continuationType)
continuationToken - A ResultContinuation object that represents the continuation token whose type is being
examined.continuationType - A ResultContinuationType value that represents the continuation token type being asserted with
the specified continuation token.public static void assertNotNull(String param, Object value)
null.param - A String that represents the name of the parameter, which becomes the exception message
text if the value parameter is null.value - An Object object that represents the value of the specified parameter. This is the value
being asserted as not null.public static void assertNotNullOrEmpty(String param, String value)
null or empty.param - A String that represents the name of the parameter, which becomes the exception message
text if the value parameter is null or an empty string.value - A String that represents the value of the specified parameter. This is the value being
asserted as not null and not an empty string.public static void assertInBounds(String param, long value, long min, long max)
param - A String that represents the name of the parameter, which becomes the exception message
text if the value parameter is out of bounds.value - The value of the specified parameter.min - The minimum value for the specified parameter.max - The maximum value for the specified parameter.public static void assertGreaterThanOrEqual(String param, long value, long min)
param - A String that represents the name of the parameter, which becomes the exception message
text if the value parameter is out of bounds.value - The value of the specified parameter.min - The minimum value for the specified parameter.public static byte[] binaryAppend(byte[] arr1,
byte[] arr2)
arr1 - First array.arr2 - Second array.public static boolean validateMaxExecutionTimeout(Long operationExpiryTimeInMs)
operationExpiryTimeInMs - the time the request expirestrue if the maximum execution time would be surpassed; otherwise, false.public static boolean validateMaxExecutionTimeout(Long operationExpiryTimeInMs, long additionalInterval)
operationExpiryTimeInMs - the time the request expiresadditionalInterval - any additional time required from nowtrue if the maximum execution time would be surpassed; otherwise, false.public static int getRemainingTimeout(Long operationExpiryTimeInMs, Integer timeoutIntervalInMs) throws StorageException
operationExpiryTimeInMs - the time the request expirestimeoutIntervalInMs - the server side timeout intervalStorageException - wraps a TimeoutException if there is no more time remainingpublic static boolean determinePathStyleFromUri(URI baseURI)
baseURI - A java.net.URI value that represents the URI being checked.true if the specified URI is path-style; otherwise, false.public static String formatETag(String etag)
xmlr - An XMLStreamReader object that represents the source XML stream reader.String that represents the character data for the Etag element.public static StorageException generateNewUnexpectedStorageException(Exception cause)
cause - An Exception object that represents the initial exception that caused the unexpected
error.StorageException object that represents the unexpected storage exception being thrown.public static String getGMTTime()
String that represents the current GMT date/time using the RFC1123 pattern.public static String getGMTTime(Date date)
date - A Date object that represents the date to convert to GMT date/time in the RFC1123
pattern.String that represents the GMT date/time for the specified value using the RFC1123
pattern.public static String getJavaISO8601Time(Date date)
date - A Date object that represents the date to convert to UTC date/time in Java's version
of the ISO8601 pattern.String that represents the UTC date/time for the specified value using Java's version
of the ISO8601 pattern.public static com.fasterxml.jackson.core.JsonGenerator getJsonGenerator(StringWriter strWriter) throws IOException
JsonGenerator with the specified StringWriter.strWriter - The StringWriter to use to create the JsonGenerator instance.JsonGenerator instanceIOExceptionpublic static com.fasterxml.jackson.core.JsonGenerator getJsonGenerator(OutputStream outStream) throws IOException
JsonGenerator with the specified OutputStream.outStream - The OutputStream to use to create the JsonGenerator instance.JsonGenerator instanceIOExceptionpublic static com.fasterxml.jackson.core.JsonParser getJsonParser(String jsonString) throws com.fasterxml.jackson.core.JsonParseException, IOException
JsonParser with the specified String. This JsonParser
will allow non-numeric numbers.jsonString - The String to use to create the JsonGenerator instance.JsonGenerator instance.IOExceptioncom.fasterxml.jackson.core.JsonParseExceptionpublic static com.fasterxml.jackson.core.JsonParser getJsonParser(InputStream inStream) throws com.fasterxml.jackson.core.JsonParseException, IOException
JsonParser with the specified InputStream. This JsonParser
will allow non-numeric numbers.inStream - The InputStream to use to create the JsonGenerator instance.JsonGenerator instance.IOExceptioncom.fasterxml.jackson.core.JsonParseExceptionpublic static SAXParser getSAXParser() throws ParserConfigurationException, SAXException
SAXParser.SAXParser instance which is namespace awareParserConfigurationExceptionSAXExceptionpublic static String getStandardHeaderValue(HttpURLConnection conn, String headerName)
conn - An HttpURLConnection object that represents the request.headerName - A String that represents the name of the header being requested.String that represents the header value, or null if there is no corresponding
header value for headerName.public static String getUTCTimeOrEmpty(Date value)
value - A Date object that represents the date to convert to UTC date/time in the ISO8601
pattern. If this value is null, this method returns an empty string.String that represents the UTC date/time for the specified value using the ISO8601
pattern, or an empty string if value is null.public static XMLStreamWriter createXMLStreamWriter(StringWriter outWriter) throws XMLStreamException
XMLStreamWriter with the specified StringWriter.outWriter - The StringWriter to use to create the XMLStreamWriter instance.XMLStreamWriter instanceXMLStreamExceptionpublic static IOException initIOException(Exception ex)
IOException class using the specified exception.ex - An Exception object that represents the exception used to create the IO exception.java.io.IOException object that represents the created IO exception.public static boolean isNullOrEmpty(String value)
null or empty.value - A String being examined for null or empty.true if the specified value is null or empty; otherwise, falsepublic static boolean isNullOrEmptyOrWhitespace(String value)
null, empty, or whitespace.value - A String being examined for null, empty, or whitespace.true if the specified value is null, empty, or whitespace; otherwise,
falsepublic static HashMap<String,String> parseAccountString(String parseString)
parseString - A String that represents the connection string to parse.java.util.HashMap object that represents the hash map of the key / value pairs parsed from
the connection string.public static Date parseRFC1123DateFromStringInGMT(String value) throws ParseException
value - A String that represents the string to parse.Date object that represents the GMT date in the RFC1123 pattern.ParseException - If the specified string is invalid.public static String safeDecode(String stringToDecode) throws StorageException
+ character, rather
than replacing it with a space character.stringToDecode - A String that represents the string to decode.String that represents the decoded string.StorageException - If a storage service error occurred.public static String safeEncode(String stringToEncode) throws StorageException
%20 for each space character,
instead of inserting the + character.stringToEncode - A String that represents the string to encode.String that represents the encoded string.StorageException - If a storage service error occurred.public static String safeRelativize(URI baseURI, URI toUri) throws URISyntaxException
baseURI - A java.net.URI object that represents the base URI for which toUri will be
made relative.toUri - A java.net.URI object that represents the URI to make relative to baseURI.String that either represents the relative URI of toUri to
baseURI, or the URI of toUri itself, depending on whether the hostname and
scheme are identical for toUri and baseURI. If the hostname and scheme of
baseURI and toUri are identical, this method returns an unencoded relative URI
such that if appended to baseURI, it will yield toUri. If the hostname or
scheme of baseURI and toUri are not identical, this method returns an unencoded
full URI specified by toUri.URISyntaxException - If baseURI or toUri is invalid.public static void logHttpError(StorageException ex, OperationContext opContext)
ex - The StorageException to serialize.opContext - The operation context which provides the logger.public static void logHttpRequest(HttpURLConnection conn, OperationContext opContext) throws IOException
conn - The HttpURLConnection to serialize.opContext - The operation context which provides the logger.IOExceptionpublic static void logHttpResponse(HttpURLConnection conn, OperationContext opContext) throws IOException
conn - The HttpURLConnection to serialize.opContext - The operation context which provides the logger.IOExceptionprotected static String trimEnd(String value, char trimChar)
value - A String that represents the string to trim.trimChar - The character to trim from the end of the string.public static String trimStart(String value)
value - A String that represents the string to trim.public static StreamMd5AndLength writeToOutputStream(InputStream sourceStream, OutputStream outStream, long writeLength, boolean rewindSourceStream, boolean calculateMD5, OperationContext opContext, RequestOptions options) throws IOException, StorageException
sourceStream - An InputStream object that represents the input stream to use as the source.outStream - An OutputStream object that represents the output stream to use as the destination.writeLength - The number of bytes to read from the stream.rewindSourceStream - true if the input stream should be rewound before it is read; otherwise,
falsecalculateMD5 - true if an MD5 hash will be calculated; otherwise, false.opContext - An OperationContext object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.options - A RequestOptions object that specifies any additional options for the request. Namely, the
maximum execution time.StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.IOException - If an I/O error occurs.StorageException - If a storage service error occurred.public static StreamMd5AndLength writeToOutputStream(InputStream sourceStream, OutputStream outStream, long writeLength, boolean rewindSourceStream, boolean calculateMD5, OperationContext opContext, RequestOptions options, Boolean shouldFlush) throws IOException, StorageException
sourceStream - An InputStream object that represents the input stream to use as the source.outStream - An OutputStream object that represents the output stream to use as the destination.writeLength - The number of bytes to read from the stream.rewindSourceStream - true if the input stream should be rewound before it is read; otherwise,
falsecalculateMD5 - true if an MD5 hash will be calculated; otherwise, false.opContext - An OperationContext object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.options - A RequestOptions object that specifies any additional options for the request. Namely, the
maximum execution time.StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.IOException - If an I/O error occurs.StorageException - If a storage service error occurred.public static StreamMd5AndLength writeToOutputStream(InputStream sourceStream, OutputStream outStream, long writeLength, boolean rewindSourceStream, boolean calculateMD5, OperationContext opContext, RequestOptions options, Boolean shouldFlush, StorageRequest<?,?,Integer> request, StreamMd5AndLength descriptor) throws IOException, StorageException
sourceStream - An InputStream object that represents the input stream to use as the source.outStream - An OutputStream object that represents the output stream to use as the destination.writeLength - The number of bytes to read from the stream.rewindSourceStream - true if the input stream should be rewound before it is read; otherwise,
falsecalculateMD5 - true if an MD5 hash will be calculated; otherwise, false.opContext - An OperationContext object that represents the context for the current operation. This object
is used to track requests to the storage service, and to provide additional runtime information about
the operation.options - A RequestOptions object that specifies any additional options for the request. Namely, the
maximum execution time.request - Used by download resume to set currentRequestByteCount on the request. Otherwise, null is always used.descriptor - A object to append to in the case of recovery action or null if this is not called
from a recovery. This value needs to be passed for recovery in case part of the body has already been read,
the recovery will attempt to download the remaining bytes but will do MD5 validation on the originally
requested range size.StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.IOException - If an I/O error occurs.StorageException - If a storage service error occurred.public static void checkNullaryCtor(Class<?> clazzType)
public static Date parseDate(String dateString)
dateString - the String to be interpreted as a DateDate objectpublic static Date parseDate(String dateString, boolean dateBackwardCompatibility)
parseDate(String) instead unless
dateBackwardCompatibility is needed.
See here for more details.
dateString - the String to be interpreted as a DatedateBackwardCompatibility - true to correct Date values that may have been written
using versions of this library prior to 2.0.0; otherwise, falseDate objectpublic static RequestLocationMode getListingLocationMode(ResultContinuation token)
token - Continuation tokenCopyright © 2019. All rights reserved.