package org.springrain.frame.util;@b@@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@import java.io.ByteArrayInputStream;@b@import java.io.ByteArrayOutputStream;@b@import java.io.ObjectInputStream;@b@import java.io.ObjectOutputStream;@b@@b@/**@b@ * 序列化/反序列化 工具类@b@ *@b@ * @author caomei@b@ */@b@public class SerializeUtils {@b@@b@ private static final Logger logger = LoggerFactory.getLogger(SerializeUtils.class);@b@@b@ private SerializeUtils() {@b@ throw new IllegalAccessError("工具类不能实例化");@b@ }@b@@b@ /**@b@ * 序列化对象@b@ *@b@ * @param object@b@ * @return@b@ */@b@ public static byte[] serialize(Object object) {@b@ if (object == null) {@b@ return null;@b@ }@b@@b@ ObjectOutputStream oos = null;@b@ ByteArrayOutputStream baos = null;@b@ try {@b@ // 序列化@b@ baos = new ByteArrayOutputStream();@b@ oos = new ObjectOutputStream(baos);@b@ oos.writeObject(object);@b@ byte[] bytes = baos.toByteArray();@b@ return bytes;@b@ } catch (Exception e) {@b@ logger.error(e.getMessage(), e);@b@ }@b@ return null;@b@ }@b@@b@ /**@b@ * 反序列化对象@b@ *@b@ * @param bytes@b@ * @return@b@ */@b@ public static Object unserialize(byte[] bytes) {@b@ if (bytes == null) {@b@ return null;@b@ }@b@ ByteArrayInputStream bais = null;@b@ try {@b@ // 反序列化@b@ bais = new ByteArrayInputStream(bytes);@b@ ObjectInputStream ois = new ObjectInputStream(bais);@b@ return ois.readObject();@b@ } catch (Exception e) {@b@ logger.error(e.getMessage(), e);@b@ }@b@ return null;@b@ }@b@}