Package glair.vision.util
Class Util
java.lang.Object
glair.vision.util.Util
Utility class for common operations and HTTP requests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFileToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String filePath) Adds a file to the specifiedMultipartBody.Builderas form data.static voidaddTextToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String fieldValue) Adds text data to the specifiedMultipartBody.Builderas form data.static voidcheckFileExist(String filePath) Checks if a file exists at the specified file path.static okhttp3.MultipartBody.BuilderCreates and returns a new instance ofMultipartBody.Builderconfigured for forming HTTP multipart requests with form data.static StringfileToBase64(String filePath) Converts a file located at the specified path to a Base64-encoded string.static voidChecks if a value is null and throws an exception if it is.static StringRemoves all whitespace from a string.static StringvisionFetch(Config config, Request request) Performs an HTTP request and fetches data from a specified endpoint.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
visionFetch
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 ofMultipartBody.Builderconfigured for forming HTTP multipart requests with form data.- Returns:
- A
MultipartBody.Builderconfigured for form data.
-
addFileToFormData
public static void addFileToFormData(okhttp3.MultipartBody.Builder builder, String fieldName, String filePath) Adds a file to the specifiedMultipartBody.Builderas form data.- Parameters:
builder- TheMultipartBody.Builderto 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 specifiedMultipartBody.Builderas form data.- Parameters:
builder- TheMultipartBody.Builderto 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
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
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
Removes all whitespace from a string.- Parameters:
str- The input string.- Returns:
- The string with all whitespace removed.
-
checkFileExist
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.
-