public class Utils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.text.SimpleDateFormat |
RESULT_FILENAME_FRAGMENT_DATE_FORMAT
A simple date format with the pattern "yyyy-MM-dd@HH-mm-ss".
|
static java.text.SimpleDateFormat |
SIMPLE_DATE_FORMAT
A simple date format with the pattern "yyyy-MM-dd HH:mm:ss".
|
static java.text.SimpleDateFormat |
SIMPLE_DATE_FORMAT_WITH_MILLIS
A simple date format with the pattern "yyyy-MM-dd HH:mm:ss.SSS".
|
static java.text.SimpleDateFormat |
SOURCE_FILE_DATE_FORMAT
A simple date format with the pattern "dd MMM yyyy HH:mm:ss".
|
| Modifier and Type | Method and Description |
|---|---|
static int |
binaryIndex(byte[] src,
byte[] pattern)
Get the index of a binary pattern within binary data.
|
static int |
binaryIndex(byte[] data,
byte[] searchFragment,
int offset)
Search inside binary data for a fragment of data, starting at a specific offset.
|
static java.lang.String |
bytesToHex(byte[] bytes)
Convert a byte array to a hex string.
|
static int |
caseInsensitiveIndexOf(java.lang.String text,
java.lang.String search)
Perform a case-insensitive 'index of'.
|
static java.lang.String |
formatTimestamp(long timestamp)
Format an absolute date and time to a string.
|
static java.lang.String |
formatTimestamp(java.util.TimeZone timeZone,
long timestamp)
Format an absolute date and time to a string by using a specific time zone.
|
static java.lang.String |
formatTimestampInSourceFileFormat(long timestamp)
Format an absolute date and time to a string in 'source file date format'.
|
static java.lang.String |
formatTimestampInSourceFileFormat(java.util.TimeZone timeZone,
long timestamp)
Format an absolute date and time to a string in 'source file date format' by using a specific time zone.
|
static java.lang.String |
formatTimestampResultFileNameFragmentFormat(long timestamp)
Format an absolute date and time to a string in 'result file name fragment format'.
|
static java.lang.String |
formatTimestampResultFileNameFragmentFormat(java.util.TimeZone timeZone,
long timestamp)
Format an absolute date and time to a string in 'result file name fragment format' by using a specific time zone.
|
static java.lang.String |
formatTimestampWithMillis(long timestamp)
Format an absolute date and time to a string which includes also milliseconds.
|
static java.lang.String |
formatTimestampWithMillis(java.util.TimeZone timeZone,
long timestamp)
Format an absolute date and time to a string which includes also milliseconds by using a specific time zone.
|
static java.lang.String |
getCurrentTimeZoneAsString()
Get the current time zone and offset as string.
|
static java.util.TimeZone |
getDefaultTimeZone()
Get the default time zone.
|
static java.util.List<java.lang.String> |
getStackTraceLines(java.lang.Throwable throwable)
Get the lines of a stack trace.
|
static java.lang.String |
getStrippedFileName(java.io.File file)
Get from a file the file name without extension
|
static java.lang.String |
getThrowableMessage(java.lang.Throwable throwable,
java.lang.String defaultMessage)
Get the message of a throwable.
|
static byte[] |
gUnZip(byte[] b)
Decompress a byte array which was compressed by the GZIP algorithm.
|
static byte[] |
inflate(byte[] b)
Inflate a byte array which was compressed by the ZLIB algorithm.
|
static boolean |
is90HumanReadableASCII(byte[] bytes)
Get if the content of a byte[] array contains at least 90% human readable ASCII chars.
|
static boolean |
isFormalValidVariableName(java.lang.String variableName)
Verify if the name of a variable is formal valid.
|
static boolean |
isUTF8(byte[] pText,
boolean supportBinaryCut)
Get if the content of a byte[] array is in UTF-8 data format.
|
static void |
main(java.lang.String[] args)
Internal test program.
|
static boolean |
matchToWildcardString(java.lang.String checkString,
java.lang.String wildcardString)
Check if a text string mach to another text string which contains one ore more wildcard chars.
|
static java.util.List<byte[]> |
splitByteArray(byte[] b,
int chunkSize)
Split a byte array into a list of chunks.
|
static java.util.List<byte[]> |
splitByteArrayToFragments(byte[] b,
int numberOfFragments)
Split a byte array into a number of fragments.
|
static java.lang.String |
stripFileExtension(java.lang.String fileName)
Get from a file name with extension the file name without extension
|
public static final java.text.SimpleDateFormat SIMPLE_DATE_FORMAT
public static final java.text.SimpleDateFormat SIMPLE_DATE_FORMAT_WITH_MILLIS
public static final java.text.SimpleDateFormat SOURCE_FILE_DATE_FORMAT
public static final java.text.SimpleDateFormat RESULT_FILENAME_FRAGMENT_DATE_FORMAT
public static java.lang.String formatTimestamp(long timestamp)
timestamp - the absolute date and time (Unix time)SIMPLE_DATE_FORMATpublic static java.lang.String formatTimestamp(java.util.TimeZone timeZone,
long timestamp)
timeZone - the time zonetimestamp - the absolute date and time (Unix time)SIMPLE_DATE_FORMATpublic static java.lang.String formatTimestampWithMillis(long timestamp)
timestamp - the absolute date and time (Unix time)SIMPLE_DATE_FORMAT_WITH_MILLISpublic static java.lang.String formatTimestampWithMillis(java.util.TimeZone timeZone,
long timestamp)
timeZone - the time zonetimestamp - the absolute date and time (Unix time)SIMPLE_DATE_FORMAT_WITH_MILLISpublic static java.lang.String formatTimestampInSourceFileFormat(long timestamp)
timestamp - the absolute date and time (Unix time)SOURCE_FILE_DATE_FORMATpublic static java.lang.String formatTimestampInSourceFileFormat(java.util.TimeZone timeZone,
long timestamp)
timeZone - the time zonetimestamp - the absolute date and time (Unix time)SOURCE_FILE_DATE_FORMATpublic static java.lang.String formatTimestampResultFileNameFragmentFormat(long timestamp)
timestamp - the absolute date and time (Unix time)RESULT_FILENAME_FRAGMENT_DATE_FORMATpublic static java.lang.String formatTimestampResultFileNameFragmentFormat(java.util.TimeZone timeZone,
long timestamp)
timeZone - the time zonetimestamp - the absolute date and time (Unix time)RESULT_FILENAME_FRAGMENT_DATE_FORMATpublic static java.util.TimeZone getDefaultTimeZone()
public static java.lang.String getCurrentTimeZoneAsString()
public static java.util.List<java.lang.String> getStackTraceLines(java.lang.Throwable throwable)
throwable - the throwablepublic static java.lang.String getThrowableMessage(java.lang.Throwable throwable,
java.lang.String defaultMessage)
throwable - the throwabledefaultMessage - the returned message if the throwable has no messagepublic static boolean matchToWildcardString(java.lang.String checkString,
java.lang.String wildcardString)
checkString - the string to checkwildcardString - the matching string which can contain wildcards '?' and/or '*'public static byte[] gUnZip(byte[] b)
throws java.io.IOException
b - the byte array to decompressjava.io.IOException - if the decompression failspublic static byte[] inflate(byte[] b)
throws java.io.IOException
b - the byte array to inflatejava.io.IOException - if the inflation failspublic static int caseInsensitiveIndexOf(java.lang.String text,
java.lang.String search)
text - the textsearch - the search fragmentpublic static int binaryIndex(byte[] src,
byte[] pattern)
src - the binary datapattern - the binary patternpublic static int binaryIndex(byte[] data,
byte[] searchFragment,
int offset)
data - the binary datasearchFragment - the fragment to searchoffset - the offset where the search starts inside the binary data (0..n-1)public static boolean is90HumanReadableASCII(byte[] bytes)
bytes - the array of bytespublic static boolean isUTF8(byte[] pText,
boolean supportBinaryCut)
pText - the byte[] array to checksupportBinaryCut - if true, don't check the last 4 bytes of the byte[] array, in order that also binary cuts of UTF-8 data fragments are supportedSee https://stackoverflow.com/questions/28890907/implement-a-function-to-check-if-a-string-byte-array-follows-utf-8-format?lq=1
public static java.util.List<byte[]> splitByteArray(byte[] b,
int chunkSize)
b - the byte array to splitchunkSize - the maximum size of a chunk in bytespublic static java.util.List<byte[]> splitByteArrayToFragments(byte[] b,
int numberOfFragments)
b - the byte array to splitnumberOfFragments - the number of fragmentspublic static boolean isFormalValidVariableName(java.lang.String variableName)
variableName - the name of the variablepublic static java.lang.String stripFileExtension(java.lang.String fileName)
fileName - the file name with extensionpublic static java.lang.String getStrippedFileName(java.io.File file)
file - the filepublic static java.lang.String bytesToHex(byte[] bytes)
bytes - the byte array to convertpublic static void main(java.lang.String[] args)
args - {no args}