public class ToolBox extends Object
| Constructor and Description |
|---|
ToolBox() |
| Modifier and Type | Method and Description |
|---|---|
static String |
bytesToHexString(byte[] bytes,
int stringLength)
Convert byte array to hex string
|
static void |
disableCertificateValidation()
Disable SSL Certificate validation
|
static double |
distance(double startLat,
double startLong,
double endLat,
double endLong)
Calculates the distance between two coordinates
|
static byte[] |
getBytesFromInputStream(InputStream is)
Reads all bytes from an input stream
|
static byte[] |
getUUID()
Return UUID as buffer of 16 bytes
|
static byte[] |
hexStringToBytes(String hexString,
int arraySize)
Convert String to array of bytes
|
static byte[] |
readBytesFromFile(String fileName)
Reads byte array from file
|
static byte[] |
readBytesFromUrl(String urlString)
Reads bytes from indicated URL.
|
static float |
readFloat(byte[] data,
int offset,
boolean isLittleEndian)
Read a float value from the byte array.
|
static int |
readInt(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
Read an signed integer value from the byte array
|
static String |
readString(byte[] data,
int offset,
int chars)
Reads a string from the input stream.
|
static String |
readStringFromUrl(String urlString)
Request page.
|
static String |
readStringFromUtf8File(String fileName)
Reads the content of a UTF-8 file into a string
|
static int |
readUnsignedInt(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
Read an unsigned integer value from the byte array
|
static long |
readUnsignedLong(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
Read an unsigned integer value from the byte array
|
static String |
secondsToHours(int seconds)
Returns the number of seconds as string in the format 5h03'02"
|
static boolean |
writeBytesToFile(String fileName,
byte[] bytes)
This method writes the bytes to a binary file
|
static void |
writeFloat(byte[] data,
float value,
int offset,
boolean isLittleEndian)
Writes a float to the byte array
|
static boolean |
writeStringToFile(String fileName,
String string)
Write string to file
|
static boolean |
writeStringToUtf8File(String fileName,
String utf8String)
Handy piece of code to write JSON as UTF-8 to file
|
static void |
writeUnsignedInt(byte[] data,
int value,
int offset,
int bytes,
boolean isLittleEndian)
Writes the given value (value) in the byte array (data) at given location (offset).
|
static void |
writeUnsignedLong(byte[] data,
long value,
int offset,
int bytes,
boolean isLittleEndian)
Writes the given value (value) in the byte array (data) at given location (offset).
|
public static void disableCertificateValidation()
public static int readUnsignedInt(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
data - Byte arrayoffset - Offset where to startbytes - Number of bytes to be read in the intisLittleEndian - Indicates whether the byte array is LittleEndian or BigEndianpublic static long readUnsignedLong(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
data - Byte arrayoffset - Offset where to startbytes - Number of bytes to be read in the intisLittleEndian - Indicates whether the byte array is LittleEndian or BigEndianpublic static int readInt(byte[] data,
int offset,
int bytes,
boolean isLittleEndian)
data - Byte arrayoffset - Offset where to startbytes - Number of bytes to be read in the intisLittleEndian - Indicates whether the byte array is LittleEndian or BigEndianpublic static float readFloat(byte[] data,
int offset,
boolean isLittleEndian)
data - Byte arrayoffset - Offset where to startisLittleEndian - Indicates whether the byte array is LittleEndian or BigEndianpublic static void writeFloat(byte[] data,
float value,
int offset,
boolean isLittleEndian)
data - Byte arrayvalue - Float value to writeoffset - Offset in the byte arrayisLittleEndian - Indicates whether the byte array is LittleEndian or BigEndianpublic static String readString(byte[] data, int offset, int chars)
data - Byte array containing the dataoffset - Offset in the arraychars - Number of characters to readpublic static void writeUnsignedInt(byte[] data,
int value,
int offset,
int bytes,
boolean isLittleEndian)
data - Array to write the value tovalue - Value to writeoffset - Offset in the byte array where the value is writtenbytes - Number of bytes making up the integer value (1-4)isLittleEndian - True for little endian, false for big endianpublic static void writeUnsignedLong(byte[] data,
long value,
int offset,
int bytes,
boolean isLittleEndian)
data - Array to write the value tovalue - Value to writeoffset - Offset in the byte array where the value is writtenbytes - Number of bytes making up the integer value (1-4)isLittleEndian - True for little endian, false for big endianpublic static String secondsToHours(int seconds)
seconds - The seconds to convertpublic static String readStringFromUrl(String urlString)
urlString - URL of the pagepublic static byte[] readBytesFromUrl(String urlString)
urlString - The URL to read frompublic static byte[] readBytesFromFile(String fileName)
fileName - The file to readpublic static String readStringFromUtf8File(String fileName)
fileName - Name of the UTF-8 encoded filepublic static boolean writeBytesToFile(String fileName, byte[] bytes)
fileName - File name of the file to write tobytes - Bytes to writepublic static boolean writeStringToFile(String fileName, String string)
fileName - Filename to usestring - String to writepublic static boolean writeStringToUtf8File(String fileName, String utf8String)
fileName - Filename to write toutf8String - String (JSON) to writepublic static byte[] getBytesFromInputStream(InputStream is)
is - Input streampublic static double distance(double startLat,
double startLong,
double endLat,
double endLong)
startLat - First coordinate latitudestartLong - First coordinate longitudeendLat - Second coordinate latitudeendLong - Second coordinate longitudepublic static byte[] getUUID()
public static byte[] hexStringToBytes(String hexString, int arraySize)
hexString - String to convertarraySize - Size of the byte array. Zero's are added at msb sidepublic static String bytesToHexString(byte[] bytes, int stringLength)
bytes - Byte array to convertstringLength - Length to which the string must be paddedCopyright © 2025. All rights reserved.