| | |
| | | package com.vincent.rsf.common.utils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.*; |
| | | |
| | | @Slf4j |
| | | public class Serialize { |
| | | |
| | | // 序列化 |
| | | public static byte[] serialize(Object object) { |
| | | ObjectOutputStream oos = null; |
| | | ByteArrayOutputStream baos = null; |
| | |
| | | oos.writeObject(object); |
| | | return baos.toByteArray(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("Serialize.serialize", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // 反序列化 |
| | | public static Object unSerialize(byte[] bytes) { |
| | | ByteArrayInputStream bais = null; |
| | | try { |
| | |
| | | }; |
| | | return ois.readObject(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("Serialize.unSerialize", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |