Utility Class

  • java.lang.Object
    • com.microsoft.azure.storage.core.Utility

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
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.

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.

StorageException 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.

RequestLocationMode 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.

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.

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.

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<?, ?, 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:

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.

Returns:

A StreamMd5AndLength object that contains the stream length, and optionally the MD5 hash.

Throws:

IOException - If an I/O error occurs.
StorageException - If a storage service error occurred.

assertContinuationType

public static void assertContinuationType(final ResultContinuation continuationToken, final ResultContinuationType continuationType)

Asserts a continuation token is of the specified type.

Parameters:

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.

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:

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.

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:

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.

assertNotNull

public static void assertNotNull(final String param, final Object value)

Asserts that a value is not .

Parameters:

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.

assertNotNullOrEmpty

public static void assertNotNullOrEmpty(final String param, final String value)

Asserts that the specified string is not or empty.

Parameters:

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.

binaryAppend

public static byte [] binaryAppend(byte[] arr1, byte[] arr2)

Appends 2 byte arrays.

Parameters:

arr1 - First array.
arr2 - Second array.

Returns:

The result byte array.

checkNullaryCtor

public static void checkNullaryCtor(Class clazzType)

Parameters:

clazzType

createXMLStreamWriter

public static XMLStreamWriter createXMLStreamWriter(StringWriter outWriter)

Returns a with the specified .

Parameters:

outWriter - The StringWriter to use to create the XMLStreamWriter instance.

Returns:

A XMLStreamWriter instance

Throws:

XMLStreamException

determinePathStyleFromUri

public static boolean determinePathStyleFromUri(final URI baseURI)

Returns a value that indicates whether a specified URI is a path-style URI.

Parameters:

baseURI - A 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:

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.

Returns:

The size of the encrypted stream, or -1 if the encrypted stream would be over the abandonLength.

Throws:

IOException - If an I/O error occurs.

findAllPatternOccurences

public static List findAllPatternOccurences(byte[] array, byte[] pattern)

Scans a byte array for all occurrences of a pattern, with no overlap of occurrence spans.

Parameters:

array - The array to search.
pattern - The pattern to search for.

Returns:

A list of starting indices of all occurrences of the pattern, in ascending order.

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:

array - The array to search.
pattern - The pattern to search for.
scanOffset - Where to begin the search.

Returns:

The starting index of the found pattern. -1 if not found.

formatETag

public static String formatETag(final String etag)

Reads character data for the Etag element from an XML stream reader.

Parameters:

etag

Returns:

A String that represents the character data for the Etag element.

generateNewUnexpectedStorageException

public static StorageException generateNewUnexpectedStorageException(final Exception cause)

Returns an unexpected storage exception.

Parameters:

cause - An Exception object that represents the initial exception that caused the unexpected error.

Returns:

A StorageException object that represents the unexpected storage exception being thrown.

getGMTTime

public static String getGMTTime()

Returns the current GMT date/time String using the RFC1123 pattern.

Returns:

A 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 - A Date object that represents the date to convert to GMT date/time in the RFC1123 pattern.

Returns:

A 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 - A Date object that represents the date to convert to UTC date/time in Java's version of the ISO8601 pattern.

Returns:

A 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:

outStream - The OutputStream to use to create the JsonGenerator instance.

Returns:

A JsonGenerator instance

Throws:

IOException

getJsonGenerator

public static JsonGenerator getJsonGenerator(StringWriter strWriter)

Returns a with the specified .

Parameters:

strWriter - The StringWriter to use to create the JsonGenerator instance.

Returns:

A JsonGenerator instance

Throws:

IOException

getJsonParser

public static JsonParser getJsonParser(final InputStream inStream)

Returns a with the specified . This JsonParser will allow non-numeric numbers.

Parameters:

inStream - The InputStream to use to create the JsonGenerator instance.

Returns:

A JsonGenerator instance.

Throws:

IOException

getJsonParser

public static JsonParser getJsonParser(final String jsonString)

Returns a with the specified . This JsonParser will allow non-numeric numbers.

Parameters:

jsonString - The String to use to create the JsonGenerator instance.

Returns:

A JsonGenerator instance.

Throws:

IOException

getListingLocationMode

public static RequestLocationMode getListingLocationMode(ResultContinuation token)

Determines which location can the listing command target by looking at the continuation token.

Parameters:

token - Continuation token

Returns:

Location mode

getRemainingTimeout

public static int getRemainingTimeout(Long operationExpiryTimeInMs, Integer timeoutIntervalInMs)

Returns a value representing the remaining time before the operation expires.

Parameters:

operationExpiryTimeInMs - the time the request expires
timeoutIntervalInMs - the server side timeout interval

Returns:

the remaining time before the operation expires

Throws:

StorageException - wraps a TimeoutException if there is no more time remaining

getSAXParser

public static SAXParser getSAXParser()

Returns a namespace aware .

Returns:

A SAXParser instance which is namespace aware

Throws:

ParserConfigurationException
SAXException

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:

conn - An HttpURLConnection object that represents the request.
headerName - A String that represents the name of the header being requested.

Returns:

A 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:

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.

Returns:

A 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:

ex - An Exception object that represents the exception used to create the IO exception.

Returns:

A 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:

value - A 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:

value - A 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:

ex - The StorageException to serialize.
opContext - The operation context which provides the logger.

logHttpRequest

public static void logHttpRequest(HttpURLConnection conn, OperationContext opContext)

Logs the HttpURLConnection request. If an exception is encountered, logs nothing.

Parameters:

conn - The HttpURLConnection to serialize.
opContext - The operation context which provides the logger.

logHttpResponse

public static void logHttpResponse(HttpURLConnection conn, OperationContext opContext)

Logs the HttpURLConnection response. If an exception is encountered, logs nothing.

Parameters:

conn - The HttpURLConnection to serialize.
opContext - The operation context which provides the logger.

parseAccountString

public static HashMap parseAccountString(final String parseString)

Parses a connection string and returns its values as a hash map of key/value pairs.

Parameters:

parseString - A String that represents the connection string to parse.

Returns:

A 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:

dateString - the String to be interpreted as a Date

Returns:

the corresponding Date object

parseDate

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:

dateString - the String to be interpreted as a Date
dateBackwardCompatibility -

true to correct Date values that may have been written using versions of this library prior to 2.0.0; otherwise, false

Returns:

the corresponding Date object

parseRFC1123DateFromStringInGMT

public static Date parseRFC1123DateFromStringInGMT(final String value)

Returns a GMT date for the specified string in the RFC1123 pattern.

Parameters:

value - A String that represents the string to parse.

Returns:

A Date object that represents the GMT date in the RFC1123 pattern.

Throws:

ParseException - If the specified string is invalid.

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:

stringToDecode - A String that represents the string to decode.

Returns:

A String that represents the decoded string.

Throws:

StorageException - If a storage service error occurred.

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:

stringToEncode - A String that represents the string to encode.

Returns:

A String that represents the encoded string.

Throws:

StorageException - If a storage service error occurred.

safeRelativize

public static String safeRelativize(final URI baseURI, final URI toUri)

Determines the relative difference between the two specified URIs.

Parameters:

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.

Returns:

A 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:

URISyntaxException - If baseURI or toUri is invalid.

splitOnPattern

public static List splitOnPattern(byte[] array, byte[] pattern)

Parameters:

array
pattern

stringJoin

public static String stringJoin(CharSequence delimiter, final String... strings)

Equivalent of String.join() in Java 8.

Parameters:

delimiter - Characters to join strings with.
strings - Strings to join.

Returns:

The joined string.

stringJoin

public static String stringJoin(CharSequence delimiter, Iterable strings)

Equivalent of String.join() in Java 8.

Parameters:

delimiter - Characters to join strings with.
strings - Strings to join.

Returns:

The joined string.

trimEnd

protected static String trimEnd(final String value, final char trimChar)

Trims the specified character from the end of a string.

Parameters:

value - A String that represents the string to trim.
trimChar - The character to trim from the end of the string.

Returns:

The string with the specified character trimmed from the end.

trimStart

public static String trimStart(final String value)

Trims whitespace from the beginning of a string.

Parameters:

value - A String that represents the string to trim.

Returns:

The string with whitespace trimmed from the beginning.

validateMaxExecutionTimeout

public static boolean validateMaxExecutionTimeout(Long operationExpiryTimeInMs)

Returns a value representing whether the maximum execution time would be surpassed.

Parameters:

operationExpiryTimeInMs - the time the request expires

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:

operationExpiryTimeInMs - the time the request expires
additionalInterval - any additional time required from now

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:

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, false

calculateMD5 -

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.

Returns:

A StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.

Throws:

IOException - If an I/O error occurs.
StorageException - If a storage service error occurred.

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:

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, false

calculateMD5 -

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.
shouldFlush

Returns:

A StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.

Throws:

IOException - If an I/O error occurs.
StorageException - If a storage service error occurred.

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:

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, false

calculateMD5 -

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.
shouldFlush
request - Used by download resume to set currentRequestByteCount on the request. Otherwise, null is always used.
descriptor - A StreamMd5AndLength 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.

Returns:

A StreamMd5AndLength object that contains the output stream length, and optionally the MD5 hash.

Throws:

IOException - If an I/O error occurs.
StorageException - If a storage service error occurred.

Applies to