Klasse K
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final double
Exabyte valuestatic final double
Gigabyte valuestatic final double
Kilobyte valuestatic final double
Megabyte valuestatic final double
Petabyte valuestatic final double
Ronnabyte valuestatic final double
Terabyte valuestatic final double
Yottabyte valuestatic final double
Zetabyte valuestatic final String
Package version -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic byte[]
compressZLIB
(byte[] argBuffer) Compress the passed data using the ZLIB algorithm.static byte[]
decodeBase64
(String argBuffer) Return decoded Base64 string.static String
Return decoded CSV string with the delimiter ','static String
Return decoded CSV stringstatic String
decodeJSON
(String argBuffer) Return decoded JSON stringstatic String
Return decoded UTF-8 string.static String
Return decoded XML Stringstatic String
decodeYAML
(String argBuffer) Return decoded YAML stringstatic byte[]
decompressZLIB
(byte[] argBuffer) Decompress the passed data using the ZLIB algorithm.static byte[]
decryptAES256
(byte[] argBuffer, byte[] argSecretKey, byte[] argInitVector) Return decrypted AES-256 buffer (AES/CBC/PKCS5Padding).static Object
deserialize
(String argString) Return base64 decoded and deserialized object.static String
encodeBase64
(byte[] argBuffer) Return encoded buffer to Base64 stringstatic String
Return encoded string for CSV with the delimiter ','static String
Return encoded string for CSVstatic String
encodeJSON
(String argBuffer) Return encoded string for JSON.static String
encodeJSON
(String argBuffer, boolean argEnforceQuotes) Return encoded string for JSON.static String
Return encoded string in UTF-8static String
Encode string for XMLstatic String
encodeYAML
(String argBuffer) Return encoded string for YAML.static String
encodeYAML
(String argBuffer, boolean argEnforceQuotes) Return encoded string for YAML.static byte[]
encryptAES256
(byte[] argBuffer, byte[] argSecretKey, byte[] argInitVector) Return encrypted AES-256 buffer (AES/CBC/PKCS5Padding).static String
formatBytes
(double argSizeInBytes) Convert number of bytes to formatted string (Example: 212 B, 21.23 KB, 3.00 MB).static byte[]
generateHash
(String argHashType, byte[] argBuffer) Return compute Hash (MD5, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-384 or SHA3-512)static String
Return current directory.static String
getIPAddress
(String argHostname) Return IP address of hostnamestatic int
Return number of processors for the JVM.static long[]
Return JVM memory statistics.static String
Return JVM name (Example "OpenJDK 64-Bit Server VM - Eclipse Adoptium").static String
Return JVM platform (Example: "Mac OS X (Version 14.5/aarch64)").static int
Return JVM major version (Example: 1.9.x as 9, 12.4 as 12).static String
Get line separatorstatic String
Return local TCP/IP address.static String
Return local TCP/IP host namestatic byte[]
getRandomBytes
(int argLength) Return random bytes generated by the SecureRandom class.static int
getRandomInt
(int argMinInt, int argMaxInt) Return random integer between the given range.static Calendar
Get application start time and date.static String
Return current date and time in ISO 8601 format (Example: "2024-02-24T14:12:44.234").static String
getTimeISO8601
(Calendar argDateTime) Return date and time in ISO 8601 format (Example: "2024-02-24T14:12:44.234").static String
Return unique id (Example: f512defd-b09a-402b-8066-21a2967e61f).static String
Return offset from local time zone to UTC as string (Example +02:00).static int
Return difference in number of minutes between UTC and the local time zone.static boolean
Check if object is empty.static boolean
Check whether the passed string contains an integer.static boolean
Check whether the passed string contains an integer and is within the allowed range.static boolean
Check whether the passed string contains a number.static boolean
Check whether the passed string contains a number and is within the allowed range.static Class
<?> Dynamic load a Java classstatic String[]
Return DNS records for the specified record type.static double
round
(double argValue, int argPrecision) Return rounded value.static double
roundSwiss
(double argValue) Return rounded value according to the "Swiss Rounding Rule 5+".static long
runGC()
Manually run garbage collector of Java virtual machine.static String
serialize
(Serializable argObject) Return base64 encoded and serialized object.static boolean
stopThread
(Thread argThread) Signal interrupt to thread.static boolean
stopThread
(Thread argThread, int argTimeOutSec) Signal interrupt to thread and wait for its termination.static String
toHex
(byte[] argBytes) Format byte array as hexadecimal string.static String
Format string as hexadecimal string representation.toString()
String representation of object.static void
waitHours
(int argHours) Waits the specified time.static void
waitMilliseconds
(int argMilliseconds) Waits the specified time.static void
waitMinutes
(int argMinutes) Waits the specified time.static void
waitSeconds
(int argSeconds) Waits the specified time.
-
Felddetails
-
VERSION
Package version- Siehe auch:
-
SIZE_KB
public static final double SIZE_KBKilobyte value- Siehe auch:
-
SIZE_MB
public static final double SIZE_MBMegabyte value- Siehe auch:
-
SIZE_GB
public static final double SIZE_GBGigabyte value- Siehe auch:
-
SIZE_TB
public static final double SIZE_TBTerabyte value- Siehe auch:
-
SIZE_PB
public static final double SIZE_PBPetabyte value- Siehe auch:
-
SIZE_EB
public static final double SIZE_EBExabyte value- Siehe auch:
-
SIZE_ZB
public static final double SIZE_ZBZetabyte value- Siehe auch:
-
SIZE_YB
public static final double SIZE_YBYottabyte value- Siehe auch:
-
SIZE_RB
public static final double SIZE_RBRonnabyte value- Siehe auch:
-
-
Methodendetails
-
compressZLIB
public static byte[] compressZLIB(byte[] argBuffer) Compress the passed data using the ZLIB algorithm.- Parameter:
argBuffer
- Data to be compressed- Gibt zurück:
- Compressed data
- Seit:
- 2024.08.11
-
decodeBase64
Return decoded Base64 string.- Parameter:
argBuffer
- Base64 string to decode- Gibt zurück:
- byte[] Decoded argBuffer or null
-
decodeCSV
Return decoded CSV string with the delimiter ','- Parameter:
argBuffer
- String to be decoded- Gibt zurück:
- String Decoded string or null
- Seit:
- 2024.06.15
-
decodeCSV
Return decoded CSV string- Parameter:
argBuffer
- String to be decodedargDelimiter
- Delimiter character (Example: ',')- Gibt zurück:
- String Decoded string
- Seit:
- 2024.06.15
-
decodeJSON
Return decoded JSON string- Parameter:
argBuffer
- String to be decoded- Gibt zurück:
- String Decoded string or null
- Seit:
- 2024.06.15
-
decodeURL
Return decoded UTF-8 string.- Parameter:
argBuffer
- is the String to be decoded- Gibt zurück:
- String Decoded string or null
-
decodeXML
Return decoded XML String- Parameter:
argBuffer
- String to be decoded- Gibt zurück:
- String Decoded string
- Seit:
- 2024.06.16
-
decodeYAML
Return decoded YAML string- Parameter:
argBuffer
- String to be decoded- Gibt zurück:
- String Decoded string or null
- Seit:
- 2024.09.14
-
decompressZLIB
public static byte[] decompressZLIB(byte[] argBuffer) Decompress the passed data using the ZLIB algorithm.- Parameter:
argBuffer
- Data to be decompressed- Gibt zurück:
- Decompressed data or null for errors
- Seit:
- 2024.08.11
-
decryptAES256
public static byte[] decryptAES256(byte[] argBuffer, byte[] argSecretKey, byte[] argInitVector) Return decrypted AES-256 buffer (AES/CBC/PKCS5Padding).Note: Before being used as the decryption key, the passed secret key is hashed with SHA-256 to always create a 256 bit key.
Example: byte[] clearText = "Some datq to be encrypted".getBytes(); byte[] secureKey = "SomeSecureKey".getBytes(); byte[] iv = K.getRandomBytes(16); byte[] encrBuffer = K.encryptAES256(clearText, secureKey, iv); byte[] decrBuffer = K.decryptAES256(encrBuffer, secureKey, iv);
- Parameter:
argBuffer
- Encrypted bufferargSecretKey
- Secret key for decryptionargInitVector
- Initialization vector (16 bytes)- Gibt zurück:
- byte[] Decrypted buffer or null
-
deserialize
Return base64 decoded and deserialized object.- Parameter:
argString
- Object to decode and deserialize- Gibt zurück:
- Object
- Seit:
- 2024.08.22
-
encodeBase64
Return encoded buffer to Base64 string- Parameter:
argBuffer
- Buffer to convert- Gibt zurück:
- String Base64 encoded string or null
-
encodeCSV
Return encoded string for CSV with the delimiter ','- Parameter:
argBuffer
- String to be encoded- Gibt zurück:
- String Encoded string or null
- Seit:
- 2024.06.15
-
encodeCSV
Return encoded string for CSV- Parameter:
argBuffer
- String to be encodedargDelimiter
- Delimiter character (Example: ',')- Gibt zurück:
- String Encoded string
- Seit:
- 2024.06.15
-
encodeJSON
Return encoded string for JSON. The returned string is always enclosed in double quotes.- Parameter:
argBuffer
- String to be encoded- Gibt zurück:
- String Encoded string
- Seit:
- 2024.06.15
- Siehe auch:
-
encodeJSON
Return encoded string for JSON.- Parameter:
argBuffer
- String to be encodedargEnforceQuotes
- Flag to enforce surrounding quotes (required for JSON keys, optional for JSON boolean/numeric values)- Gibt zurück:
- String Encoded string
- Seit:
- 2024.06.28
-
encodeURL
Return encoded string in UTF-8- Parameter:
argBuffer
- is the String to be encoded- Gibt zurück:
- String Encoded string or null
-
encodeXML
Encode string for XML- Parameter:
argBuffer
- String to be encoded- Gibt zurück:
- String Encoded string
- Seit:
- 2024.06.16
-
encodeYAML
Return encoded string for YAML. The returned string is always enclosed in double quotes.- Parameter:
argBuffer
- String to be encoded- Gibt zurück:
- String Encoded string
- Seit:
- 2024.09.14
- Siehe auch:
-
encodeYAML
Return encoded string for YAML. Note: Strings are always enclosed with double quotes.- Parameter:
argBuffer
- String to be encodedargEnforceQuotes
- Flag to enforce surrounding quotes (optional for YAML values)- Gibt zurück:
- String Encoded string
- Seit:
- 2024.09.14
-
encryptAES256
public static byte[] encryptAES256(byte[] argBuffer, byte[] argSecretKey, byte[] argInitVector) Return encrypted AES-256 buffer (AES/CBC/PKCS5Padding).Note: Before being used as the encryption key, the passed secret key is hashed with SHA-256 to always create a 256 bit key.
Example: byte[] clearText = "Some data to be encrypted".getBytes(); byte[] secureKey = "SomeSecureKey".getBytes(); byte[] iv = K.getRandomBytes(16); byte[] encrBuffer = K.encryptAES256(clearText, secureKey, iv); byte[] decrBuffer = K.decryptAES256(encrBuffer, secureKey, iv);
- Parameter:
argBuffer
- Clear text bufferargSecretKey
- Secret key for encryptionargInitVector
- Initialization vector (16 bytes)- Gibt zurück:
- byte[] Encrypted buffer or null
-
formatBytes
Convert number of bytes to formatted string (Example: 212 B, 21.23 KB, 3.00 MB).- Parameter:
argSizeInBytes
- Number of bytes to be formatted- Gibt zurück:
- String with formatted size (Example 12.03 GB)
- Seit:
- 2024.06.23
-
generateHash
Return compute Hash (MD5, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-384 or SHA3-512)- Parameter:
argHashType
- Hash algorithmargBuffer
- argBuffer to hash- Gibt zurück:
- byte[] Hashed data or null
-
getCurrentDir
Return current directory.- Gibt zurück:
- Current directory, e.g. "/Users/johnsmith"
- Seit:
- 2024.05.24
-
getIPAddress
Return IP address of hostname- Parameter:
argHostname
- Hostname- Gibt zurück:
- String IP address or null
-
getJVMCPUCount
public static int getJVMCPUCount()Return number of processors for the JVM.- Gibt zurück:
- int Number of processors
-
getJVMMemStats
public static long[] getJVMMemStats()Return JVM memory statistics.Note: The returned array has the following values:
[0] = Maximum heap size in bytes
[1] = Current heap size in bytes
[2] = Used heap size in bytes
[3] = Free heap size in bytes- Gibt zurück:
- JVM memory statistics
-
getJVMName
Return JVM name (Example "OpenJDK 64-Bit Server VM - Eclipse Adoptium").- Gibt zurück:
- String JVM version number and vendor
-
getJVMPlatform
Return JVM platform (Example: "Mac OS X (Version 14.5/aarch64)").- Gibt zurück:
- String JVM platform
-
getJVMVersion
public static int getJVMVersion()Return JVM major version (Example: 1.9.x as 9, 12.4 as 12).- Gibt zurück:
- int Major version number of JVM runtime or 0 for errors
-
getLineSeparator
Get line separator- Gibt zurück:
- String Platform dependent line separator (\r, \n or \r\n)
-
getLocalHostAddress
Return local TCP/IP address.- Gibt zurück:
- String IP address or null
-
getLocalHostName
Return local TCP/IP host name- Gibt zurück:
- String Host name or null
-
getRandomBytes
public static byte[] getRandomBytes(int argLength) Return random bytes generated by the SecureRandom class.- Parameter:
argLength
- Number of bytes to be generated- Gibt zurück:
- byte[] Generated bytes
-
getRandomInt
public static int getRandomInt(int argMinInt, int argMaxInt) Return random integer between the given range.- Parameter:
argMinInt
- Lowest possible integer (inclusive)argMaxInt
- Highest possible integer (exclusive)- Gibt zurück:
- Random integer
- Seit:
- 2024.05.29
-
getStartTime
Get application start time and date.- Gibt zurück:
- Start date and time
- Seit:
- 2024.05.24
-
getTimeISO8601
Return current date and time in ISO 8601 format (Example: "2024-02-24T14:12:44.234").- Gibt zurück:
- String ISO 8601 date/time
-
getTimeISO8601
Return date and time in ISO 8601 format (Example: "2024-02-24T14:12:44.234").- Parameter:
argDateTime
- Date/time- Gibt zurück:
- String ISO 8601 date/time
-
getUniqueID
Return unique id (Example: f512defd-b09a-402b-8066-21a2967e61f).- Gibt zurück:
- Unique id
- Seit:
- 2024.05.24
-
getUTCOffsetAsString
Return offset from local time zone to UTC as string (Example +02:00).- Gibt zurück:
- String with zone offset
-
getUTCOffsetMin
public static int getUTCOffsetMin()Return difference in number of minutes between UTC and the local time zone.- Gibt zurück:
- Difference in minutes
-
isEmpty
Check if object is empty.- Parameter:
argObject
- Object to test for emptiness- Gibt zurück:
- True if object is empty (null or no elements), false otherwise
- Seit:
- 2024.05.20
-
isInteger
Check whether the passed string contains an integer.- Parameter:
argString
- String to be tested- Gibt zurück:
- True if number, false otherwise
- Seit:
- 2024.08.26
-
isInteger
Check whether the passed string contains an integer and is within the allowed range.- Parameter:
argString
- String to be testedargMinimum
- Minimum allowed valueargMaximum
- Maximum allowed value- Gibt zurück:
- True if number, false otherwise
- Seit:
- 2024.08.26
-
isNumber
Check whether the passed string contains a number.- Parameter:
argString
- String to be tested- Gibt zurück:
- True if number, false otherwise
- Seit:
- 2024.06.28
-
isNumber
Check whether the passed string contains a number and is within the allowed range.- Parameter:
argString
- String to be testedargMinimum
- Minimum allowed valueargMaximum
- Maximum allowed value- Gibt zurück:
- True if number, false otherwise
- Seit:
- 2024.09.12
-
loadClass
Dynamic load a Java class- Parameter:
argClassName
- Java class name, e.g ch.k43.util.KSocketServerSample- Gibt zurück:
- Class Loaded Java class or null for errors
-
queryDNS
Return DNS records for the specified record type.- Parameter:
argDNSRecordType
- DNS record type (MX, A, etc.)argMailDomain
- Domain to query- Gibt zurück:
- Array with matching DNS records or null
- Seit:
- 2024.05.17
-
round
public static double round(double argValue, int argPrecision) Return rounded value.- Parameter:
argValue
- Value to be roundedargPrecision
- Number of decimal digits- Gibt zurück:
- double Rounded value
- Seit:
- 2025.08.10
-
roundSwiss
public static double roundSwiss(double argValue) Return rounded value according to the "Swiss Rounding Rule 5+".Note: The calculation is equivalent to Math.round(value * 20.0) / 20.0 and is mainly used by Swiss financial applications.
Examples:
- Values between 0.0000 and 0.0249 are rounded down to 0.00
- Values between 0.0250 and 0.0749 are rounded to 0.05
- Values between 0.0750 and 0.0999 are rounded up to 0.10- Parameter:
argValue
- Value to be rounded- Gibt zurück:
- double Rounded value
-
runGC
public static long runGC()Manually run garbage collector of Java virtual machine. Note: The manual execution of the garbage collector is not needed under normal operation.- Gibt zurück:
- Number of bytes reclaimed
-
serialize
Return base64 encoded and serialized object.- Parameter:
argObject
- Object to serialize and encode- Gibt zurück:
- Base64 string
- Seit:
- 2024.08.22
-
stopThread
Signal interrupt to thread.- Parameter:
argThread
- Thread to interrupt for termination- Gibt zurück:
- True for success, false otherwise
- Seit:
- 2024.08.29
-
stopThread
Signal interrupt to thread and wait for its termination.- Parameter:
argThread
- Thread to terminateargTimeOutSec
- Number of seconds to wait for thread termination (0 to 60)- Gibt zurück:
- True for success, false otherwise
- Seit:
- 2024.08.29
-
toHex
Format byte array as hexadecimal string.- Parameter:
argBytes
- Byte array- Gibt zurück:
- Hexadecimal string
- Seit:
- 2024.05.24
-
toHex
Format string as hexadecimal string representation.- Parameter:
argString
- String to be formatted- Gibt zurück:
- Hexadecimal string
- Seit:
- 2024.05.24
-
waitHours
public static void waitHours(int argHours) Waits the specified time.- Parameter:
argHours
- Number of hours to wait
-
waitMilliseconds
public static void waitMilliseconds(int argMilliseconds) Waits the specified time.- Parameter:
argMilliseconds
- Number of milliseconds to wait
-
waitMinutes
public static void waitMinutes(int argMinutes) Waits the specified time.- Parameter:
argMinutes
- Number of minutes to wait
-
waitSeconds
public static void waitSeconds(int argSeconds) Waits the specified time.- Parameter:
argSeconds
- Number of seconds to wait
-
toString
String representation of object.
-