Class Util

java.lang.Object
glair.vision.util.Util

public class Util extends Object
Utility class for common operations and HTTP requests.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addFileToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String filePath)
    Adds a file to the specified MultipartBody.Builder as form data.
    static void
    addTextToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String fieldValue)
    Adds text data to the specified MultipartBody.Builder as form data.
    static void
    Checks if a file exists at the specified file path.
    static okhttp3.MultipartBody.Builder
    Creates and returns a new instance of MultipartBody.Builder configured for forming HTTP multipart requests with form data.
    static String
    fileToBase64(String filePath)
    Converts a file located at the specified path to a Base64-encoded string.
    static void
    require(String key, String value)
    Checks if a value is null and throws an exception if it is.
    static String
    Removes all whitespace from a string.
    static String
    visionFetch(Config config, Request request)
    Performs an HTTP request and fetches data from a specified endpoint.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • visionFetch

      public static String visionFetch(Config config, Request request) throws Exception
      Performs an HTTP request and fetches data from a specified endpoint.
      Parameters:
      config - The configuration settings for the request.
      request - The HTTP request to be executed.
      Returns:
      The response data from the HTTP request.
      Throws:
      Exception - If an error occurs during the HTTP request or if the response status is not OK (200).
    • createFormData

      public static okhttp3.MultipartBody.Builder createFormData()
      Creates and returns a new instance of MultipartBody.Builder configured for forming HTTP multipart requests with form data.
      Returns:
      A MultipartBody.Builder configured for form data.
    • addFileToFormData

      public static void addFileToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String filePath)
      Adds a file to the specified MultipartBody.Builder as form data.
      Parameters:
      builder - The MultipartBody.Builder to which the file should be added.
      fieldName - The name of the form field for the file.
      filePath - The path to the file to be added.
    • addTextToFormData

      public static void addTextToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String fieldValue)
      Adds text data to the specified MultipartBody.Builder as form data.
      Parameters:
      builder - The MultipartBody.Builder to which the text data should be added.
      fieldName - The name of the form field for the text data.
      fieldValue - The value of the text data.
    • fileToBase64

      public static String fileToBase64(String filePath) throws Exception
      Converts a file located at the specified path to a Base64-encoded string.
      Parameters:
      filePath - The path to the file to be converted to Base64.
      Returns:
      A Base64-encoded string representing the content of the file.
      Throws:
      Exception - If an error occurs during the file conversion process.
    • require

      public static void require(String key, String value) throws Exception
      Checks if a value is null and throws an exception if it is.
      Parameters:
      key - The key associated with the value.
      value - The value to check.
      Throws:
      Exception - If the value is null.
    • trimAll

      public static String trimAll(String str)
      Removes all whitespace from a string.
      Parameters:
      str - The input string.
      Returns:
      The string with all whitespace removed.
    • checkFileExist

      public static void checkFileExist(String filePath) throws Exception
      Checks if a file exists at the specified file path.
      Parameters:
      filePath - The path to the file to be checked.
      Throws:
      Exception - If the file does not exist or an error occurs during the check.