null
.
- *
- * @param param
- * A {@code String} that represents the name of the parameter, which becomes the exception message
- * text if the value
parameter is null
.
- * @param value
- * An Object
object that represents the value of the specified parameter. This is the value
- * being asserted as not null
.
- */
- static void assertNotNull(final String param, final Object value) {
- if (value == null) {
- throw new IllegalArgumentException(String.format(Locale.ROOT, SR.ARGUMENT_NULL_OR_EMPTY, param));
- }
- }
-
- /**
- * Returns a value that indicates whether the specified string is null
or empty.
- *
- * @param value
- * A {@code String} being examined for null
or empty.
- *
- * @return true
if the specified value is null
or empty; otherwise, false
- */
- static boolean isNullOrEmpty(final String value) {
- return value == null || value.length() == 0;
- }
-
- /**
- * Performs safe decoding of the specified string, taking care to preserve each + character, rather
- * than replacing it with a space character.
- *
- * @param stringToDecode
- * A {@code String} that represents the string to decode.
- *
- * @return A {@code String} that represents the decoded string.
- */
- static String safeURLDecode(final String stringToDecode) {
- if (stringToDecode.length() == 0) {
- return Constants.EMPTY_STRING;
- }
-
- // '+' are decoded as ' ' so preserve before decoding
- if (stringToDecode.contains("+")) {
- final StringBuilder outBuilder = new StringBuilder();
-
- int startDex = 0;
- for (int m = 0; m < stringToDecode.length(); m++) {
- if (stringToDecode.charAt(m) == '+') {
- if (m > startDex) {
- try {
- outBuilder.append(URLDecoder.decode(stringToDecode.substring(startDex, m),
- Constants.UTF8_CHARSET));
- } catch (UnsupportedEncodingException e) {
- throw new Error(e);
- }
- }
-
- outBuilder.append("+");
- startDex = m + 1;
- }
- }
-
- if (startDex != stringToDecode.length()) {
- try {
- outBuilder.append(URLDecoder.decode(stringToDecode.substring(startDex, stringToDecode.length()),
- Constants.UTF8_CHARSET));
- } catch (UnsupportedEncodingException e) {
- throw new Error(e);
- }
- }
-
- return outBuilder.toString();
- } else {
- try {
- return URLDecoder.decode(stringToDecode, Constants.UTF8_CHARSET);
- } catch (UnsupportedEncodingException e) {
- throw new Error(e);
- }
- }
- }
-
- /**
- * Given a String representing a date in a form of the ISO8601 pattern, generates a Date representing it
- * with up to millisecond precision.
- *
- * @param dateString
- * the {@code String} to be interpreted as a Date
- *
- * @return the corresponding Date
object
- * @throws IllegalArgumentException If {@code dateString} doesn't match an ISO8601 pattern
- */
- public static OffsetDateTime parseDate(String dateString) {
- String pattern = MAX_PRECISION_PATTERN;
- switch (dateString.length()) {
- case 28: // "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"-> [2012-01-04T23:21:59.1234567Z] length = 28
- case 27: // "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"-> [2012-01-04T23:21:59.123456Z] length = 27
- case 26: // "yyyy-MM-dd'T'HH:mm:ss.SSSSS'Z'"-> [2012-01-04T23:21:59.12345Z] length = 26
- case 25: // "yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'"-> [2012-01-04T23:21:59.1234Z] length = 25
- case 24: // "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"-> [2012-01-04T23:21:59.123Z] length = 24
- dateString = dateString.substring(0, MAX_PRECISION_DATESTRING_LENGTH);
- break;
- case 23: // "yyyy-MM-dd'T'HH:mm:ss.SS'Z'"-> [2012-01-04T23:21:59.12Z] length = 23
- // SS is assumed to be milliseconds, so a trailing 0 is necessary
- dateString = dateString.replace("Z", "0");
- break;
- case 22: // "yyyy-MM-dd'T'HH:mm:ss.S'Z'"-> [2012-01-04T23:21:59.1Z] length = 22
- // S is assumed to be milliseconds, so trailing 0's are necessary
- dateString = dateString.replace("Z", "00");
- break;
- case 20: // "yyyy-MM-dd'T'HH:mm:ss'Z'"-> [2012-01-04T23:21:59Z] length = 20
- pattern = Utility.ISO8601_PATTERN;
- break;
- case 17: // "yyyy-MM-dd'T'HH:mm'Z'"-> [2012-01-04T23:21Z] length = 17
- pattern = Utility.ISO8601_PATTERN_NO_SECONDS;
- break;
- default:
- throw new IllegalArgumentException(String.format(Locale.ROOT, SR.INVALID_DATE_STRING, dateString));
- }
-
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern, Locale.ROOT);
- return LocalDateTime.parse(dateString, formatter).atZone(UTC_ZONE).toOffsetDateTime();
- }
-
- /**
- * Asserts that the specified integer is in the valid range.
- *
- * @param param
- * A String
that represents the name of the parameter, which becomes the exception message
- * text if the value
parameter is out of bounds.
- * @param value
- * The value of the specified parameter.
- * @param min
- * The minimum value for the specified parameter.
- * @param max
- * The maximum value for the specified parameter.
- * @throws IllegalArgumentException If {@code value} is less than {@code min} or greater than {@code max}.
- */
- public static void assertInBounds(final String param, final long value, final long min, final long max) {
- if (value < min || value > max) {
- throw new IllegalArgumentException(String.format(Locale.ROOT, SR.PARAMETER_NOT_IN_RANGE, param, min, max));
- }
- }
-
- /**
- * Performs safe encoding of the specified string, taking care to insert %20 for each space character,
- * instead of inserting the + character.
- */
- static String safeURLEncode(final String stringToEncode) {
- if (stringToEncode == null) {
- return null;
- }
- if (stringToEncode.length() == 0) {
- return Constants.EMPTY_STRING;
- }
-
- try {
- final String tString = URLEncoder.encode(stringToEncode, Constants.UTF8_CHARSET);
-
- if (stringToEncode.contains(" ")) {
- final StringBuilder outBuilder = new StringBuilder();
-
- int startDex = 0;
- for (int m = 0; m < stringToEncode.length(); m++) {
- if (stringToEncode.charAt(m) == ' ') {
- if (m > startDex) {
- outBuilder.append(URLEncoder.encode(stringToEncode.substring(startDex, m),
- Constants.UTF8_CHARSET));
- }
-
- outBuilder.append("%20");
- startDex = m + 1;
- }
- }
-
- if (startDex != stringToEncode.length()) {
- outBuilder.append(URLEncoder.encode(stringToEncode.substring(startDex, stringToEncode.length()),
- Constants.UTF8_CHARSET));
- }
-
- return outBuilder.toString();
- } else {
- return tString;
- }
-
- } catch (final UnsupportedEncodingException e) {
- throw new Error(e); // If we can't encode UTF-8, we fail.
- }
- }
-
- static Date
+ * @return the corresponding Date
object
+ * @throws IllegalArgumentException If {@code dateString} doesn't match an ISO8601 pattern
+ */
+ public static OffsetDateTime parseDate(String dateString) {
+ String pattern = MAX_PRECISION_PATTERN;
+ switch (dateString.length()) {
+ case 28: // "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"-> [2012-01-04T23:21:59.1234567Z] length = 28
+ case 27: // "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"-> [2012-01-04T23:21:59.123456Z] length = 27
+ case 26: // "yyyy-MM-dd'T'HH:mm:ss.SSSSS'Z'"-> [2012-01-04T23:21:59.12345Z] length = 26
+ case 25: // "yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'"-> [2012-01-04T23:21:59.1234Z] length = 25
+ case 24: // "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"-> [2012-01-04T23:21:59.123Z] length = 24
+ dateString = dateString.substring(0, MAX_PRECISION_DATESTRING_LENGTH);
+ break;
+ case 23: // "yyyy-MM-dd'T'HH:mm:ss.SS'Z'"-> [2012-01-04T23:21:59.12Z] length = 23
+ // SS is assumed to be milliseconds, so a trailing 0 is necessary
+ dateString = dateString.replace("Z", "0");
+ break;
+ case 22: // "yyyy-MM-dd'T'HH:mm:ss.S'Z'"-> [2012-01-04T23:21:59.1Z] length = 22
+ // S is assumed to be milliseconds, so trailing 0's are necessary
+ dateString = dateString.replace("Z", "00");
+ break;
+ case 20: // "yyyy-MM-dd'T'HH:mm:ss'Z'"-> [2012-01-04T23:21:59Z] length = 20
+ pattern = Utility.ISO8601_PATTERN;
+ break;
+ case 17: // "yyyy-MM-dd'T'HH:mm'Z'"-> [2012-01-04T23:21Z] length = 17
+ pattern = Utility.ISO8601_PATTERN_NO_SECONDS;
+ break;
+ default:
+ throw new IllegalArgumentException(String.format(Locale.ROOT, Constants.MessageConstants.INVALID_DATE_STRING, dateString));
+ }
+
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern, Locale.ROOT);
+ return LocalDateTime.parse(dateString, formatter).atZone(ZoneOffset.UTC).toOffsetDateTime();
+ }
+
+ /**
+ * Wraps any potential error responses from the service and applies post processing of the response's eTag header
+ * to standardize the value.
+ *
+ * @param response Response from a service call
+ * @param errorWrapper Error wrapping function that is applied to the response
+ * @param Sample Code
- * - *For more samples, please see the samples - * file
*/ public RequestRetryOptions(RetryPolicyType retryPolicyType, Integer maxTries, Integer tryTimeout, Long retryDelayInMs, Long maxRetryDelayInMs, String secondaryHost) { @@ -100,40 +98,40 @@ public RequestRetryOptions(RetryPolicyType retryPolicyType, Integer maxTries, In } this.maxRetryDelayInMs = TimeUnit.SECONDS.toMillis(120); } - this.secondaryHost = secondaryHost; } /** - * @return the maximum number attempts that will be retried before the operation finally fails. + * @return the maximum number of retries that will be attempted. */ public int maxTries() { return this.maxTries; } /** - * @return the timeout in seconds allowed for each retry operation. + * @return the maximum time, in seconds, allowed for a request until it is considered timed out. */ public int tryTimeout() { return this.tryTimeout; } /** - * @return the secondary host that retries could be attempted against. + * @return the URI of the secondary host where retries are attempted. If this is null then there is no secondary + * host and all retries are attempted against the original host. */ public String secondaryHost() { return this.secondaryHost; } /** - * @return the delay in milliseconds between retry attempts. + * @return the delay in milliseconds between each retry attempt. */ public long retryDelayInMs() { return retryDelayInMs; } /** - * @return the maximum delay in milliseconds between retry attempts. + * @return the maximum delay in milliseconds allowed between each retry. */ public long maxRetryDelayInMs() { return maxRetryDelayInMs; diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java similarity index 93% rename from sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java rename to sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java index 83bef0b2b49f..22b62af89b04 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java @@ -44,7 +44,7 @@ public Mono