mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-19 03:47:49 +08:00
32 lines
902 B
Java
32 lines
902 B
Java
package com.genersoft.iot.vmp.utils;
|
|
|
|
import java.io.*;
|
|
|
|
public class SerializeUtils {
|
|
public static byte[] serialize(Object obj){
|
|
byte[] bytes = null;
|
|
try {
|
|
ByteArrayOutputStream baos=new ByteArrayOutputStream();;
|
|
ObjectOutputStream oos=new ObjectOutputStream(baos);
|
|
oos.writeObject(obj);
|
|
bytes=baos.toByteArray();
|
|
baos.close();
|
|
oos.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return bytes;
|
|
}
|
|
public static Object deSerialize(byte[] bytes){
|
|
Object obj=null;
|
|
try {
|
|
ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
|
|
ObjectInputStream ois=new ObjectInputStream(bais);
|
|
obj=ois.readObject();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return obj;
|
|
}
|
|
}
|