fun.bigtable.kraken.util.SerializeUtils Maven / Gradle / Ivy
package fun.bigtable.kraken.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class SerializeUtils {
public static byte[] serialize(Object object) {
ObjectOutputStream objectOutputStream = null;
ByteArrayOutputStream byteArrayOutputStream = null;
try {
// 序列化
byteArrayOutputStream = new ByteArrayOutputStream();
objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(object);
return byteArrayOutputStream.toByteArray();
} catch (Exception ignored) {
}
return null;
}
public static Object unSerialize(byte[] bytes) {
if (bytes==null) {
return null;
}
ByteArrayInputStream byteArrayInputStream;
try {
// 反序列化
byteArrayInputStream = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(byteArrayInputStream);
return ois.readObject();
} catch (Exception ignored) {
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy