public class ParseUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
notDigits |
static Pattern |
startWithNotDigits |
static Pattern |
whitespaces |
static Pattern |
whitespacesColonWhitespace |
| 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 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 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 |
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 String |
getStringBetween(String line,
char c)
Gets a value between two characters having multiple same characters
between them.
|
static String |
getTextBetweenStrings(String text,
String before,
String after)
Get a String in a line of text between two marker strings
|
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 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 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 String |
removeMatchingString(String original,
String toRemove)
Removes all matching sub strings from the string.
|
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.
|
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.
|
public static final Pattern whitespacesColonWhitespace
public static final Pattern whitespaces
public static final Pattern notDigits
public static final Pattern startWithNotDigits
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 long parseLastLong(String s, long li)
s - The string to parseli - Default long integer 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[] 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 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)
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.delimiter - 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 textCopyright © 2010–2019 oshi. All rights reserved.