package com.iflytek.atp.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import com.iflytek.atp.log.IflytekLogger;
import com.iflytek.atp.log.IflytekLoggerFactory;
public class ByteConvertUtils {
static IflytekLogger logger =IflytekLoggerFactory.getLogger(ByteConvertUtils.class);
/**
*
* @Methodname:byteArrayToObject(byte数组转化为对象)
* @Description:(这里描述这个方法适用条件 – 可选)
* @Param @param bytes
* @Param @return
* @Return Object
* @Author emtf
* @Datetime 2018年9月13日 下午1:58:46
* @Exception
* @Since 1.0.0
*/
public static Object byteArrayToObject(byte[] bytes) {
Object obj = null;
ByteArrayInputStream byteArrayInputStream = null;
ObjectInputStream objectInputStream = null;
try {
byteArrayInputStream = new ByteArrayInputStream(bytes);
objectInputStream = new ObjectInputStream(byteArrayInputStream);
obj = objectInputStream.readObject();
} catch (Exception e) {
logger.error("byteArrayToObject failed, " + e);
} finally {
if (byteArrayInputStream != null) {
try {
byteArrayInputStream.close();
} catch (IOException e) {
logger.error("close byteArrayInputStream failed, " + e);
}
}
if (objectInputStream != null) {
try {
objectInputStream.close();
} catch (IOException e) {
logger.error("close objectInputStream failed, " + e);
}
}
}
return obj;
}
}
字节数组转为object
最新推荐文章于 2024-08-17 15:09:14 发布