public static byte[] objectToXml(Object obj,ClassLoader cl){
if(cl == null){ return objectToXml(obj); }
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLEncoder xml = new XMLEncoder(bos);
//HACK
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
if (cl != oldLoader && cl != null){
try{
Thread.currentThread().setContextClassLoader(cl);
xml.writeObject(obj);
}catch(Exception e){e.printStackTrace();}
finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}else{
xml.writeObject(obj);
}
xml.close();
return bos.toByteArray();
}
FileUtils.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:Ultraino
作者:
评论列表
文章目录