Class Util

java.lang.Object
org.filestack.internal.Util

public class Util extends Object
Small helper functions that don't need their own class.
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • createStringPart

      public static okhttp3.RequestBody createStringPart(String content)
      Creates Request Body from String. For multipart form uploads.
    • partToString

      public static String partToString(okhttp3.RequestBody body) throws IOException
      Converts RequestBody to String.
      Throws:
      IOException
    • throwHttpResponseException

      public static <T> void throwHttpResponseException(Response<T> response) throws IOException
      Throws an HttpException with the code and error body from a Response.
      Parameters:
      response - response from a backend call
      Throws:
      HttpException - always unless error reading response body
      IOException - on error reading response body
    • checkResponseAndThrow

      public static <T> void checkResponseAndThrow(Response<T> response) throws IOException
      Checks status of backend responses. Throws a HttpException if response isn't in 200 range.
      Parameters:
      response - response from a backend call
      Throws:
      HttpException - on response code not in 200 range
      IOException - on error reading response body
    • createWriteFile

      public static File createWriteFile(String pathname) throws IOException
      Creates and validates a new File for writing.
      Parameters:
      pathname - path to file
      Returns:
      file pointing to pathname
      Throws:
      FileNotFoundException - if path isn't usable
      IOException - if a file can't be created
    • createReadFile

      public static File createReadFile(String pathname) throws IOException
      Creates and validates a new File for reading.
      Parameters:
      pathname - path to file
      Returns:
      file pointing to pathname
      Throws:
      FileNotFoundException - if path doesn't exist or isn't usable
      IOException
    • isUnitTest

      public static boolean isUnitTest()
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable String value)
      Check if String is null or empty.
    • throwIfNullOrEmpty

      public static void throwIfNullOrEmpty(@Nullable String value, String message)
      Throw an IllegalArgumentException with message if String is mull or empty.
    • base64

      public static String base64(byte[] data)
    • base64

      public static String base64(byte[] data, int offset, int length)
    • base64Url

      public static String base64Url(byte[] data)
    • addIfNotNull

      public static void addIfNotNull(com.google.gson.JsonObject object, String key, String value)
      Populates JsonObject if value is not null.
    • addIfNotNull

      public static void addIfNotNull(com.google.gson.JsonObject object, String key, @Nullable Number value)
      Populates JsonObject if value is not null.