java.lang.Object
oshi.util.FormatUtil
Formatting utility for appending units or converting between number types.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 notationstatic 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 long
getUnsignedInt
(int x) Convert unsigned int to signed long.static int
roundToInt
(double x) Rounds a floating point number to the nearest integerstatic 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.
-
Field Details
-
HEX_ERROR
ConstantHEX_ERROR="0x%08X"
- See Also:
-
-
Method Details
-
formatBytes
Format bytes into a rounded string representation using IEC standard (matches Mac/Linux). For hard drive capacities, use @linkformatBytesDecimal(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.- Parameters:
bytes
- Bytes.- Returns:
- Rounded string representation of the byte size.
-
formatBytesDecimal
Format bytes into a rounded string representation using decimal SI units. These are used by hard drive manufacturers for capacity. Most other storage should useformatBytes(long)
.- Parameters:
bytes
- Bytes.- Returns:
- Rounded string representation of the byte size.
-
formatHertz
Format hertz into a string to a rounded string representation.- Parameters:
hertz
- Hertz.- Returns:
- Rounded string representation of the hertz size.
-
formatValue
Format arbitrary units into a string to a rounded string representation.- Parameters:
value
- The valueunit
- Units to append metric prefix to- Returns:
- Rounded string representation of the value with metric prefix to extension
-
formatElapsedSecs
Formats an elapsed time in seconds as days, hh:mm:ss.- Parameters:
secs
- Elapsed seconds- Returns:
- A string representation of elapsed time
-
getUnsignedInt
public static long getUnsignedInt(int x) Convert unsigned int to signed long.- Parameters:
x
- Signed int representing an unsigned integer- Returns:
- long value of x unsigned
-
toUnsignedString
Represent a 32 bit value as if it were an unsigned integer. This is a Java 7 implementation of Java 8's Integer.toUnsignedString.- Parameters:
i
- a 32 bit value- Returns:
- the string representation of the unsigned integer
-
toUnsignedString
Represent a 64 bit value as if it were an unsigned long. This is a Java 7 implementation of Java 8's Long.toUnsignedString.- Parameters:
l
- a 64 bit value- Returns:
- the string representation of the unsigned long
-
formatError
Translate an integer error code to its hex notation- Parameters:
errorCode
- The error code- Returns:
- A string representing the error as 0x....
-
roundToInt
public static int roundToInt(double x) Rounds a floating point number to the nearest integer- Parameters:
x
- the floating point number- Returns:
- the integer
-