package net.java.amateras.xstream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import com.thoughtworks.xstream.XStream;
public class XStreamSerializer {
public static String serialize(Object obj, ClassLoader loader){
XStream xstream = new XStream();
xstream.setClassLoader(loader);
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xstream.toXML(obj);
}
public static InputStream serializeStream(Object obj, ClassLoader loader) throws UnsupportedEncodingException {
String xml = serialize(obj, loader);
return new ByteArrayInputStream(xml.getBytes("UTF-8"));
}
public static Object deserialize(String xml, ClassLoader loader){
XStream xstream = new XStream();
xstream.setClassLoader(loader);
return xstream.fromXML(xml);
}
public static Object deserialize(Reader reader, ClassLoader loader){
XStream xstream = new XStream();
xstream.setClassLoader(loader);
return xstream.fromXML(reader);
}
public static Object deserialize(InputStream in, ClassLoader loader) throws UnsupportedEncodingException {
XStream xstream = new XStream();
xstream.setClassLoader(loader);
return xstream.fromXML(new InputStreamReader(in, "UTF-8"));
}
}
猿人林克
- 粉丝: 1441
- 资源: 13
最新资源
- 城镇老旧小区改造(加装电梯)考评内容和评价标准表.docx
- 城镇老旧小区改造及既有住宅加装电梯赋分权重.docx
- 底板隐蔽前监理检查记录.docx
- 出差审批单(表格模板).docx
- 第三方技术服务机构消防验收项目情况工作月汇报表.docx
- 电梯质量安全风险管控清单(安装(含修理).docx
- 飞机舱位代码表.docx
- 顶板隐蔽前监理检查记录表.docx
- 高危妊娠产前评分标准表.docx
- 高温中暑病例报告卡表格.docx
- 个体工商户营业执照颁发及归档记录表.doc
- 更换输液流程表.docx
- 公务接待审批单(表格模板).docx
- 古今地名对照表.docx
- 固定资产验收单、移交清单、处置清单.docx
- 骨关节损伤鉴定标准条款表.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页