Class ConnHelper

java.lang.Object
com.intellijava.core.utils.ConnHelper

public class ConnHelper extends Object
ConnHelper is a class that contains common helper functions to call remote services.
Author:
github.com/Barqawiz
  • Constructor Details

    • ConnHelper

      public ConnHelper()
      ConnHelper default constructor.
  • Method Details

    • convertMaptToJson

      public static String convertMaptToJson(Map<String,Object> params)
      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

      public static <T> T convertSteamToModel(InputStream stream, Class<T> classOfT)
      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

      public static String getErrorMessage(HttpURLConnection connection) throws IOException
      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

      public static String readStream(InputStream stream) throws IOException
      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.