public class Utility
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG_MODE |
static java.util.Random |
rnd
Object to get some random values...
|
static int |
TCP_BUFFER_SIZE
Default size for the TCP input stream
|
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Float |
bytesToFloat(byte[] bytes,
int offset,
int size)
Returns a
float value from array of bytes. |
static byte[] |
calculateCRC(byte[] data,
int offset,
int len)
Calculates and returns the CRC using the data passed in parameters.
|
static boolean |
checkCRC(byte[] data,
int offset,
int len,
byte[] crc)
Checks the CRC and returns true if it is correct, otherwise false.
|
static void |
DEBUG(java.lang.Object object,
java.lang.String method,
java.lang.String msg) |
static void |
DEBUG(java.lang.String className,
java.lang.String method,
java.lang.String msg) |
static void |
DEBUG(java.lang.String packageName,
java.lang.String className,
java.lang.String method,
java.lang.String msg) |
static java.io.BufferedReader |
fileParser(java.lang.String pathName,
java.lang.String fileName)
Method to use to access a file in your resources folder...
|
static java.lang.String |
getHexString(byte[] b)
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
|
static java.lang.String |
getHexString(byte[] b,
int offset,
int length)
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
|
static java.lang.String |
getHexStringForDebug(byte[] b,
int offset,
int length)
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) and
format the string with `0xCC` where CC is the string in HEX
|
static java.lang.String |
getStringRndVal(int factor)
Retrieves a random value rounded to 2 decimal...
|
static java.lang.String |
md5sum(java.lang.String msg)
Returns the md5 of any input...
|
static void |
pDebug(java.lang.String msg) |
static byte[] |
readBytes(java.io.InputStream in)
Reads the incoming data from an input stream as long as there is
something to read and saved the data in an array of bytes.
|
static java.util.List<java.lang.String> |
readLine(java.io.InputStream in)
Reads lines of text from the given input stream.
|
static byte[] |
readNBytes(java.io.InputStream in,
int len)
Reads from the given input stream an amount of bytes and retrieves these data as
an array of bytes.
|
static void |
threadWait(java.lang.Thread thread,
long millis)
To be used to make a thread waiting for a certain amount of time
|
static int |
unsignedByteToSignedInt(byte from)
Converts an unsigned byte to a signed integer.
|
static void |
waitSomeTime(int ms)
To wait some times ...
|
static void |
writeLine(java.io.OutputStream out,
byte[] toSend)
Send the data contained in the given array of bytes through the output
stream.
|
public static final int TCP_BUFFER_SIZE
public static final boolean DEBUG_MODE
public static java.util.Random rnd
public static byte[] calculateCRC(byte[] data, int offset, int len)
data
- a byte array containing the data to sendoffset
- the offsetlen
- the data lengthpublic static boolean checkCRC(byte[] data, int offset, int len, byte[] crc)
data
- a byte array containing the data to sendoffset
- the offsetlen
- the data lengthcrc
- a byte array containing the CRC to checkpublic static java.lang.Float bytesToFloat(byte[] bytes, int offset, int size)
float
value from array of bytes. This byte's array can only be 2 or 4 bytes long.bytes
- The array of bytes to convert.offset
- The position where the method has to start to get the bytes from.size
- The amount of bytes to convert.Float
value or null
if the process failed.public static int unsignedByteToSignedInt(byte from)
from
- an unsigned byte to convert to a signed integerpublic static java.lang.String getHexString(byte[] b)
b
- The array of bytes to be convert in HEX characters.public static java.lang.String getHexString(byte[] b, int offset, int length)
b
- The byte array to convert in HEX stringoffset
- The index where we start to convert from.length
- The amount of bytes to convert in HEX stringpublic static java.lang.String getHexStringForDebug(byte[] b, int offset, int length)
b
- The byte array to convert in HEX stringoffset
- The index where we start to convert from.length
- The amount of bytes to convert in HEX stringpublic static void threadWait(java.lang.Thread thread, long millis)
thread
- The thread to be stoppedmillis
- The amount of time in [ms] to stop the thread.public static void waitSomeTime(int ms)
public static java.lang.String md5sum(java.lang.String msg)
msg
- The input string to processpublic static java.lang.String getStringRndVal(int factor)
factor
- A coefficient which the random value is multiplied with.public static byte[] readBytes(java.io.InputStream in) throws java.io.IOException
in
- The input Stream where to read the data coming from.array of bytes
. Or null if the
has been closed by the peer while waiting for incoming data.java.io.IOException
- If the first byte cannot be read for any reason other
than the end of the file, if the input stream has been
closed, or if some other I/O error occurs.public static byte[] readNBytes(java.io.InputStream in, int len) throws java.io.IOException
in
- The input Stream where to read the data coming from.len
- The number of bytes to be read from the input stream.array of bytes
.java.io.IOException
- If the first byte cannot be read for any reason other
than the end of the file, if the input stream has been
closed, or if some other I/O error occurs.public static java.util.List<java.lang.String> readLine(java.io.InputStream in) throws java.io.IOException
in
- The Input Stream to read from.java.io.IOException
- If an I/O error occurspublic static void writeLine(java.io.OutputStream out, byte[] toSend) throws java.io.IOException
out
- The Output Stream to send the data to.toSend
- The data to sendjava.io.IOException
- If an I/O error occurspublic static java.io.BufferedReader fileParser(java.lang.String pathName, java.lang.String fileName)
pathName
- folder's name (if exists) from `resources`fileName
- Name of the file to accesspublic static void DEBUG(java.lang.String className, java.lang.String method, java.lang.String msg)
public static void DEBUG(java.lang.Object object, java.lang.String method, java.lang.String msg)
public static void DEBUG(java.lang.String packageName, java.lang.String className, java.lang.String method, java.lang.String msg)
public static void pDebug(java.lang.String msg)