Class GeneralUtils


  • public class GeneralUtils
    extends Object
    General purpose utilities.
    • Method Detail

      • 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
        Creates Calendar instance from an ISO 8601 formatted string.
        Parameters:
        dateTime - An ISO 8601 formatted string.
        Returns:
        A Calendar instance 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 matching format.
        Returns:
        The Date represented 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 a String from a file specified by resource.
        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)
      • 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 IOException
        Get 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 parse
        tClass - The Class object of Type T
        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
      • sanitizeURL

        public static String sanitizeURL​(String urlToSanitize)
      • getEnvString

        public static String getEnvString​(String applitools_env)
      • getDontCloseBatches

        public static boolean getDontCloseBatches()
      • getPropertyString

        public static String getPropertyString​(String property)
      • getLastWordOfStringWithRegex

        public static String getLastWordOfStringWithRegex​(String charSequence,
                                                          String regex)
      • createErrorMessageFromExceptionWithText

        public static String createErrorMessageFromExceptionWithText​(Exception e,
                                                                     String errorText)
      • createEyesMessageWithLevel

        public static String createEyesMessageWithLevel​(String message,
                                                        String level)