Initial commit
This commit is contained in:
52
sources/com/ubt/jimu/controller/util/XmlUtils.java
Normal file
52
sources/com/ubt/jimu/controller/util/XmlUtils.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.ubt.jimu.controller.util;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.naming.NoNameCoder;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class XmlUtils {
|
||||
public static Object a(Class cls, String str) {
|
||||
File file = new File(str);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
XStream xStream = new XStream(new FieldDefaultProvider());
|
||||
xStream.ignoreUnknownElements();
|
||||
xStream.processAnnotations(cls);
|
||||
try {
|
||||
return xStream.fromXML(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
XLog.b("XmlUtils", "xml parse exception msg: %s", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void a(Object obj, String str) {
|
||||
ALog.a("XmlUtils").d("saveXml");
|
||||
File file = new File(str);
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
try {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
try {
|
||||
XStream xStream = new XStream(new DomDriver("UTF-8", new NoNameCoder()));
|
||||
xStream.processAnnotations(obj.getClass());
|
||||
xStream.setMode(1001);
|
||||
xStream.toXML(obj, fileOutputStream);
|
||||
fileOutputStream.close();
|
||||
} finally {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user