public class Builder extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
HEX_ERROR
Constant
HEX_ERROR="0x%08X" |
static Pattern |
notDigits
Constant
notDigits |
static Pattern |
startWithNotDigits
Constant
startWithNotDigits |
static String |
SYSFS_SERIAL_PATH
The official/approved path for sysfs information.
|
static OffsetDateTime |
UNIX_EPOCH
The Unix Epoch, a default value when WMI DateTime queries return no value.
|
static String |
UNKNOWN
String to report for unknown information
|
static Pattern |
whitespaces
Constant
whitespaces |
static Pattern |
whitespacesColonWhitespace
Constant
whitespacesColonWhitespace |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
asciiStringToByteArray(String text,
int length)
Parse a human readable ASCII string into a byte array, truncating or padding
with zeros (if necessary) so the array has the specified length.
|
static float |
byteArrayToFloat(byte[] bytes,
int size,
int fpBits)
Convert a byte array to its floating point representation.
|
static String |
byteArrayToHexString(byte[] bytes)
Parse a byte aray into a string of hexadecimal digits including leading zeros
|
static long |
byteArrayToLong(byte[] bytes,
int size)
Convert a byte array to its integer representation.
|
static int |
countStringToLongArray(String s,
char delimiter)
Parses a delimited string to count elements of an array of longs.
|
static long |
filetimeToUtcMs(long filetime,
boolean local)
Convert a long representing filetime (100-ns since 1601 epoch) to ms since
1970 epoch
|
static String |
formatBytes(long bytes)
Format bytes into a rounded string representation using IEC standard (matches
Mac/Linux).
|
static String |
formatBytesDecimal(long bytes)
Format bytes into a rounded string representation using decimal SI units.
|
static String |
formatElapsedSecs(long secs)
Formats an elapsed time in seconds as days, hh:mm:ss.
|
static String |
formatError(int errorCode)
Translate an integer error code to its hex notation
|
static String |
formatHertz(long hertz)
Format hertz into a string to a rounded string representation.
|
static String |
formatValue(long value,
String unit)
Format arbitrary units into a string to a rounded string representation.
|
static Map<Integer,String> |
getCwdMap(int pid)
getCwdMap.
|
static String |
getDescriptorRangeLimits(byte[] desc)
Parse descriptor range limits
|
static byte[][] |
getDescriptors(byte[] edid)
Get the VESA descriptors
|
static String |
getDescriptorText(byte[] desc)
Parse descriptor text
|
static int |
getDescriptorType(byte[] desc)
Get the VESA descriptor type
|
static String |
getDoubleQuoteStringValue(String line)
Parse a string key = "value" (string)
|
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 |
getHcm(byte[] edid)
Get monitor width in cm
|
static int |
getIntFromFile(String filename)
Read a file and return the int value contained therein.
|
static Map<String,String> |
getKeyValueMapFromFile(String filename,
String separator)
Read a file and return a map of string keys to string values contained
therein.
|
static long |
getLongFromFile(String filename)
Read a file and return the long value contained therein.
|
static String |
getManufacturerID(byte[] edid)
Gets the Manufacturer ID from (up to) 3 5-bit characters in bytes 8 and 9
|
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 |
getProductID(byte[] edid)
Gets the Product ID, bytes 10 and 11
|
static String |
getSerialNo(byte[] edid)
Gets the Serial number, bytes 12-15
|
static String |
getSingleQuoteStringValue(String line)
Parses a string key = 'value' (string)
|
static String |
getStringBetween(String line,
char c)
Gets a value between two characters having multiple same characters between
them.
|
static String |
getStringFromFile(String filename)
Read a file and return the String value contained therein.
|
static String |
getTextBetweenStrings(String text,
String before,
String after)
Get a String in a line of text between two marker strings
|
static String |
getTimingDescriptor(byte[] desc)
Parse a detailed timing descriptor
|
static long |
getUnsignedInt(int x)
Convert unsigned int to signed long.
|
static long |
getUnsignedLongFromFile(String filename)
Read a file and return the unsigned long value contained therein as a long.
|
static int |
getVcm(byte[] edid)
Get monitor height in cm
|
static String |
getVersion(byte[] edid)
Return the EDID version
|
static byte |
getWeek(byte[] edid)
Return the week of year of manufacture
|
static int |
getYear(byte[] edid)
Return the year of manufacture
|
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 boolean |
isDigital(byte[] edid)
Test if this EDID is a digital monitor based on byte 20
|
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 OffsetDateTime |
parseCimDateTimeToOffset(String cimDateTime)
Converts a string in CIM Date Format, as returned by WMI for DateTime types,
into a
OffsetDateTime. |
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 double |
parseLastDouble(String s,
double d)
Parse the last element of a space-delimited string to a value
|
static int |
parseLastInt(String s,
int i)
Parse the last element of a space-delimited string to a value
|
static long |
parseLastLong(String s,
long li)
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 |
parseMmDdYyyyToYyyyMmDD(String dateString)
Parse a date in MM-DD-YYYY or MM/DD/YYYY to YYYY-MM-DD
|
static long[] |
parseStringToLongArray(String s,
int[] indices,
int length,
char delimiter)
Parses a delimited string to an array of longs.
|
static long |
parseUnsignedLongOrDefault(String s,
long defaultLong)
Attempts to parse a string to an "unsigned" long.
|
static String |
parseUuidOrDefault(String s,
String defaultStr)
Attempts to parse a UUID.
|
static List<String> |
readFile(String filename)
Read an entire file at one time.
|
static List<String> |
readFile(String filename,
boolean reportError)
Read an entire file at one time.
|
static String |
removeMatchingString(String original,
String toRemove)
Removes all matching sub strings from the string.
|
static float |
round(float d,
int decimalPlace)
Round to certain number of decimals.
|
static void |
sleep(long ms)
Sleeps for the specified number of milliseconds.
|
static long |
strToLong(String str,
int size)
Convert a string to an integer representation.
|
static String |
toString(byte[] edid)
Parse an EDID byte array into user-readable information
|
static String |
toUnsignedString(int i)
Represent a 32 bit value as if it were an unsigned integer.
|
static String |
toUnsignedString(long l)
Represent a 64 bit value as if it were an unsigned long.
|
static long |
unsignedIntToLong(int unsignedValue)
Convert an unsigned integer to a long value.
|
static long |
unsignedLongToSignedLong(long unsignedValue)
Convert an unsigned long to a signed long value by stripping the sign bit.
|
static boolean |
wildcardMatch(String text,
String pattern)
Tests if a String matches another String with a wildcard pattern.
|
public static final String HEX_ERROR
HEX_ERROR="0x%08X"public static final String UNKNOWN
public static final String SYSFS_SERIAL_PATH
public static final OffsetDateTime UNIX_EPOCH
public static final Pattern whitespacesColonWhitespace
whitespacesColonWhitespacepublic static final Pattern whitespaces
whitespacespublic static final Pattern notDigits
notDigitspublic static final Pattern startWithNotDigits
startWithNotDigitspublic static String formatBytes(long bytes)
formatBytesDecimal(long). For Windows displays for KB, MB and GB, in
JEDEC units, edit the returned string to remove the 'i' to display the
(incorrect) JEDEC units.bytes - Bytes.public static String formatBytesDecimal(long bytes)
formatBytes(long).bytes - Bytes.public static String formatHertz(long hertz)
hertz - Hertz.public static String formatValue(long value, String unit)
value - The valueunit - Units to append metric prefix topublic static String formatElapsedSecs(long secs)
secs - Elapsed secondspublic static float round(float d,
int decimalPlace)
d - Number to be roundeddecimalPlace - Number of decimal places to round topublic static long getUnsignedInt(int x)
x - Signed int representing an unsigned integerpublic static String toUnsignedString(int i)
This is a Java 7 implementation of Java 8's Integer.toUnsignedString.
i - a 32 bit valuepublic static String toUnsignedString(long l)
This is a Java 7 implementation of Java 8's Long.toUnsignedString.
l - a 64 bit valuepublic static String formatError(int errorCode)
errorCode - The error codepublic static Map<Integer,String> getCwdMap(int pid)
getCwdMap.
pid - a int.Map object.public static long parseHertz(String hertz)
hertz - Hertz size.Long Hertz value or -1 if not parseable.public static int parseLastInt(String s, int i)
s - The string to parsei - Default integer if not parsablepublic static long parseLastLong(String s, long li)
s - The string to parseli - Default long integer if not parsablepublic static double parseLastDouble(String s, double d)
s - The string to parsed - Default double if not parsablepublic static String parseLastString(String s)
s - The string to parsepublic static String byteArrayToHexString(byte[] bytes)
bytes - The byte array to representpublic static byte[] hexStringToByteArray(String digits)
digits - The string to be parsedpublic static byte[] asciiStringToByteArray(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 ASCII 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 unsignedIntToLong(int unsignedValue)
unsignedValue - The unsigned integer value to convert.public static long unsignedLongToSignedLong(long unsignedValue)
unsignedValue - The unsigned long value to convert.public 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 long parseUnsignedLongOrDefault(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 String getDoubleQuoteStringValue(String line)
line - the entire stringpublic static String getStringBetween(String line, char c)
line - The "key-value" pair line.c - The Trailing And Leading characters of the string linepublic 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 returnpublic static String removeMatchingString(String original, String toRemove)
original - source String to remove fromtoRemove - the sub string to be removedpublic static long[] parseStringToLongArray(String s, int[] indices, int length, char delimiter)
The indices parameters are referenced assuming the length as specified, and leading characters are ignored. For example, if the string is "foo 12 34 5" and the length is 3, then index 0 is 12, index 1 is 34, and index 2 is 5.
s - The string to parseindices - An array indicating which indexes should be populated in the final
array; other values will be skipped. This idex is zero-referenced
assuming the rightmost delimited fields of the string contain the
array.length - The total number of elements in the string array. It is
permissible for the string to have more elements than this;
leading elements will be ignored. This should be calculated once
per text format by countStringToLongArray(java.lang.String, char).delimiter - The character to delimit by.public static int countStringToLongArray(String s, char delimiter)
length field for
parseStringToLongArray(java.lang.String, int[], int, char).s - The string to parsedelimiter - The character to delimit bypublic static String getTextBetweenStrings(String text, String before, String after)
text - Text to search for matchbefore - Start matching after this textafter - End matching before this textpublic static long filetimeToUtcMs(long filetime,
boolean local)
filetime - A 64-bit value equivalent to FILETIMElocal - True if converting from a local filetime (PDH counter); false if
already UTC (WMI PerfRawData classes)public static String parseMmDdYyyyToYyyyMmDD(String dateString)
dateString - The date in MM DD YYYY formatpublic static OffsetDateTime parseCimDateTimeToOffset(String cimDateTime)
OffsetDateTime.cimDateTime - A non-null DateTime String in CIM date format, e.g.,
20160513072950.782000-420OffsetDateTime if the string is
parsable, otherwise UNIX_EPOCH.public static void sleep(long ms)
ms - How long to sleeppublic static boolean wildcardMatch(String text, String pattern)
text - The String to testpattern - The String containing a wildcard pattern where ? represents a
single character and * represents any number of characters. If the
first character of the pattern is a carat (^) the test is
performed against the remaining characters and the result of the
test is the opposite.public static String getManufacturerID(byte[] edid)
edid - The EDID byte arraypublic static String getProductID(byte[] edid)
edid - The EDID byte arraypublic static String getSerialNo(byte[] edid)
edid - The EDID byte arraypublic static byte getWeek(byte[] edid)
edid - The EDID byte arraypublic static int getYear(byte[] edid)
edid - The EDID byte arraypublic static String getVersion(byte[] edid)
edid - The EDID byte arraypublic static boolean isDigital(byte[] edid)
edid - The EDID byte arraypublic static int getHcm(byte[] edid)
edid - The EDID byte arraypublic static int getVcm(byte[] edid)
edid - The EDID byte arraypublic static byte[][] getDescriptors(byte[] edid)
edid - The EDID byte arraypublic static int getDescriptorType(byte[] desc)
desc - An 18-byte VESA descriptorpublic static String getTimingDescriptor(byte[] desc)
desc - An 18-byte VESA descriptorpublic static String getDescriptorRangeLimits(byte[] desc)
desc - An 18-byte VESA descriptorpublic static String getDescriptorText(byte[] desc)
desc - An 18-byte VESA descriptorpublic static String toString(byte[] edid)
edid - An EDID byte arraypublic static List<String> readFile(String filename)
filename - The file to readpublic static List<String> readFile(String filename, boolean reportError)
filename - The file to readreportError - Whether to log errors reading the filepublic static long getLongFromFile(String filename)
filename - The file to readpublic static long getUnsignedLongFromFile(String filename)
filename - The file to readpublic static int getIntFromFile(String filename)
filename - The file to readpublic static String getStringFromFile(String filename)
filename - The file to readpublic static Map<String,String> getKeyValueMapFromFile(String filename, String separator)
filename - The file to readseparator - Characters in each line of the file that separate the key and the
valueCopyright © 2020. All rights reserved.