Package com.ibm.cloud.sdk.core.util
Class RequestUtils
- java.lang.Object
-
- com.ibm.cloud.sdk.core.util.RequestUtils
-
public final class RequestUtils extends java.lang.Object
Utility functions to use when creating aRequestBuilder
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
buildUserAgent(java.lang.String subComponent)
Builds the user agent using System properties.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()
Returns the "system info" which consists of the values of system properties whose names are contained in the "properties" list defined above.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 aMap
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 aMap
with only the specified given key, or array of keys.
-
-
-
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 aMap
excluding the given key, or array of keys.- Parameters:
params
- the parameterstoOmit
- 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 aMap
with only the specified given key, or array of keys. IftoPick
is empty all keys will remain in the Map.- Parameters:
params
- the parameterstoPick
- 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 arrayseparator
- 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 iterableseparator
- the separator- Returns:
- the joined String
-
buildUserAgent
public static java.lang.String buildUserAgent(java.lang.String subComponent)
Builds the user agent using System properties.- Parameters:
subComponent
- an optional sub-component to be included in the user agent value- Returns:
- the string that represents the user agent
-
getSystemInfo
public static java.lang.String getSystemInfo()
Returns the "system info" which consists of the values of system properties whose names are contained in the "properties" list defined above.- Returns:
- the system info associated with the current environment
-
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/PUTcontentType
- 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/PUTcontentType
- the HTTP contentType to use.- Returns:
RequestBody
-
-