Class Utility


  • public final class Utility
    extends Object
    Utility methods for storage client libraries.
    • Field Detail

      • STORAGE_TRACING_NAMESPACE_VALUE

        public static final String STORAGE_TRACING_NAMESPACE_VALUE
        Please see here for more information on Azure resource provider namespaces.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Utility

        public Utility()
    • Method Detail

      • urlDecode

        public static String urlDecode​(String stringToDecode)
        Performs a safe decoding of the passed string, taking care to preserve each + character rather than replacing it with a space character.
        Parameters:
        stringToDecode - String value to decode
        Returns:
        the decoded string value
        Throws:
        RuntimeException - If the UTF-8 charset isn't supported
      • urlEncode

        public static String urlEncode​(String stringToEncode)
        Performs a safe encoding of the specified string, taking care to insert %20 for each space character instead of inserting the + character.
        Parameters:
        stringToEncode - String value to encode
        Returns:
        the encoded string value
        Throws:
        RuntimeException - If the UTF-8 charset ins't supported
      • encodeUrlPath

        public static String encodeUrlPath​(String url)
        Performs a safe encoding of a url string, only encoding the path.
        Parameters:
        url - The url to encode.
        Returns:
        The encoded url.
      • parseDate

        @Deprecated
        public static OffsetDateTime parseDate​(String dateString)
        Deprecated.
        Use StorageImplUtils.parseDateAndFormat(String)
        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
        Throws:
        IllegalArgumentException - If dateString doesn't match an ISO8601 pattern
      • convertStreamToByteBuffer

        public static Flux<ByteBuffer> convertStreamToByteBuffer​(InputStream data,
                                                                 long length,
                                                                 int blockSize)
        A utility method for converting the input stream to Flux of ByteBuffer. Will check the equality of entity length and the input length.
        Parameters:
        data - The input data which needs to convert to ByteBuffer.
        length - The expected input data length.
        blockSize - The size of each ByteBuffer.
        Returns:
        ByteBuffer which contains the input data.
        Throws:
        com.azure.core.exception.UnexpectedLengthException - when input data length mismatch input length.
        RuntimeException - When I/O error occurs.
      • convertStreamToByteBuffer

        public static Flux<ByteBuffer> convertStreamToByteBuffer​(InputStream data,
                                                                 long length,
                                                                 int blockSize,
                                                                 boolean markAndReset)
        A utility method for converting the input stream to Flux of ByteBuffer. Will check the equality of entity length and the input length. Using markAndReset=true to force a seekable stream implies a buffering strategy is not being used, in which case length is still needed for whatever underlying REST call is being streamed to. If markAndReset=false and data is being buffered, consider using FluxUtil.toFluxByteBuffer(InputStream, int) which does not require a data length.
        Parameters:
        data - The input data which needs to convert to ByteBuffer.
        length - The expected input data length.
        blockSize - The size of each ByteBuffer.
        markAndReset - Whether the stream needs to be marked and reset. This should generally always be true to support retries. It is false in the case of buffered upload to support non markable streams because buffered upload uses its own mechanisms to support retries.
        Returns:
        ByteBuffer which contains the input data.
        Throws:
        com.azure.core.exception.UnexpectedLengthException - when input data length mismatch input length.
        RuntimeException - When I/O error occurs.
      • appendQueryParameter

        public static String appendQueryParameter​(String url,
                                                  String key,
                                                  String value)
        Appends a query parameter to a url.
        Parameters:
        url - The url.
        key - The query key.
        value - The query value.
        Returns:
        The updated url.