import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
/**
* 对象工具类
*
* @author
*
*/
public class BeanUtil extends BeanUtils {
/**
* 将对象序列化
*
* @param obj
* @return
*/
public static ByteArrayOutputStream objToByte(Object obj) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
} catch (IOException e1) {
e1.printStackTrace();
}
return bos;
}
/**
* 反序列化
*
* @param byt
* @return
*/
public static Object byteToObj(byte[] byt) {
ObjectInputStream ois = null;
Object obj = null;
try {
ois = new ObjectInputStream(new ByteArrayInputStream(byt, 0,
byt.length));
obj = ois.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return obj;
}
}
对象工具类
最新推荐文章于 2024-01-17 15:06:46 发布