类 BinaryUtils
java.lang.Object
gu.sql2java.store.BinaryUtils
二进制数据(byte[],ByteBuffer)工具类
- 作者:
- guyadong
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static final <T> ByteBuffergetByteBuffer(T src) 将数据对象src转换为ByteBufferstatic final <T> ByteBuffergetByteBufferNotEmpty(T src) static final <T> byte[]getBytes(T src) 将数据对象src转换为字节数组(byte[])
src的数据类型可以是byte[],InputStream,ByteBuffer,String(base64编码),File,URL,URI否则抛出IllegalArgumentException
对象转换为InputStream或byte[]时,可能会抛出IOException当src为File或FileInputStream时,使用NIO方式(readBytes(FileInputStream))读取static final byte[]getBytesInBuffer(ByteBuffer buffer) 返回buffer中所有字节(position~limit),不改变buffer状态static final <T> byte[]getBytesNotEmpty(T src) static final <T> InputStreamgetInputStream(T src) 将对象转换为InputStream
类型可以是byte[],ByteBuffer,InputStream,String(base64编码),File,URL,URI,否则抛出RuntimeExceptionstatic final byte[]getMD5(byte[] source) 生成MD5校验码static final ByteBuffergetMD5(ByteBuffer source) 生成MD5校验码static final StringgetMD5String(byte[] source) 生成MD5校验码字符串static final StringgetMD5String(ByteBuffer source) 生成MD5校验码字符串static final ByteBufferhex2ByteBuffer(String src) convert HEX string to ByteBufferstatic final byte[]convert HEX string to byte arraystatic final byte[]readBytes(FileInputStream fin) static final byte[]readBytes(InputStream in) static final FileNIO方式将data数据保存在file指定的文件中
如果file所在文件夹不存在,则会自动创建所有的文件夹static final StringtoHex(byte[] buffer) 将16位byte[] 转换为32位的HEX格式的字符串Stringstatic final StringtoHex(ByteBuffer buffer) static final boolean字符串验证器,根据正则表达式判断字符串是否为十六进制(HEX)字符串 输入为null或空或正则表达式不匹配则返回falsestatic final boolean判断是否为有效的MD5字符串
-
构造器详细资料
-
BinaryUtils
public BinaryUtils()
-
-
方法详细资料
-
getMD5
public static final byte[] getMD5(byte[] source) 生成MD5校验码- 参数:
source-
-
getBytesInBuffer
返回buffer中所有字节(position~limit),不改变buffer状态- 参数:
buffer-- 返回:
- buffer 为 null 时返回 null
-
getMD5
生成MD5校验码- 参数:
source-- 另请参阅:
-
toHex
将16位byte[] 转换为32位的HEX格式的字符串String- 参数:
buffer-
-
toHex
- 另请参阅:
-
validHEX
字符串验证器,根据正则表达式判断字符串是否为十六进制(HEX)字符串 输入为null或空或正则表达式不匹配则返回false -
hex2Bytes
convert HEX string to byte array- 参数:
src-- 返回:
- byte array or
nullif src isnull
-
hex2ByteBuffer
convert HEX string to ByteBuffer- 参数:
src-- 返回:
- byte array or
nullif src isnull
-
getMD5String
生成MD5校验码字符串- 参数:
source-- 另请参阅:
-
getMD5String
生成MD5校验码字符串- 参数:
source-- 另请参阅:
-
validMd5
判断是否为有效的MD5字符串 -
readBytes
- 参数:
in- 为null返回null- 返回:
- 字节数组,如果输入为
null返回null - 抛出:
IOExceptionIllegalArgumentException-in为null
-
readBytes
- 参数:
fin-FileInputStream- 返回:
- 返回读取的字节数 当
fin为null时返回null; - 抛出:
IOException
-
getInputStream
public static final <T> InputStream getInputStream(T src) throws IOException, IllegalArgumentException 将对象转换为InputStream
类型可以是byte[],ByteBuffer,InputStream,String(base64编码),File,URL,URI,否则抛出RuntimeException- 参数:
src- 获取InputStream的源对象- 返回:
- 返回获取的InputStream对象,src为
null返回null,类型错误抛出异常 - 抛出:
IOExceptionIllegalArgumentException- 无法从src获取InputStream
-
getBytes
将数据对象src转换为字节数组(byte[])
src的数据类型可以是byte[],InputStream,ByteBuffer,String(base64编码),File,URL,URI否则抛出IllegalArgumentException
对象转换为InputStream或byte[]时,可能会抛出IOException当src为File或FileInputStream时,使用NIO方式(readBytes(FileInputStream))读取- 参数:
src- 获取byte[]的源对象- 返回:
- 返回字节数组,参数为
null返回null,类型不对则抛出异常 - 抛出:
IOExceptionIllegalArgumentException-src为null或无法从src获取InputStream- 另请参阅:
-
getBytesNotEmpty
- 参数:
src- 获取byte[]的源对象- 返回:
- 返回非空字节数组
- 抛出:
IOException- 另请参阅:
-
getByteBuffer
public static final <T> ByteBuffer getByteBuffer(T src) throws IOException, IllegalArgumentException 将数据对象src转换为ByteBuffer- 参数:
src- 获取byte[]的源对象- 返回:
- 返回字节数组,参数为
null返回null,类型不对则抛出异常 - 抛出:
IOExceptionIllegalArgumentException- 无法从src获取InputStream- 另请参阅:
-
getByteBufferNotEmpty
public static final <T> ByteBuffer getByteBufferNotEmpty(T src) throws IOException, IllegalArgumentException - 参数:
src-- 返回:
- 返回非空字节数组
- 抛出:
IOExceptionIllegalArgumentException
-
saveBytes
public static final File saveBytes(byte[] data, File file, boolean overwrite) throws IOException, IllegalArgumentException NIO方式将data数据保存在file指定的文件中
如果file所在文件夹不存在,则会自动创建所有的文件夹- 参数:
data-file- 文件保存的位置overwrite- 同名文件存在时是否覆盖- 返回:
- 返回保存的文件名
- 抛出:
IOException-file存在但不是文件或其他IO异常IllegalArgumentException-data为null时
-