public class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
allEquals(int needle,
byte... bytes) |
static byte[] |
asByteArray(int... values) |
static String |
bytes2HexString(byte... bytes)
Formats an array of bytes as a string showing values in hex.
|
static String |
bytes2HexStringCompact(byte... bytes)
Same as bytes2HexString(), but without bytes seprator
|
static int |
bytes2Int(byte... bytes) |
static String |
bytes2String(String charsetName,
byte... bytes)
Interprets an array of bytes as an string in a given charset.
|
static String |
bytes2UTF8String(byte... bytes)
Interprets an array of bytes as an UTF-8 string.
|
static int |
compareVersions(String v1,
String v2) |
static String |
image2Base64String(Image image) |
static byte[] |
int2Bytes(int value) |
static String |
int2HexString(int i)
Formats an integer as a hex string of little-endian, non-zero-padded
bytes.
|
static <T extends Comparable<T>> |
map2UTF8String(Map<T,byte[]> map)
Formats a map of objects to byte arrays for printing.
|
public static String int2HexString(int i)
i
- the integer to formatpublic static String bytes2HexString(byte... bytes)
Silently skips leading zero bytes.
bytes
- the bytes to printpublic static String bytes2HexStringCompact(byte... bytes)
bytes
- public static <T extends Comparable<T>> String map2UTF8String(Map<T,byte[]> map)
Each map entry is written out as a string line, map key first, then an equals sign, then an UTF-8 string interpreted from the bytes, then the recovered bytes written out as strings.
The map keys are sorted by the natural order of the key type.
Example:
42 = Hello World ()
T
- a comparable key type (comparable for sorting)map
- the map to formatpublic static String bytes2String(String charsetName, byte... bytes)
charsetName
- Charset name known to Java String class (UTF-8, ISO-8859-1,...).bytes
- the bytes to convert to string, null
allowed.public static String bytes2UTF8String(byte... bytes)
Failing that, interprets as ISO-8859-1 or return a hex string.
bytes
- the bytes to convert to string, null
allowed.public static byte[] asByteArray(int... values)
public static byte[] int2Bytes(int value)
public static int bytes2Int(byte... bytes)
public static boolean allEquals(int needle, byte... bytes)
public static int compareVersions(String v1, String v2) throws RuntimeException
RuntimeException
Copyright © 2017 Open Source Developer, Goran Rakic. All rights reserved.