Class RequestUtils


  • public final class RequestUtils
    extends java.lang.Object
    Utility functions to use when creating a RequestBuilder.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encode​(java.lang.String content)
      Encode a string into a valid URL string.
      static okhttp3.RequestBody fileBody​(java.io.File file, java.lang.String contentType)
      Returns a request body that encapsulates the specified file qualified with the specified content type.
      static java.lang.String getSystemInfo()  
      static java.lang.String getUserAgent()
      Gets the user agent.
      static okhttp3.RequestBody inputStreamBody​(java.io.InputStream stream, java.lang.String contentType)
      Returns a request body the encapsulates the specified input stream qualified with the specified content type.
      static java.lang.String join​(java.lang.Iterable<?> iterable, java.lang.String separator)
      Creates a String of all elements of an iterable, separated by a separator.
      static <T> java.lang.String join​(T[] array, java.lang.String separator)
      Creates a String of all elements of an array, separated by a separator.
      static java.util.Map<java.lang.String,​java.lang.Object> omit​(java.util.Map<java.lang.String,​java.lang.Object> params, java.lang.String... toOmit)
      Return a copy of a Map excluding the given key, or array of keys.
      static java.util.Map<java.lang.String,​java.lang.Object> pick​(java.util.Map<java.lang.String,​java.lang.Object> params, java.lang.String... toPick)
      Return a copy of a Map with only the specified given key, or array of keys.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • encode

        public static java.lang.String encode​(java.lang.String content)
        Encode a string into a valid URL string.
        Parameters:
        content - the content
        Returns:
        the string
      • omit

        public static java.util.Map<java.lang.String,​java.lang.Object> omit​(java.util.Map<java.lang.String,​java.lang.Object> params,
                                                                                  java.lang.String... toOmit)
        Return a copy of a Map excluding the given key, or array of keys.
        Parameters:
        params - the parameters
        toOmit - the keys to omit
        Returns:
        the map with the omitted key-value pars, or null if params is null
      • pick

        public static java.util.Map<java.lang.String,​java.lang.Object> pick​(java.util.Map<java.lang.String,​java.lang.Object> params,
                                                                                  java.lang.String... toPick)
        Return a copy of a Map with only the specified given key, or array of keys. If toPick is empty all keys will remain in the Map.
        Parameters:
        params - the parameters
        toPick - the keys to pick
        Returns:
        the map with the picked key-value pars, or null if params is null
      • join

        public static <T> java.lang.String join​(T[] array,
                                                java.lang.String separator)
        Creates a String of all elements of an array, separated by a separator.
        Type Parameters:
        T - the generic type
        Parameters:
        array - the array
        separator - the separator
        Returns:
        the joined String
      • join

        public static java.lang.String join​(java.lang.Iterable<?> iterable,
                                            java.lang.String separator)
        Creates a String of all elements of an iterable, separated by a separator.
        Parameters:
        iterable - the iterable
        separator - the separator
        Returns:
        the joined String
      • getSystemInfo

        public static java.lang.String getSystemInfo()
      • getUserAgent

        public static java.lang.String getUserAgent()
        Gets the user agent.
        Returns:
        the user agent
      • fileBody

        public static okhttp3.RequestBody fileBody​(java.io.File file,
                                                   java.lang.String contentType)
        Returns a request body that encapsulates the specified file qualified with the specified content type.
        Parameters:
        file - the file content to POST/PUT
        contentType - the HTTP contentType to use.
        Returns:
        RequestBody
      • inputStreamBody

        public static okhttp3.RequestBody inputStreamBody​(java.io.InputStream stream,
                                                          java.lang.String contentType)
        Returns a request body the encapsulates the specified input stream qualified with the specified content type.
        Parameters:
        stream - the input stream content to POST/PUT
        contentType - the HTTP contentType to use.
        Returns:
        RequestBody