Package com.applitools.utils
Class GeneralUtils
- java.lang.Object
-
- com.applitools.utils.GeneralUtils
-
public class GeneralUtils extends Object
General purpose utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcreateErrorMessageFromExceptionWithText(Exception e, String errorText)static StringcreateEyesMessageWithLevel(String message, String level)static CalendarfromISO8601DateTime(String dateTime)CreatesCalendarinstance from an ISO 8601 formatted string.static DategetDate(DateFormat format, String date)Gets date.static booleangetDontCloseBatches()static StringgetEnvString(String applitools_env)static longgetFullSecondsElapsedTimeMillis(long start, long end)Gets full seconds elapsed time millis.static byte[]getGzipByteArrayOutputStream(String domJson)Get gzip byte array output stream byte [ ].static StringgetLastWordOfStringWithRegex(String charSequence, String regex)static StringgetPropertyString(String property)static URIgetServerUrl()Gets default server url.static StringgetSha256hash(byte[] content)Gets sha 256 hash.static StringgetSha256hash(Byte[] content)Gets sha 256 hash.static byte[]getUnGzipByteArrayOutputStream(byte[] gZippedString)Get un gzip byte array output stream byte [ ].static voidlogExceptionStackTrace(Logger logger, Stage stage, Type type, Throwable ex, String... testIds)static voidlogExceptionStackTrace(Logger logger, Stage stage, Throwable ex, String... testIds)static <T> TparseJsonToObject(String jsonStr, Class<T> tClass)Parse json to object t.static byte[]readInputStream(InputStream inputStream)static StringreadInputStreamAsString(InputStream inputStream)static StringreadTextFromResource(String resource)Creates aStringfrom a file specified byresource.static StringsanitizeURL(String urlToSanitize)static voidsleep(long milliseconds)Sleeps the input amount of milliseconds.static StringtoISO8601DateTime(Calendar calendar)Formats date and time as represented by a calendar instance to an ISO 8601 string.static StringtoRfc1123(Calendar calendar)Formats date and time as represented by a calendar instance to an TFC 1123 string.static voidtryRunTaskWithRetry(EyesRunnable task, long retryTimeoutSeconds, long sleepTimeBetweenRetiesMS, String errorMessageOnTimeout, Logger logger)
-
-
-
Method Detail
-
readInputStream
public static byte[] readInputStream(InputStream inputStream) throws IOException
- Throws:
IOException
-
readInputStreamAsString
public static String readInputStreamAsString(InputStream inputStream) throws IOException
- Throws:
IOException
-
toISO8601DateTime
public static String toISO8601DateTime(Calendar calendar)
Formats date and time as represented by a calendar instance to an ISO 8601 string.- Parameters:
calendar- The date and time which we would like to format.- Returns:
- An ISO8601 formatted string representing the input date and time.
-
toRfc1123
public static String toRfc1123(Calendar calendar)
Formats date and time as represented by a calendar instance to an TFC 1123 string.- Parameters:
calendar- The date and time which we would like to format.- Returns:
- An RFC 1123 formatted string representing the input date and time.
-
fromISO8601DateTime
public static Calendar fromISO8601DateTime(String dateTime) throws ParseException
CreatesCalendarinstance from an ISO 8601 formatted string.- Parameters:
dateTime- An ISO 8601 formatted string.- Returns:
- A
Calendarinstance representing the given date and time. - Throws:
ParseException- the parse exception
-
sleep
public static void sleep(long milliseconds)
Sleeps the input amount of milliseconds.- Parameters:
milliseconds- The number of milliseconds to sleep.
-
getDate
public static Date getDate(DateFormat format, String date)
Gets date.- Parameters:
format- The date format parser.date- The date string in a format matchingformat.- Returns:
- The
Daterepresented by the input string.
-
getFullSecondsElapsedTimeMillis
public static long getFullSecondsElapsedTimeMillis(long start, long end)Gets full seconds elapsed time millis.- Parameters:
start- The start time. (Milliseconds)end- The end time. (Milliseconds).- Returns:
- The elapsed time between the start and end times, rounded up to a full second, in milliseconds.
-
readTextFromResource
public static String readTextFromResource(String resource)
Creates aStringfrom a file specified byresource.- Parameters:
resource- The resource path.- Returns:
- The resource's text.
- Throws:
EyesException- If there was a problem reading the resource.
-
logExceptionStackTrace
public static void logExceptionStackTrace(Logger logger, Stage stage, Throwable ex, String... testIds)
-
logExceptionStackTrace
public static void logExceptionStackTrace(Logger logger, Stage stage, Type type, Throwable ex, String... testIds)
-
getServerUrl
public static URI getServerUrl()
Gets default server url.- Returns:
- the default server url
-
getGzipByteArrayOutputStream
public static byte[] getGzipByteArrayOutputStream(String domJson)
Get gzip byte array output stream byte [ ].- Parameters:
domJson- JSON as string to be gzipped- Returns:
- byte[] of the gzipped string
-
getUnGzipByteArrayOutputStream
public static byte[] getUnGzipByteArrayOutputStream(byte[] gZippedString) throws IOExceptionGet un gzip byte array output stream byte [ ].- Parameters:
gZippedString- byte array gzipped encoded- Returns:
- byte[] of the ungzipped byte array
- Throws:
IOException- the io exception
-
parseJsonToObject
public static <T> T parseJsonToObject(String jsonStr, Class<T> tClass) throws IOException
Parse json to object t.- Type Parameters:
T- The type parameter- Parameters:
jsonStr- The JSON string to parsetClass- The Class object of TypeT- Returns:
- An instance of Class
T, created by parsing of the given JSON string - Throws:
IOException- An IO Exception
-
getSha256hash
public static String getSha256hash(Byte[] content)
Gets sha 256 hash.- Parameters:
content- the content- Returns:
- the sha 256 hash
-
getSha256hash
public static String getSha256hash(byte[] content)
Gets sha 256 hash.- Parameters:
content- the content- Returns:
- the sha 256 hash
-
getDontCloseBatches
public static boolean getDontCloseBatches()
-
getLastWordOfStringWithRegex
public static String getLastWordOfStringWithRegex(String charSequence, String regex)
-
tryRunTaskWithRetry
public static void tryRunTaskWithRetry(EyesRunnable task, long retryTimeoutSeconds, long sleepTimeBetweenRetiesMS, String errorMessageOnTimeout, Logger logger) throws EyesException
- Throws:
EyesException
-
createErrorMessageFromExceptionWithText
public static String createErrorMessageFromExceptionWithText(Exception e, String errorText)
-
-