Package com.intellijava.core.utils
Class ConnHelper
java.lang.Object
com.intellijava.core.utils.ConnHelper
ConnHelper is a class that contains common helper functions to call remote services.
- Author:
- github.com/Barqawiz
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertMaptToJson(Map<String, Object> params) Convert a map of string key and object value to Json string.static <T> TconvertSteamToModel(InputStream stream, Class<T> classOfT) Convert API input stream to the relevant class model.static StringgetErrorMessage(HttpURLConnection connection) Get the error message from an HttpURLConnection.static StringreadStream(InputStream stream) Read an input stream and return its contents as a string.
-
Constructor Details
-
ConnHelper
public ConnHelper()ConnHelper default constructor.
-
-
Method Details
-
convertMaptToJson
Convert a map of string key and object value to Json string.- Parameters:
params- a map of key-value pairs to be converted to json.- Returns:
- a json string representation of the provided map.
-
convertSteamToModel
Convert API input stream to the relevant class model.- Type Parameters:
T- the type of the response model.- Parameters:
stream- input stream from the called API.classOfT- the class type of the response model.- Returns:
- an instance of the provided class type, T, that represents the API response.
-
getErrorMessage
Get the error message from an HttpURLConnection.- Parameters:
connection- the HttpURLConnection from which to get the error message.- Returns:
- the error message as a string.
- Throws:
IOException- if there is an issue reading the error stream.
-
readStream
Read an input stream and return its contents as a string.- Parameters:
stream- the input stream to read.- Returns:
- the contents of the input stream as a string.
- Throws:
IOException- if there is an issue reading the input stream.
-