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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addIfNotNull
(com.google.gson.JsonObject object, String key, Number value) PopulatesJsonObject
if value is not null.static void
addIfNotNull
(com.google.gson.JsonObject object, String key, String value) PopulatesJsonObject
if value is not null.static String
base64
(byte[] data) static String
base64
(byte[] data, int offset, int length) static String
base64Url
(byte[] data) static <T> void
checkResponseAndThrow
(Response<T> response) Checks status of backend responses.static File
createReadFile
(String pathname) Creates and validates a newFile
for reading.static okhttp3.RequestBody
createStringPart
(String content) CreatesRequest Body
from String.static File
createWriteFile
(String pathname) Creates and validates a newFile
for writing.static boolean
isNullOrEmpty
(String value) Check if String is null or empty.static boolean
static String
partToString
(okhttp3.RequestBody body) ConvertsRequestBody
to String.static <T> void
throwHttpResponseException
(Response<T> response) Throws anHttpException
with the code and error body from aResponse
.static void
throwIfNullOrEmpty
(String value, String message) Throw anIllegalArgumentException
with message if String is mull or empty.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
createStringPart
CreatesRequest Body
from String. For multipart form uploads. -
partToString
ConvertsRequestBody
to String.- Throws:
IOException
-
throwHttpResponseException
Throws anHttpException
with 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 aHttpException
if 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 newFile
for 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 newFile
for 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 anIllegalArgumentException
with message if String is mull or empty. -
base64
-
base64
-
base64Url
-
addIfNotNull
PopulatesJsonObject
if value is not null. -
addIfNotNull
public static void addIfNotNull(com.google.gson.JsonObject object, String key, @Nullable Number value) PopulatesJsonObject
if value is not null.
-