| | |
| | | package com.ard.route.util; |
| | | |
| | | import java.io.*; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | |
| | |
| | | return ""; |
| | | } |
| | | |
| | | // 对象序列化为字节数组 |
| | | public static byte[] serialize(Object obj) throws IOException { |
| | | try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | ObjectOutputStream oos = new ObjectOutputStream(baos)) { |
| | | oos.writeObject(obj); |
| | | return baos.toByteArray(); |
| | | } |
| | | } |
| | | |
| | | // 字节数组反序列化为对象 |
| | | public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException { |
| | | try (ByteArrayInputStream bais = new ByteArrayInputStream(data); |
| | | ObjectInputStream ois = new ObjectInputStream(bais)) { |
| | | return ois.readObject(); |
| | | } |
| | | } |
| | | |
| | | } |