Package org.filestack.internal
Class Util
java.lang.Object
org.filestack.internal.Util
Small helper functions that don't need their own class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddIfNotNull(com.google.gson.JsonObject object, String key, Number value) PopulatesJsonObjectif value is not null.static voidaddIfNotNull(com.google.gson.JsonObject object, String key, String value) PopulatesJsonObjectif value is not null.static Stringbase64(byte[] data) static Stringbase64(byte[] data, int offset, int length) static Stringbase64Url(byte[] data) static <T> voidcheckResponseAndThrow(Response<T> response) Checks status of backend responses.static FilecreateReadFile(String pathname) Creates and validates a newFilefor reading.static okhttp3.RequestBodycreateStringPart(String content) CreatesRequest Bodyfrom String.static FilecreateWriteFile(String pathname) Creates and validates a newFilefor writing.static booleanisNullOrEmpty(String value) Check if String is null or empty.static booleanstatic StringpartToString(okhttp3.RequestBody body) ConvertsRequestBodyto String.static <T> voidthrowHttpResponseException(Response<T> response) Throws anHttpExceptionwith the code and error body from aResponse.static voidthrowIfNullOrEmpty(String value, String message) Throw anIllegalArgumentExceptionwith message if String is mull or empty.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
createStringPart
CreatesRequest Bodyfrom String. For multipart form uploads. -
partToString
ConvertsRequestBodyto String.- Throws:
IOException
-
throwHttpResponseException
Throws anHttpExceptionwith the code and error body from aResponse.- Parameters:
response- response from a backend call- Throws:
HttpException- always unless error reading response bodyIOException- on error reading response body
-
checkResponseAndThrow
Checks status of backend responses. Throws aHttpExceptionif response isn't in 200 range.- Parameters:
response- response from a backend call- Throws:
HttpException- on response code not in 200 rangeIOException- on error reading response body
-
createWriteFile
Creates and validates a newFilefor writing.- Parameters:
pathname- path to file- Returns:
- file pointing to pathname
- Throws:
FileNotFoundException- if path isn't usableIOException- if a file can't be created
-
createReadFile
Creates and validates a newFilefor reading.- Parameters:
pathname- path to file- Returns:
- file pointing to pathname
- Throws:
FileNotFoundException- if path doesn't exist or isn't usableIOException
-
isUnitTest
public static boolean isUnitTest() -
isNullOrEmpty
Check if String is null or empty. -
throwIfNullOrEmpty
Throw anIllegalArgumentExceptionwith message if String is mull or empty. -
base64
-
base64
-
base64Url
-
addIfNotNull
PopulatesJsonObjectif value is not null. -
addIfNotNull
public static void addIfNotNull(com.google.gson.JsonObject object, String key, @Nullable Number value) PopulatesJsonObjectif value is not null.
-