101 lines
3.9 KiB
Java
101 lines
3.9 KiB
Java
package com.thoughtworks.xstream.converters.collections;
|
|
|
|
import com.thoughtworks.xstream.converters.Converter;
|
|
import com.thoughtworks.xstream.converters.MarshallingContext;
|
|
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
|
import com.thoughtworks.xstream.core.util.Fields;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
|
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
|
import com.unity3d.ads.metadata.MediationMetaData;
|
|
import java.lang.reflect.Field;
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
import java.util.TreeMap;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class PropertiesConverter implements Converter {
|
|
static /* synthetic */ Class class$java$util$Properties;
|
|
private static final Field defaultsField;
|
|
private final boolean sort;
|
|
|
|
static {
|
|
Class cls = class$java$util$Properties;
|
|
if (cls == null) {
|
|
cls = class$("java.util.Properties");
|
|
class$java$util$Properties = cls;
|
|
}
|
|
Class cls2 = class$java$util$Properties;
|
|
if (cls2 == null) {
|
|
cls2 = class$("java.util.Properties");
|
|
class$java$util$Properties = cls2;
|
|
}
|
|
defaultsField = Fields.locate(cls, cls2, false);
|
|
}
|
|
|
|
public PropertiesConverter() {
|
|
this(false);
|
|
}
|
|
|
|
static /* synthetic */ Class class$(String str) {
|
|
try {
|
|
return Class.forName(str);
|
|
} catch (ClassNotFoundException e) {
|
|
throw new NoClassDefFoundError().initCause(e);
|
|
}
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.ConverterMatcher
|
|
public boolean canConvert(Class cls) {
|
|
Class cls2 = class$java$util$Properties;
|
|
if (cls2 == null) {
|
|
cls2 = class$("java.util.Properties");
|
|
class$java$util$Properties = cls2;
|
|
}
|
|
return cls2 == cls;
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) {
|
|
Properties properties;
|
|
Properties properties2 = (Properties) obj;
|
|
for (Map.Entry entry : (this.sort ? new TreeMap(properties2) : properties2).entrySet()) {
|
|
hierarchicalStreamWriter.startNode("property");
|
|
hierarchicalStreamWriter.addAttribute(MediationMetaData.KEY_NAME, entry.getKey().toString());
|
|
hierarchicalStreamWriter.addAttribute("value", entry.getValue().toString());
|
|
hierarchicalStreamWriter.endNode();
|
|
}
|
|
Field field = defaultsField;
|
|
if (field == null || (properties = (Properties) Fields.read(field, properties2)) == null) {
|
|
return;
|
|
}
|
|
hierarchicalStreamWriter.startNode("defaults");
|
|
marshal(properties, hierarchicalStreamWriter, marshallingContext);
|
|
hierarchicalStreamWriter.endNode();
|
|
}
|
|
|
|
@Override // com.thoughtworks.xstream.converters.Converter
|
|
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
|
Properties properties = new Properties();
|
|
Properties properties2 = null;
|
|
while (hierarchicalStreamReader.hasMoreChildren()) {
|
|
hierarchicalStreamReader.moveDown();
|
|
if (hierarchicalStreamReader.getNodeName().equals("defaults")) {
|
|
properties2 = (Properties) unmarshal(hierarchicalStreamReader, unmarshallingContext);
|
|
} else {
|
|
properties.setProperty(hierarchicalStreamReader.getAttribute(MediationMetaData.KEY_NAME), hierarchicalStreamReader.getAttribute("value"));
|
|
}
|
|
hierarchicalStreamReader.moveUp();
|
|
}
|
|
if (properties2 == null) {
|
|
return properties;
|
|
}
|
|
Properties properties3 = new Properties(properties2);
|
|
properties3.putAll(properties);
|
|
return properties3;
|
|
}
|
|
|
|
public PropertiesConverter(boolean z) {
|
|
this.sort = z;
|
|
}
|
|
}
|