Utility Class
- java.
lang. Object - com.
microsoft. azure. storage. core. Utility
- com.
public class Utility
RESERVED FOR INTERNAL USE. A class which provides utility methods.
Field Summary
Modifier and Type | Field and Description |
---|---|
final TimeZone |
GMT_ZONE
Stores a reference to the GMT time zone. |
final Locale |
LOCALE_US
Stores a reference to the US locale. |
final TimeZone |
UTC_ZONE
Stores a reference to the UTC time zone. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Stream |
analyzeStream(final InputStream sourceStream, long writeLength, long abandonLength, final boolean rewindSourceStream, final boolean calculateMD5)
Determines the size of an input stream, and optionally calculates the MD5 hash for the stream. |
void |
assertContinuationType(final ResultContinuation continuationToken, final ResultContinuationType continuationType)
Asserts a continuation token is of the specified type. |
void |
assertGreaterThanOrEqual(final String param, final long value, final long min)
Asserts that the specified value is greater than or equal to the min value. |
void |
assertInBounds(final String param, final long value, final long min, final long max)
Asserts that the specified integer is in the valid range. |
void |
assertNotNull(final String param, final Object value)
Asserts that a value is not . |
void |
assertNotNullOrEmpty(final String param, final String value)
Asserts that the specified string is not or empty. |
byte [] |
binaryAppend(byte[] arr1, byte[] arr2)
Appends 2 byte arrays. |
void | checkNullaryCtor(Class<?> clazzType) |
XMLStreamWriter |
createXMLStreamWriter(StringWriter outWriter)
Returns a with the specified . |
boolean |
determinePathStyleFromUri(final URI baseURI)
Returns a value that indicates whether a specified URI is a path-style URI. |
long |
encryptStreamIfUnderThreshold(final InputStream sourceStream, final ByteArrayOutputStream targetStream, Cipher cipher, long writeLength, long abandonLength)
Encrypts an input stream up to a given length. Exits early if the encrypted data is longer than the abandon length. |
List<Integer> |
findAllPatternOccurences(byte[] array, byte[] pattern)
Scans a byte array for all occurrences of a pattern, with no overlap of occurrence spans. |
int |
findPattern(byte[] array, byte[] pattern, int scanOffset)
Scans a byte array for the first occurrence of a pattern, starting at the offset provided. |
String |
formatETag(final String etag)
Reads character data for the Etag element from an XML stream reader. |
Storage |
generateNewUnexpectedStorageException(final Exception cause)
Returns an unexpected storage exception. |
String |
getGMTTime()
Returns the current GMT date/time String using the RFC1123 pattern. |
String |
getGMTTime(final Date date)
Returns the GTM date/time String for the specified value using the RFC1123 pattern. |
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. |
JsonGenerator |
getJsonGenerator(OutputStream outStream)
Returns a with the specified . |
JsonGenerator |
getJsonGenerator(StringWriter strWriter)
Returns a with the specified . |
JsonParser |
getJsonParser(final InputStream inStream)
Returns a with the specified . This JsonParser will allow non-numeric numbers. |
JsonParser |
getJsonParser(final String jsonString)
Returns a with the specified . This JsonParser will allow non-numeric numbers. |
Request |
getListingLocationMode(ResultContinuation token)
Determines which location can the listing command target by looking at the continuation token. |
int |
getRemainingTimeout(Long operationExpiryTimeInMs, Integer timeoutIntervalInMs)
Returns a value representing the remaining time before the operation expires. |
SAXParser |
getSAXParser()
Returns a namespace aware . |
String |
getStandardHeaderValue(final HttpURLConnection conn, final 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. |
String |
getUTCTimeOrEmpty(final Date value)
Returns the UTC date/time for the specified value using the ISO8601 pattern. |
IOException |
initIOException(final Exception ex)
Creates an instance of the class using the specified exception. |
boolean |
isNullOrEmpty(final String value)
Returns a value that indicates whether the specified string is or empty. |
boolean |
isNullOrEmptyOrWhitespace(final String value)
Returns a value that indicates whether the specified string is , empty, or whitespace. |
void |
logHttpError(StorageException ex, OperationContext opContext)
Serializes the parsed StorageException. If an exception is encountered, returns empty string. |
void |
logHttpRequest(HttpURLConnection conn, OperationContext opContext)
Logs the HttpURLConnection request. If an exception is encountered, logs nothing. |
void |
logHttpResponse(HttpURLConnection conn, OperationContext opContext)
Logs the HttpURLConnection response. If an exception is encountered, logs nothing. |
HashMap<String, String> |
parseAccountString(final String parseString)
Parses a connection string and returns its values as a hash map of key/value pairs. |
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. |
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. Use parseDate(String dateString) instead unless is needed. See here for more details. |
Date |
parseRFC1123DateFromStringInGMT(final String value)
Returns a GMT date for the specified string in the RFC1123 pattern. |
String |
safeDecode(final String stringToDecode)
Performs safe decoding of the specified string, taking care to preserve each character, rather than replacing it with a space character. |
String |
safeEncode(final String stringToEncode)
Performs safe encoding of the specified string, taking care to insert for each space character, instead of inserting the character. |
String |
safeRelativize(final URI baseURI, final URI toUri)
Determines the relative difference between the two specified URIs. |
List<byte[]> | splitOnPattern(byte[] array, byte[] pattern) |
String |
stringJoin(CharSequence delimiter, final String... strings)
Equivalent of String.join() in Java 8. |
String |
stringJoin(CharSequence delimiter, Iterable<String> strings)
Equivalent of String.join() in Java 8. |
String |
trimEnd(final String value, final char trimChar)
Trims the specified character from the end of a string. |
String |
trimStart(final String value)
Trims whitespace from the beginning of a string. |
boolean |
validateMaxExecutionTimeout(Long operationExpiryTimeInMs)
Returns a value representing whether the maximum execution time would be surpassed. |
boolean |
validateMaxExecutionTimeout(Long operationExpiryTimeInMs, long additionalInterval)
Returns a value representing whether the maximum execution time would be surpassed. |
Stream |
writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final 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. |
Stream |
writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final RequestOptions options, final 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. |
Stream |
writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final RequestOptions options, final 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. |
Field Details
GMT_ZONE
public static final TimeZone GMT_ZONE= TimeZone.getTimeZone("GMT")
Stores a reference to the GMT time zone.
LOCALE_US
public static final Locale LOCALE_US= Locale.US
Stores a reference to the US locale.
UTC_ZONE
public static final TimeZone UTC_ZONE= TimeZone.getTimeZone("UTC")
Stores a reference to the UTC time zone.
Method Details
analyzeStream
public static StreamMd5AndLength analyzeStream(final InputStream sourceStream, long writeLength, long abandonLength, final boolean rewindSourceStream, final boolean calculateMD5)
Determines the size of an input stream, and optionally calculates the MD5 hash for the stream.
Parameters:
InputStream
object that represents the stream to measure.
-1
to force the entire stream to be read. This parameter is provided to support upload thresholds.
true
if the stream should be rewound after it is read; otherwise, false
.
true
if an MD5 hash will be calculated; otherwise, false
.
Returns:
Throws:
assertContinuationType
public static void assertContinuationType(final ResultContinuation continuationToken, final ResultContinuationType continuationType)
Asserts a continuation token is of the specified type.
Parameters:
assertGreaterThanOrEqual
public static void assertGreaterThanOrEqual(final String param, final long value, final long min)
Asserts that the specified value is greater than or equal to the min value.
Parameters:
String
that represents the name of the parameter, which becomes the exception message text if the value
parameter is out of bounds.
assertInBounds
public static void assertInBounds(final String param, final long value, final long min, final long max)
Asserts that the specified integer is in the valid range.
Parameters:
String
that represents the name of the parameter, which becomes the exception message text if the value
parameter is out of bounds.
assertNotNull
public static void assertNotNull(final String param, final Object value)
Asserts that a value is not .
Parameters:
String
that represents the name of the parameter, which becomes the exception message text if the value
parameter is null
.
Object
object that represents the value of the specified parameter. This is the value being asserted as not null
.
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(final String param, final String value)
Asserts that the specified string is not or empty.
Parameters:
String
that represents the name of the parameter, which becomes the exception message text if the value
parameter is null
or an empty string.
String
that represents the value of the specified parameter. This is the value being asserted as not null
and not an empty string.
binaryAppend
public static byte [] binaryAppend(byte[] arr1, byte[] arr2)
Appends 2 byte arrays.
Parameters:
Returns:
checkNullaryCtor
public static void checkNullaryCtor(Class clazzType)
Parameters:
createXMLStreamWriter
public static XMLStreamWriter createXMLStreamWriter(StringWriter outWriter)
Returns a with the specified .
Parameters:
StringWriter
to use to create the XMLStreamWriter
instance.
Returns:
XMLStreamWriter
instanceThrows:
determinePathStyleFromUri
public static boolean determinePathStyleFromUri(final URI baseURI)
Returns a value that indicates whether a specified URI is a path-style URI.
Parameters:
java.net.URI
value that represents the URI being checked.
Returns:
true
if the specified URI is path-style; otherwise, false
.
encryptStreamIfUnderThreshold
public static long encryptStreamIfUnderThreshold(final InputStream sourceStream, final ByteArrayOutputStream targetStream, Cipher cipher, long writeLength, long abandonLength)
Encrypts an input stream up to a given length. Exits early if the encrypted data is longer than the abandon length.
Parameters:
InputStream
object that represents the stream to measure.
ByteArrayOutputStream
object that represents the stream to write the encrypted data.
Cipher
to use to encrypt the data.
-1
to force the entire stream to be read. This parameter is provided to support upload thresholds.
Returns:
Throws:
findAllPatternOccurences
public static List
Scans a byte array for all occurrences of a pattern, with no overlap of occurrence spans.
Parameters:
Returns:
findPattern
public static int findPattern(byte[] array, byte[] pattern, int scanOffset)
Scans a byte array for the first occurrence of a pattern, starting at the offset provided.
Parameters:
Returns:
formatETag
public static String formatETag(final String etag)
Reads character data for the Etag element from an XML stream reader.
Parameters:
Returns:
String
that represents the character data for the Etag element.generateNewUnexpectedStorageException
public static StorageException generateNewUnexpectedStorageException(final Exception cause)
Returns an unexpected storage exception.
Parameters:
Exception
object that represents the initial exception that caused the unexpected error.
Returns:
getGMTTime
public static String getGMTTime()
Returns the current GMT date/time String using the RFC1123 pattern.
Returns:
String
that represents the current GMT date/time using the RFC1123 pattern.getGMTTime
public static String getGMTTime(final Date date)
Returns the GTM date/time String for the specified value using the RFC1123 pattern.
Parameters:
Date
object that represents the date to convert to GMT date/time in the RFC1123 pattern.
Returns:
String
that represents the GMT date/time for the specified value using the RFC1123 pattern.getJavaISO8601Time
public 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.
Parameters:
Date
object that represents the date to convert to UTC date/time in Java's version of the ISO8601 pattern.
Returns:
String
that represents the UTC date/time for the specified value using Java's version of the ISO8601 pattern.getJsonGenerator
public static JsonGenerator getJsonGenerator(OutputStream outStream)
Returns a with the specified .
Parameters:
OutputStream
to use to create the JsonGenerator
instance.
Returns:
JsonGenerator
instanceThrows:
getJsonGenerator
public static JsonGenerator getJsonGenerator(StringWriter strWriter)
Returns a with the specified .
Parameters:
StringWriter
to use to create the JsonGenerator
instance.
Returns:
JsonGenerator
instanceThrows:
getJsonParser
public static JsonParser getJsonParser(final InputStream inStream)
Returns a with the specified . This JsonParser will allow non-numeric numbers.
Parameters:
InputStream
to use to create the JsonGenerator
instance.
Returns:
JsonGenerator
instance.Throws:
getJsonParser
public static JsonParser getJsonParser(final String jsonString)
Returns a with the specified . This JsonParser will allow non-numeric numbers.
Parameters:
String
to use to create the JsonGenerator
instance.
Returns:
JsonGenerator
instance.Throws:
getListingLocationMode
public static RequestLocationMode getListingLocationMode(ResultContinuation token)
Determines which location can the listing command target by looking at the continuation token.
Parameters:
Returns:
getRemainingTimeout
public static int getRemainingTimeout(Long operationExpiryTimeInMs, Integer timeoutIntervalInMs)
Returns a value representing the remaining time before the operation expires.
Parameters:
Returns:
Throws:
getSAXParser
public static SAXParser getSAXParser()
Returns a namespace aware .
Returns:
SAXParser
instance which is namespace awareThrows:
getStandardHeaderValue
public static String getStandardHeaderValue(final HttpURLConnection conn, final 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.
Parameters:
HttpURLConnection
object that represents the request.
String
that represents the name of the header being requested.
Returns:
String
that represents the header value, or null
if there is no corresponding header value for headerName
.getUTCTimeOrEmpty
public static String getUTCTimeOrEmpty(final Date value)
Returns the UTC date/time for the specified value using the ISO8601 pattern.
Parameters:
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.
Returns:
String
that represents the UTC date/time for the specified value using the ISO8601 pattern, or an empty string if value
is null
.initIOException
public static IOException initIOException(final Exception ex)
Creates an instance of the class using the specified exception.
Parameters:
Exception
object that represents the exception used to create the IO exception.
Returns:
java.io.IOException
object that represents the created IO exception.isNullOrEmpty
public static boolean isNullOrEmpty(final String value)
Returns a value that indicates whether the specified string is or empty.
Parameters:
String
being examined for null
or empty.
Returns:
true
if the specified value is null
or empty; otherwise, false
isNullOrEmptyOrWhitespace
public static boolean isNullOrEmptyOrWhitespace(final String value)
Returns a value that indicates whether the specified string is , empty, or whitespace.
Parameters:
String
being examined for null
, empty, or whitespace.
Returns:
true
if the specified value is null
, empty, or whitespace; otherwise, false
logHttpError
public static void logHttpError(StorageException ex, OperationContext opContext)
Serializes the parsed StorageException. If an exception is encountered, returns empty string.
Parameters:
logHttpRequest
public static void logHttpRequest(HttpURLConnection conn, OperationContext opContext)
Logs the HttpURLConnection request. If an exception is encountered, logs nothing.
Parameters:
logHttpResponse
public static void logHttpResponse(HttpURLConnection conn, OperationContext opContext)
Logs the HttpURLConnection response. If an exception is encountered, logs nothing.
Parameters:
parseAccountString
public static HashMap
Parses a connection string and returns its values as a hash map of key/value pairs.
Parameters:
String
that represents the connection string to parse.
Returns:
java.util.HashMap
object that represents the hash map of the key / value pairs parsed from the connection string.parseDate
public 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.
Parameters:
String
to be interpreted as a Date
Returns:
Date
objectparseDate
public 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. Use parseDate(String dateString) instead unless is needed.
See here for more details.
Parameters:
String
to be interpreted as a Date
true
to correct Date values that may have been written using versions of this library prior to 2.0.0; otherwise, false
Returns:
Date
objectparseRFC1123DateFromStringInGMT
public static Date parseRFC1123DateFromStringInGMT(final String value)
Returns a GMT date for the specified string in the RFC1123 pattern.
Parameters:
String
that represents the string to parse.
Returns:
Date
object that represents the GMT date in the RFC1123 pattern.Throws:
safeDecode
public static String safeDecode(final String stringToDecode)
Performs safe decoding of the specified string, taking care to preserve each character, rather than replacing it with a space character.
Parameters:
String
that represents the string to decode.
Returns:
String
that represents the decoded string.Throws:
safeEncode
public static String safeEncode(final String stringToEncode)
Performs safe encoding of the specified string, taking care to insert for each space character, instead of inserting the character.
Parameters:
String
that represents the string to encode.
Returns:
String
that represents the encoded string.Throws:
safeRelativize
public static String safeRelativize(final URI baseURI, final URI toUri)
Determines the relative difference between the two specified URIs.
Parameters:
java.net.URI
object that represents the base URI for which toUri
will be made relative.
java.net.URI
object that represents the URI to make relative to baseURI
.
Returns:
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
.Throws:
baseURI
or toUri
is invalid.
splitOnPattern
public static List
Parameters:
stringJoin
public static String stringJoin(CharSequence delimiter, final String... strings)
Equivalent of String.join() in Java 8.
Parameters:
Returns:
stringJoin
public static String stringJoin(CharSequence delimiter, Iterable
Equivalent of String.join() in Java 8.
Parameters:
Returns:
trimEnd
protected static String trimEnd(final String value, final char trimChar)
Trims the specified character from the end of a string.
Parameters:
String
that represents the string to trim.
Returns:
trimStart
public static String trimStart(final String value)
Trims whitespace from the beginning of a string.
Parameters:
String
that represents the string to trim.
Returns:
validateMaxExecutionTimeout
public static boolean validateMaxExecutionTimeout(Long operationExpiryTimeInMs)
Returns a value representing whether the maximum execution time would be surpassed.
Parameters:
Returns:
true
if the maximum execution time would be surpassed; otherwise, false
.
validateMaxExecutionTimeout
public static boolean validateMaxExecutionTimeout(Long operationExpiryTimeInMs, long additionalInterval)
Returns a value representing whether the maximum execution time would be surpassed.
Parameters:
Returns:
true
if the maximum execution time would be surpassed; otherwise, false
.
writeToOutputStream
public static StreamMd5AndLength writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final 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.
Parameters:
InputStream
object that represents the input stream to use as the source.
OutputStream
object that represents the output stream to use as the destination.
true
if the input stream should be rewound before it is read; otherwise, false
true
if an MD5 hash will be calculated; otherwise, false
.
Returns:
Throws:
writeToOutputStream
public static StreamMd5AndLength writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final RequestOptions options, final 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.
Parameters:
InputStream
object that represents the input stream to use as the source.
OutputStream
object that represents the output stream to use as the destination.
true
if the input stream should be rewound before it is read; otherwise, false
true
if an MD5 hash will be calculated; otherwise, false
.
Returns:
Throws:
writeToOutputStream
public static StreamMd5AndLength writeToOutputStream(final InputStream sourceStream, final OutputStream outStream, long writeLength, final boolean rewindSourceStream, final boolean calculateMD5, OperationContext opContext, final RequestOptions options, final Boolean shouldFlush, StorageRequest 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.
Parameters:
InputStream
object that represents the input stream to use as the source.
OutputStream
object that represents the output stream to use as the destination.
true
if the input stream should be rewound before it is read; otherwise, false
true
if an MD5 hash will be calculated; otherwise, false
.
Returns:
Throws:
Applies to
Azure SDK for Java