Class CommonUtils

java.lang.Object
ee.datel.dogis.utils.CommonUtils

@Component public class CommonUtils extends Object
Common methods.
  • Method Details

    • getForkJoinPool

      public static ExecutorService getForkJoinPool()
      Provides singleton ForkJoinPool
      Returns:
      the executor
    • getTaskExecutor

      public static org.springframework.scheduling.SchedulingTaskExecutor getTaskExecutor()
      Provides singleton SchedulingTaskExecutor
      Returns:
      the executor
    • getVirtualExecutor

      public static ExecutorService getVirtualExecutor()
      Provides singleton Virtual Thread ExecutorService
      Returns:
      the executor
    • copyFields

      public static <K, T> T copyFields(K source, T target)
      Copy values of fields with same name from one object to other, uses reflection.
      Type Parameters:
      K - generic
      T - generic
      Parameters:
      source - values source object
      target - target object
      Returns:
      target object with values copied
    • doNothing

      public static void doNothing(Throwable ex)
      Does nothing.
      Parameters:
      ex - exception
    • getRandomInt

      public static int getRandomInt()
      Random integer provider.
      Returns:
      random value
    • getRandomLong

      public static long getRandomLong()
      Random long provider.
      Returns:
      random value
    • getRandomProvider

      public static SecureRandom getRandomProvider()
      Random provider, singleton.
      Returns:
      provider.
    • getExceptionCause

      public static Throwable getExceptionCause(Exception ex)
      REtrieves the root cause from exception.
      Parameters:
      ex - exception
      Returns:
      root cause
    • popBuffer

      public static StringBuilder popBuffer()
      Retrieve a StringBuilder.
      Returns:
      StringBuilder
    • push

      public static void push(StringBuilder sb)
      Stores buffer back into storage.
      Parameters:
      sb - StringBuilder to store
    • concatenate

      public static String concatenate(CharSequence... part)
      Concatenates strings.
      Parameters:
      part - values to concatenate
      Returns:
      concatenated string
    • split

      public static String[] split(String list, char onChar)
      Splits input string on separator char.
      Trims result and removes empty elements.
      Parameters:
      list - the sequence of characters to split
      onChar - separator character
      Returns:
      splitted
    • convertToLocalizedDate

      public static Date convertToLocalizedDate(LocalDateTime utcTimestamp)
      Convert LocalDateTime to Localized Date.
      Parameters:
      utcTimestamp - UTC dateTime
      Returns:
      truncatedTo(ChronoUnit.MILLIS)
    • convertToLocalDateTimeZ

      public static LocalDateTime convertToLocalDateTimeZ(Date dateZoned)
      Convert Date to LocalDateTime UTC.
      Parameters:
      dateZoned - localized date
      Returns:
      truncatedTo(ChronoUnit.MILLIS)
    • isGzipAccepted

      public static boolean isGzipAccepted(jakarta.servlet.http.HttpServletRequest request)
      Test whether request accepts response gzip'ed compression.
      Parameters:
      request - http request
      Returns:
      test result
    • getGzipOutputstream

      public static OutputStream getGzipOutputstream(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, OutputStream out) throws IOException
      Wraps response output stream with GzipOutputstream, adds Content Encoding HTTP header.
      Parameters:
      request - HTTP request
      response - HTTP response
      out - HTTP response output stream
      Returns:
      wrapped output stream
      Throws:
      IOException - then exception
    • deUtf8

      public static String deUtf8(String value)
      Corrects when needed wrongly decoded UTF-8 strings.
      Parameters:
      value - input string
      Returns:
      correct string