Package ee.datel.dogis.utils
Class CommonUtils
java.lang.Object
ee.datel.dogis.utils.CommonUtils
Common methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringconcatenate(CharSequence... part) Concatenates strings.static LocalDateTimeconvertToLocalDateTimeZ(Date dateZoned) Convert Date to LocalDateTime UTC.static DateconvertToLocalizedDate(LocalDateTime utcTimestamp) Convert LocalDateTime to Localized Date.static <K,T> T copyFields(K source, T target) Copy values of fields with same name from one object to other, uses reflection.static StringCorrects when needed wrongly decoded UTF-8 strings.static voidDoes nothing.static ThrowableREtrieves the root cause from exception.static ExecutorServiceProvides singleton ForkJoinPoolstatic OutputStreamgetGzipOutputstream(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, OutputStream out) Wraps response output stream with GzipOutputstream, adds Content Encoding HTTP header.static intRandom integer provider.static longRandom long provider.static SecureRandomRandom provider, singleton.static org.springframework.scheduling.SchedulingTaskExecutorProvides singleton SchedulingTaskExecutorstatic ExecutorServiceProvides singleton Virtual Thread ExecutorServicestatic booleanisGzipAccepted(jakarta.servlet.http.HttpServletRequest request) Test whether request accepts response gzip'ed compression.static StringBuilderRetrieve a StringBuilder.static voidpush(StringBuilder sb) Stores buffer back into storage.static String[]Splits input string on separator char.
Trims result and removes empty elements.
-
Method Details
-
getForkJoinPool
Provides singleton ForkJoinPool- Returns:
- the executor
-
getTaskExecutor
public static org.springframework.scheduling.SchedulingTaskExecutor getTaskExecutor()Provides singleton SchedulingTaskExecutor- Returns:
- the executor
-
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- genericT- generic- Parameters:
source- values source objecttarget- target object- Returns:
- target object with values copied
-
doNothing
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
Random provider, singleton.- Returns:
- provider.
-
getExceptionCause
REtrieves the root cause from exception.- Parameters:
ex- exception- Returns:
- root cause
-
popBuffer
Retrieve a StringBuilder.- Returns:
- StringBuilder
-
push
Stores buffer back into storage.- Parameters:
sb- StringBuilder to store
-
concatenate
Concatenates strings.- Parameters:
part- values to concatenate- Returns:
- concatenated string
-
split
Splits input string on separator char.
Trims result and removes empty elements.- Parameters:
list- the sequence of characters to splitonChar- separator character- Returns:
- splitted
-
convertToLocalizedDate
Convert LocalDateTime to Localized Date.- Parameters:
utcTimestamp- UTC dateTime- Returns:
- truncatedTo(ChronoUnit.MILLIS)
-
convertToLocalDateTimeZ
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 requestresponse- HTTP responseout- HTTP response output stream- Returns:
- wrapped output stream
- Throws:
IOException- then exception
-
deUtf8
Corrects when needed wrongly decoded UTF-8 strings.- Parameters:
value- input string- Returns:
- correct string
-