public final class DOFUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static byte[] |
asciiStringToBytes(java.lang.String value)
Convert a String to an ascii byte array.
|
static java.lang.String |
bytesToAsciiString(byte[] data)
Convert an ascii byte array to a String.
|
static java.lang.String |
bytesToAsciiString(byte[] data,
int offset,
int length)
Convert an ascii byte array to a String.
|
static java.lang.String |
bytesToHexString(byte[] data)
Convert a byte array of data to its hexadecimal String representation.
|
static java.lang.String |
bytesToHexString(byte[] data,
int offset,
int length)
Convert a byte array of data to its hexadecimal String representation.
|
static DOFObjectID.Source |
createAsAssignedOID(int nodeId,
byte asID,
short sequence,
long timeStamp)
Create an AS assigned identifier from its specified parts.
|
static byte[] |
createGuid()
Create a type 4 (pseudo randomly generated) UUID as an array of 16 bytes.
|
static int |
extractNodeID(DOFObjectID sourceID)
Extract the node identifier from an AS generated source identifier.
|
static boolean |
getBoolParam(java.util.Map<java.lang.String,java.lang.String> paramMap,
java.lang.String key,
boolean defaultValue)
Get a boolean value from a parameter map.
|
static java.lang.String |
getErrorMessage(java.lang.Exception exception)
Convenience method to create more readable exception messages.
|
static int |
getIntParam(java.util.Map<java.lang.String,java.lang.String> paramMap,
java.lang.String key,
int defaultValue)
Get an integer value from a parameter map.
|
static long |
getLongParam(java.util.Map<java.lang.String,java.lang.String> paramMap,
java.lang.String key,
long defaultValue)
Get a long value from a parameter map.
|
static byte[] |
getRandomBytes(int length)
Get a secure, random byte array of the specified length.
|
static int |
getRandomInt(int range)
Get a secure, random integer within the specified range.
|
static java.lang.String |
getStringParam(java.util.Map<java.lang.String,java.lang.String> paramMap,
java.lang.String key,
java.lang.String defaultValue)
Get a string value from a parameter map.
|
static byte[] |
hexStringToBytes(java.lang.String value)
Convert a hexadecimal String to a byte array.
|
static boolean |
isValidAsciiString(java.lang.String value)
Whether the string is a valid ascii string.
|
static boolean |
isValidHexString(java.lang.String value)
Is the String a valid hex String? Does it contain an even amount of only hex-characters.
|
public static java.lang.String bytesToHexString(byte[] data)
data
- The data to convert. Cannot be null.public static java.lang.String bytesToHexString(byte[] data, int offset, int length)
data
- The data to convert. Cannot be null.offset
- The offset into the array where the conversion should start.length
- The number of bytes to convert to hexadecimal format. The length cannot be
greater than data.length - offset.public static byte[] hexStringToBytes(java.lang.String value)
value
- The hexadecimal String to convert. Cannot be null and must only contain hex-characters.public static boolean isValidHexString(java.lang.String value)
value
- The hex String to check if valid. Cannot be null.public static java.lang.String bytesToAsciiString(byte[] data)
data
- The data to convert. Cannot be null.public static java.lang.String bytesToAsciiString(byte[] data, int offset, int length)
data
- The data to convert. Cannot be null.offset
- The offset into the array where the conversion should start.length
- The number of bytes to convert.public static byte[] asciiStringToBytes(java.lang.String value)
value
- The String to convert. Cannot be null and must only contain valid ascii in the range 32-126.public static boolean isValidAsciiString(java.lang.String value)
value
- The string to check if valid. Must not be null.public static byte[] createGuid()
public static byte[] getRandomBytes(int length)
length
- The desired length of the array to be returned.public static int getRandomInt(int range)
range
- The desired range, within which to pick a random number.public static boolean getBoolParam(java.util.Map<java.lang.String,java.lang.String> paramMap, java.lang.String key, boolean defaultValue)
paramMap
- The parameter map.key
- The key for the value.defaultValue
- The default value to use if the parameter does not exist or could not be created.public static int getIntParam(java.util.Map<java.lang.String,java.lang.String> paramMap, java.lang.String key, int defaultValue)
paramMap
- The parameter map.key
- The key for the value.defaultValue
- The default value to use if the parameter does not exist or could not be created.public static long getLongParam(java.util.Map<java.lang.String,java.lang.String> paramMap, java.lang.String key, long defaultValue)
paramMap
- The parameter map.key
- The key for the value.defaultValue
- The default value to use if the parameter does not exist or could not be created.public static java.lang.String getStringParam(java.util.Map<java.lang.String,java.lang.String> paramMap, java.lang.String key, java.lang.String defaultValue)
paramMap
- The parameter map.key
- The key for the value.defaultValue
- The default value to use if the parameter does not exist.public static java.lang.String getErrorMessage(java.lang.Exception exception)
exception
- The exception to get the message for.public static DOFObjectID.Source createAsAssignedOID(int nodeId, byte asID, short sequence, long timeStamp)
nodeId
- The AS assigned node source identifier.asID
- The identifier assigned to the AS. Must be >=0 and <= 0x3F(63)sequence
- The sequence of the identifier for the current time stamp. Must be >=0 and <= 0x3FF(1023).timeStamp
- The time stamp for the identifier. Seconds since January 1970. Must be >= 0.public static int extractNodeID(DOFObjectID sourceID)
sourceID
- The AS assigned source identifier. Must not be null. Must be a valid AS assigned identifier DOFObjectID.CLASS_AS
.