public class ByteKit extends Object
| Constructor and Description |
|---|
ByteKit() |
| Modifier and Type | Method and Description |
|---|---|
static String |
bcd(byte[] data,
int from,
int to)
解析 BCD 码
|
static double |
bytesToDouble(byte[] data,
int off,
boolean bigEndian)
byte数组转double
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static double |
bytesToDoubleBE(byte[] data,
int off)
byte数组转double
默认以:
ByteOrder.BIG_ENDIAN |
static double |
bytesToDoubleLE(byte[] data,
int off)
byte数组转double
默认以:
ByteOrder.LITTLE_ENDIAN |
static float |
bytesToFloat(byte[] data,
int off,
boolean bigEndian)
byte数组转float
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static float |
bytesToFloatBE(byte[] data,
int off)
byte数组转float
默认以:
ByteOrder.BIG_ENDIAN |
static float |
bytesToFloatLE(byte[] data,
int off)
byte数组转float
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToInt(byte[] data,
int off,
boolean bigEndian)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static int |
bytesToInt(byte[] data,
int start,
ByteOrder byteOrder)
byte[]转int值
|
static int |
bytesToIntBE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN |
static int |
bytesToIntLE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static long |
bytesToLong(byte[] data,
int off,
boolean bigEndian)
byte数组转long
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static long |
bytesToLong(byte[] data,
int start,
ByteOrder byteOrder)
byte数组转long
|
static long |
bytesToLongBE(byte[] data,
int off)
byte数组转long
默认以:
ByteOrder.BIG_ENDIAN |
static long |
bytesToLongLE(byte[] data,
int off)
byte数组转long
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToShort(byte[] data,
int off,
boolean bigEndian)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static void |
bytesToShort(byte[] data,
short[] s,
int off,
int len,
boolean bigEndian)
byte数组处理
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static int |
bytesToShortBE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToShortLE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static void |
bytesToShortLE(byte[] data,
short[] s,
int off,
int len)
byte数组处理
默认排序:
ByteOrder.LITTLE_ENDIAN |
static void |
bytesToShortsBE(byte[] data,
short[] s,
int off,
int len)
byte数组处理
默认排序:
ByteOrder.BIG_ENDIAN |
static int |
bytesToTag(byte[] data,
int off,
boolean bigEndian)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static int |
bytesToTagBE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN |
static int |
bytesToTagLE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToUShort(byte[] data,
int off,
boolean bigEndian)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN |
static int |
bytesToUShortBE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToUShortLE(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.LITTLE_ENDIAN |
static int |
bytesToVR(byte[] data,
int off)
byte数组转int
默认以:
ByteOrder.BIG_ENDIAN |
static byte[] |
concat(byte[] buf1,
byte[] buf2)
将两个字节数组连接到一个新的字节数组
|
static int |
countOf(byte[] data,
byte target)
统计目标字节在字节数组中出现的次数
|
static byte[] |
doubleToBytes(double data,
byte[] bytes,
int off,
boolean bigEndian)
double转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
doubleToBytesBE(double data,
byte[] bytes,
int off)
double转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
doubleToBytesLE(double data,
byte[] bytes,
int off)
double转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static byte[] |
floatToBytes(float data,
byte[] bytes,
int off,
boolean bigEndian)
float转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
floatToBytesBE(float data,
byte[] bytes,
int off)
float转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
floatToBytesLE(float data,
byte[] bytes,
int off)
float转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static <T extends Number> |
get(byte[] bytes,
Class<T> targetClass,
ByteOrder byteOrder)
byte数组转换为指定类型数字
|
static byte[] |
get(Number number,
ByteOrder byteOrder)
将
Number转换为 |
static byte |
getByte(int data)
int转byte
|
static byte[] |
getBytes(char data)
char转byte数组
|
static byte[] |
getBytes(char[] data)
char转byte数组
|
static byte[] |
getBytes(double data)
double转byte数组
默认以小端序转换
|
static byte[] |
getBytes(double data,
ByteOrder byteOrder)
double转byte数组
|
static byte[] |
getBytes(float data)
float转byte数组
|
static byte[] |
getBytes(float data,
ByteOrder byteOrder)
double转byte数组
|
static byte[] |
getBytes(int... data)
int转byte数组
默认以小端序转换
|
static byte[] |
getBytes(int data)
int转byte数组
默认以小端序转换
|
static byte[] |
getBytes(int data,
ByteOrder byteOrder)
int转byte数组
自定义端序
|
static byte[] |
getBytes(long data)
long转byte数组
默认以小端序转换
|
static byte[] |
getBytes(long data,
ByteOrder byteOrder)
long转byte数组
|
static byte[] |
getBytes(Number number)
将
Number转换为byte数组 |
static byte[] |
getBytes(short data)
short转byte数组
默认以小端序转换
|
static byte[] |
getBytes(short data,
ByteOrder byteOrder)
short转byte数组
自定义端序
|
static byte[] |
getBytes(String data)
string转byte数组
|
static byte[] |
getBytes(String data,
String charset)
string转byte数组
|
static char |
getChar(byte[] data)
byte数组转char
|
static double |
getDouble(byte[] data)
byte数组转Double
默认以小端序转换
|
static double |
getDouble(byte[] data,
ByteOrder byteOrder)
byte数组转double
自定义端序
|
static float |
getFloat(byte[] data)
byte数组转Double
默认以小端序转换
|
static float |
getFloat(byte[] data,
ByteOrder byteOrder)
byte数组转double
自定义端序
|
static int |
getInt(byte data)
byte转无符号int
|
static int |
getInt(byte[] data)
byte[]转int值
默认以小端序转换
|
static int |
getInt(byte[] data,
ByteOrder byteOrder)
byte[]转int值
自定义端序
|
static long |
getLong(byte[] data)
byte数组转long
|
static long |
getLong(byte[] data,
ByteOrder byteOrder)
byte数组转long
|
static <T extends Number> |
getNumber(byte[] bytes,
Class<T> targetClass)
byte数组转换为指定类型数字
|
static short |
getShort(byte[] data)
byte数组转short
默认以小端序转换
|
static short |
getShort(byte[] data,
ByteOrder byteOrder)
byte数组转short
自定义端序
|
static String |
getString(byte[] data)
byte数组转string
|
static String |
getString(byte[] data,
String charset)
byte数组转string
|
static int |
indexOf(byte[] data,
byte target,
int from,
int to)
寻找目标字节在字节数组中的下标
|
static byte[] |
intToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
int转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
intToBytesBE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
intToBytesLE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static byte[] |
join(byte[]... data)
连接多个字节数组
|
static byte[] |
join(byte data,
byte[]... datas)
连接多个字节数组
|
static byte[] |
longToBytes(long data,
byte[] bytes,
int off,
boolean bigEndian)
long转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
longToBytesBE(long data,
byte[] bytes,
int off)
long转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
longToBytesLE(long data,
byte[] bytes,
int off)
long转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static byte[] |
shortToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
int转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
shortToBytesBE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
shortToBytesLE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static byte[][] |
split(byte[] data,
byte separator)
根据分隔符拆分字节数组
|
static byte[][] |
split(byte[] data,
int len)
拆分byte数组为几个等份(最后一份可能小于len)
|
static byte[] |
subArray(byte[] data,
int from)
截取子数组
|
static byte[] |
subArray(byte[] data,
int from,
int to)
截取子数组
|
static byte[] |
swapInts(byte[] data,
int off,
int len) |
static byte[] |
swapLongs(byte[] data,
int off,
int len) |
static byte[][] |
swapShorts(byte[][] data) |
static byte[] |
swapShorts(byte[] data,
int off,
int len) |
static byte[] |
tagToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
int转byte数组
排序:
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN |
static byte[] |
tagToBytesBE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.BIG_ENDIAN |
static byte[] |
tagToBytesLE(int data,
byte[] bytes,
int off)
int转byte数组
默认排序:
ByteOrder.LITTLE_ENDIAN |
static byte[] |
trim(byte[] data,
byte empty)
首尾去掉空字符
|
static byte[] |
trim(byte[] data,
byte empty,
int from,
int to)
从 from 到 to 截取子串 并 首尾去掉空字符
|
static int |
unsigned(byte data)
无符号整数
|
static int |
xor(byte[] data)
异或值,返回
|
public static byte getByte(int data)
data - int值public static byte[] getBytes(int data)
data - int值public static byte[] getBytes(int... data)
data - int值public static byte[] getBytes(int data,
ByteOrder byteOrder)
data - int值byteOrder - 端序public static byte[] getBytes(long data)
data - long值public static byte[] getBytes(long data,
ByteOrder byteOrder)
data - long值byteOrder - 端序public static byte[] getBytes(float data)
data - float值public static byte[] getBytes(float data,
ByteOrder byteOrder)
data - double值byteOrder - 端序public static byte[] getBytes(double data)
data - double值public static byte[] getBytes(double data,
ByteOrder byteOrder)
data - double值byteOrder - 端序public static byte[] getBytes(short data)
data - short值public static byte[] getBytes(short data,
ByteOrder byteOrder)
data - short值byteOrder - 端序public static byte[] getBytes(char data)
data - char值public static byte[] getBytes(char[] data)
data - char值public static byte[] getBytes(String data)
data - string值public static byte[] getBytes(String data, String charset)
data - string值charset - 字符集public static int getInt(byte data)
data - byte值public static int getInt(byte[] data)
data - byte数组public static int getInt(byte[] data,
ByteOrder byteOrder)
data - byte数组byteOrder - 端序public static int bytesToInt(byte[] data,
int start,
ByteOrder byteOrder)
data - byte数组start - 计算数组开始位置byteOrder - 端序public static long getLong(byte[] data)
data - byte数组public static long getLong(byte[] data,
ByteOrder byteOrder)
data - byte数组byteOrder - 端序public static long bytesToLong(byte[] data,
int start,
ByteOrder byteOrder)
data - byte数组start - 计算数组开始位置byteOrder - 端序public static float getFloat(byte[] data)
data - byte数组public static float getFloat(byte[] data,
ByteOrder byteOrder)
data - byte数组byteOrder - 端序public static double getDouble(byte[] data)
data - byte数组public static double getDouble(byte[] data,
ByteOrder byteOrder)
data - byte数组byteOrder - 端序public static short getShort(byte[] data)
data - byte数组public static short getShort(byte[] data,
ByteOrder byteOrder)
data - byte数组byteOrder - 端序public static char getChar(byte[] data)
data - 字节数组public static String getString(byte[] data)
data - 字节数组public static String getString(byte[] data, String charset)
data - 字节数组charset - 字符集public static byte[] getBytes(Number number)
Number转换为byte数组number - byte数组public static <T extends Number> T getNumber(byte[] bytes, Class<T> targetClass)
T - 数字类型bytes - byte数组targetClass - 目标数字类型IllegalArgumentException - 不支持的数字类型,如用户自定义数字类型public static byte[] get(Number number, ByteOrder byteOrder)
Number转换为number - 数字byteOrder - 端序public static <T extends Number> T get(byte[] bytes, Class<T> targetClass, ByteOrder byteOrder)
T - 数字类型bytes - byte数组targetClass - 目标数字类型byteOrder - 端序IllegalArgumentException - 不支持的数字类型,如用户自定义数字类型public static byte[][] split(byte[] data,
byte separator)
data - 字节数组separator - 分隔符public static byte[][] split(byte[] data,
int len)
data - 数组len - 每个小节的长度public static byte[] subArray(byte[] data,
int from)
data - 字节数组from - 开始下标(包含)public static byte[] subArray(byte[] data,
int from,
int to)
data - 字节数组from - 开始下标(包含)to - 结束下标(不包含)public static byte[] join(byte data,
byte[]... datas)
data - 连字符datas - 二维数组public static byte[] join(byte[]... data)
data - 二维数组public static byte[] trim(byte[] data,
byte empty)
data - 字节数组empty - 空数组public static byte[] trim(byte[] data,
byte empty,
int from,
int to)
data - 字节数组empty - 空字节from - 开始下标(包含)to - 结束下标(不包含)public static int bytesToInt(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static int bytesToIntBE(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static int bytesToIntLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static int bytesToShort(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static void bytesToShort(byte[] data,
short[] s,
int off,
int len,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - long值s - 字符off - 偏移量len - 字符长度bigEndian - 是否大字节序列public static int bytesToShortBE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static int bytesToShortLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static void bytesToShortsBE(byte[] data,
short[] s,
int off,
int len)
ByteOrder.BIG_ENDIANdata - double值s - 字符off - 偏移量len - 字符长度public static void bytesToShortLE(byte[] data,
short[] s,
int off,
int len)
ByteOrder.LITTLE_ENDIANdata - double值s - 字符off - 偏移量len - 字符长度public static int bytesToUShort(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static int bytesToUShortBE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static int bytesToUShortLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static float bytesToFloat(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static float bytesToFloatBE(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static float bytesToFloatLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static long bytesToLong(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static long bytesToLongBE(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static long bytesToLongLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static double bytesToDouble(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static double bytesToDoubleBE(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static double bytesToDoubleLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static int bytesToVR(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static int bytesToTag(byte[] data,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量bigEndian - 是否大字节序列public static int bytesToTagBE(byte[] data,
int off)
ByteOrder.BIG_ENDIANdata - byte数组off - 偏移量public static int bytesToTagLE(byte[] data,
int off)
ByteOrder.LITTLE_ENDIANdata - byte数组off - 偏移量public static byte[] intToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - float值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] intToBytesBE(int data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] intToBytesLE(int data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] shortToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - int值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] shortToBytesBE(int data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] shortToBytesLE(int data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] longToBytes(long data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - long值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] longToBytesBE(long data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - long值bytes - 目标字节off - 偏移量public static byte[] longToBytesLE(long data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - long值bytes - 目标字节off - 偏移量public static byte[] floatToBytes(float data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - float值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] floatToBytesBE(float data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - double值bytes - 目标字节off - 偏移量public static byte[] floatToBytesLE(float data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - double值bytes - 目标字节off - 偏移量public static byte[] doubleToBytes(double data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - double值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] doubleToBytesBE(double data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - double值bytes - 目标字节off - 偏移量public static byte[] doubleToBytesLE(double data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - double值bytes - 目标字节off - 偏移量public static byte[] tagToBytes(int data,
byte[] bytes,
int off,
boolean bigEndian)
ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIANdata - float值bytes - 目标字节off - 偏移量bigEndian - 是否大字节序列public static byte[] tagToBytesBE(int data,
byte[] bytes,
int off)
ByteOrder.BIG_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] tagToBytesLE(int data,
byte[] bytes,
int off)
ByteOrder.LITTLE_ENDIANdata - int值bytes - 目标字节off - 偏移量public static byte[] swapInts(byte[] data,
int off,
int len)
public static byte[] swapLongs(byte[] data,
int off,
int len)
public static byte[][] swapShorts(byte[][] data)
public static byte[] swapShorts(byte[] data,
int off,
int len)
public static int indexOf(byte[] data,
byte target,
int from,
int to)
data - 字节数组target - 目标字节from - 检索开始下标(包含)to - 检索结束下标(不包含)public static int countOf(byte[] data,
byte target)
data - 字节数组target - 目标字节public static String bcd(byte[] data, int from, int to)
data - 字节数组from - 开始下标(包含)to - 结束下标(不包含)public static int unsigned(byte data)
data - 字节public static int xor(byte[] data)
data - 数组public static byte[] concat(byte[] buf1,
byte[] buf2)
buf1 - 字节数组buf2 - 字节数组Copyright © 2022. All rights reserved.