org.xson.web.util.SerializeUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xco-web Show documentation
Show all versions of xco-web Show documentation
xco-web is an easy to use control layer framework, is part of the SOA system, using xml language to describe the controller.
The newest version!
package org.xson.web.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.xson.web.XcoWebException;
public class SerializeUtil {
/**
* 序列化
*/
public static byte[] serialize(Object object) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
// oos.writ
byte[] bytes = baos.toByteArray();
baos.close();
baos.close();
return bytes;
} catch (Exception e) {
throw new XcoWebException(e);
}
}
/**
* 反序列化
*/
public static Object unserialize(byte[] bytes) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (Exception e) {
throw new XcoWebException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy