public class ParseUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static float |
byteArrayToFloat(byte[] bytes,
int size,
int fpBits)
Convert a byte array to its floating point representation.
|
static long |
byteArrayToLong(byte[] bytes,
int size)
Convert a byte array to its integer representation.
|
static long |
cimDateTimeToMillis(String cimDate)
Parses a CIM_DateTime format (from WMI) to milliseconds since the epoch.
|
static int |
getFirstIntValue(String line)
Parses a string such as "10.12.2" or "key = 1 (0x1) (int)" to find the
integer value of the first set of one or more consecutive digits
|
static int |
getNthIntValue(String line,
int n)
Parses a string such as "10.12.2" or "key = 1 (0x1) (int)" to find the
integer value of the nth set of one or more consecutive digits
|
static String |
getSingleQuoteStringValue(String line)
Parses a string key = 'value' (string)
|
static byte[] |
hexStringToByteArray(String digits)
Parse a string of hexadecimal digits into a byte array
|
static String |
hexStringToString(String hexString)
Parses a string of hex digits to a string where each pair of hex digits
represents an ASCII character
|
static byte[] |
longToByteArray(long value,
int valueSize,
int length)
Convert a long value to a byte array using Big Endian, truncating or
padding with zeros (if necessary) so the array has the specified length.
|
static long |
parseDHMSOrDefault(String s,
long defaultLong)
Attempts to parse a string of the form [DD-[hh:]]mm:ss[.ddd] to a number
of milliseconds.
|
static double |
parseDoubleOrDefault(String s,
double defaultDouble)
Attempts to parse a string to a double.
|
static long |
parseHertz(String hertz)
Parse hertz from a string, eg.
|
static int |
parseIntOrDefault(String s,
int defaultInt)
Attempts to parse a string to an int.
|
static int |
parseLastInt(String s,
int i)
Parse the last element of a space-delimited string to a value
|
static String |
parseLastString(String s)
Parse the last element of a space-delimited string to a string
|
static long |
parseLongOrDefault(String s,
long defaultLong)
Attempts to parse a string to a long.
|
static String |
parseUuidOrDefault(String s,
String defaultStr)
Attempts to parse a UUID.
|
static byte[] |
stringToByteArray(String text,
int length)
Parse a human readable string into a byte array, truncating or padding
with zeros (if necessary) so the array has the specified length.
|
static long |
strToLong(String str,
int size)
Convert a string to an integer representation.
|
public static long parseHertz(String hertz)
hertz - Hertz size.Long Hertz value or -1 if not parsable.public static int parseLastInt(String s, int i)
s - The string to parsei - Default integer if not parsablepublic static String parseLastString(String s)
s - The string to parsepublic static byte[] hexStringToByteArray(String digits)
digits - The string to be parsedpublic static byte[] stringToByteArray(String text, int length)
text - The string to be parsedlength - Length of the returned array.public static byte[] longToByteArray(long value,
int valueSize,
int length)
value - The value to be convertedvalueSize - Number of bytes representing the valuelength - Number of bytes to returnpublic static long strToLong(String str, int size)
str - A human readable stringsize - Number of characters to convert to the long. May not exceed 8.public static long byteArrayToLong(byte[] bytes,
int size)
bytes - An array of bytes no smaller than the size to be convertedsize - Number of bytes to convert to the long. May not exceed 8.public static float byteArrayToFloat(byte[] bytes,
int size,
int fpBits)
bytes - An array of bytes no smaller than the size to be convertedsize - Number of bytes to convert to the float. May not exceed 8.fpBits - Number of bits representing the decimalpublic static long cimDateTimeToMillis(String cimDate)
cimDate - A string containing the CIM_DateTimepublic static String hexStringToString(String hexString)
hexString - A sequence of hex digitspublic static int parseIntOrDefault(String s, int defaultInt)
s - The string to parsedefaultInt - The value to return if parsing failspublic static long parseLongOrDefault(String s, long defaultLong)
s - The string to parsedefaultLong - The value to return if parsing failspublic static double parseDoubleOrDefault(String s, double defaultDouble)
s - The string to parsedefaultDouble - The value to return if parsing failspublic static long parseDHMSOrDefault(String s, long defaultLong)
s - The string to parsedefaultLong - The value to return if parsing failspublic static String parseUuidOrDefault(String s, String defaultStr)
s - The string to parsedefaultStr - The value to return if parsing failspublic static String getSingleQuoteStringValue(String line)
line - The entire stringpublic static int getFirstIntValue(String line)
line - The entire stringpublic static int getNthIntValue(String line, int n)
line - The entire stringn - Which set of integers to returnCopyright © 2010–2017 oshi. All rights reserved.