public class BytesUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_LEN |
static int |
DOUBLE_LEN |
static int |
FLOAT_LEN |
static int |
INT_LEN |
static int |
LONG_LEN |
static int |
SHORT_LEN |
Constructor and Description |
---|
BytesUtils() |
Modifier and Type | Method and Description |
---|---|
static double |
bytesToDouble(byte[] bytes,
int startIndex)
Given an array of bytes, convert it to a double, least significant byte is stored in the beginning.
|
static float |
bytesToFloat(byte[] bytes,
int startIndex)
Given a byte array, restore it as an int
|
static int |
bytesToInt(byte[] bytes,
int startIndex)
Given a byte array, restore it as an int
|
static long |
bytesToLong(byte[] bytes,
int startIndex)
Given an array of bytes, convert it to a long, least significant byte is stored in the beginning.
|
static short |
bytesToShort(byte[] bytes,
int startIndex)
Given a byte array, restore it as a short
|
static String |
bytesToString(byte[] bytes,
int startIndex)
Given a byte array, restore a String out of it.
|
static int |
doubleToBytes(double dnum,
byte[] bytes,
int startIndex)
Given a double, convert it into a byte array
|
static int |
floatToBytes(float fnum,
byte[] bytes,
int startIndex)
translate float into bytes, stored in byte array starting from startIndex
|
static int |
intToBytes(int num,
byte[] bytes,
int startIndex)
translate int into bytes, stored in byte array starting from startIndex
|
static int |
longToBytes(long lnum,
byte[] bytes,
int startIndex)
Given a long, convert it into a byte array
|
static int |
shortToBytes(short num,
byte[] bytes,
int startIndex)
translate short into bytes, stored in byte array starting from startIndex
|
static int |
stringToBytes(String str,
byte[] bytes,
int startIndex)
Give a String less than 255 bytes, store it as byte array, starting with the length of the string.
|
public static final int BYTE_LEN
public static final int SHORT_LEN
public static final int INT_LEN
public static final int FLOAT_LEN
public static final int LONG_LEN
public static final int DOUBLE_LEN
public static int intToBytes(int num, byte[] bytes, int startIndex)
num
- the integer to be translatedbytes
- [] the byte arraystartIndex
- starting to store in this indexpublic static int bytesToInt(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index of the place the int is storedpublic static int floatToBytes(float fnum, byte[] bytes, int startIndex)
num
- the float to be translatedbytes
- [] the byte arraystartIndex
- starting to store in this indexpublic static float bytesToFloat(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index of the place the int is storedpublic static int shortToBytes(short num, byte[] bytes, int startIndex)
num
- the short to be translatedbytes
- [] the byte arraystartIndex
- starting to store in this indexpublic static short bytesToShort(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index of the place the int is storedpublic static int stringToBytes(String str, byte[] bytes, int startIndex)
str
- the string that is less than 255 bytesbytes
- the byte arraystartIndex
- the starting index where the string will be stored.public static String bytesToString(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index where the string is stored, the first cell stores the lengthpublic static int longToBytes(long lnum, byte[] bytes, int startIndex)
lnum
- the long given to convertbytes
- the bytes where to store the resultstartIndex
- the starting index of the array where the result is stored.public static long bytesToLong(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index of the array where the long is stored.public static int doubleToBytes(double dnum, byte[] bytes, int startIndex)
dnum
- the double given to convertbytes
- the bytes where to store the resultstartIndex
- the starting index of the array where the result is stored.public static double bytesToDouble(byte[] bytes, int startIndex)
bytes
- the byte arraystartIndex
- the starting index of the array where the long is stored.Copyright © 2019. All rights reserved.