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