package com.thoughtworks.xstream.converters.reflection; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.core.ClassLoaderReference; import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.ReferencingMarshallingContext; import com.thoughtworks.xstream.core.util.CustomObjectInputStream; import com.thoughtworks.xstream.core.util.CustomObjectOutputStream; import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.core.util.SerializationMembers; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.mapper.Mapper; import java.io.Externalizable; import java.io.IOException; import java.io.NotActiveException; import java.io.ObjectInputValidation; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Map; /* loaded from: classes.dex */ public class ExternalizableConverter implements Converter { static /* synthetic */ Class class$com$thoughtworks$xstream$converters$reflection$ExternalizableConverter; static /* synthetic */ Class class$java$io$Externalizable; private final ClassLoaderReference classLoaderReference; private Mapper mapper; private transient SerializationMembers serializationMembers; public ExternalizableConverter(Mapper mapper, ClassLoaderReference classLoaderReference) { this.mapper = mapper; this.classLoaderReference = classLoaderReference; this.serializationMembers = new SerializationMembers(); } static /* synthetic */ Class class$(String str) { try { return Class.forName(str); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError().initCause(e); } } private Object readResolve() { this.serializationMembers = new SerializationMembers(); return this; } @Override // com.thoughtworks.xstream.converters.ConverterMatcher public boolean canConvert(Class cls) { if (cls != null && JVM.canCreateDerivedObjectOutputStream()) { Class cls2 = class$java$io$Externalizable; if (cls2 == null) { cls2 = class$("java.io.Externalizable"); class$java$io$Externalizable = cls2; } if (cls2.isAssignableFrom(cls)) { return true; } } return false; } @Override // com.thoughtworks.xstream.converters.Converter public void marshal(Object obj, final HierarchicalStreamWriter hierarchicalStreamWriter, final MarshallingContext marshallingContext) { Object callWriteReplace = this.serializationMembers.callWriteReplace(obj); if (callWriteReplace != obj && (marshallingContext instanceof ReferencingMarshallingContext)) { ((ReferencingMarshallingContext) marshallingContext).replace(obj, callWriteReplace); } if (callWriteReplace.getClass() != obj.getClass()) { String aliasForSystemAttribute = this.mapper.aliasForSystemAttribute("resolves-to"); if (aliasForSystemAttribute != null) { hierarchicalStreamWriter.addAttribute(aliasForSystemAttribute, this.mapper.serializedClass(callWriteReplace.getClass())); } marshallingContext.convertAnother(callWriteReplace); return; } try { CustomObjectOutputStream customObjectOutputStream = CustomObjectOutputStream.getInstance(marshallingContext, new CustomObjectOutputStream.StreamCallback() { // from class: com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.1 @Override // com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback public void close() { throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutput.close() from writeExternal()"); } @Override // com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback public void defaultWriteObject() { throw new UnsupportedOperationException(); } @Override // com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback public void flush() { hierarchicalStreamWriter.flush(); } @Override // com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback public void writeFieldsToStream(Map map) { throw new UnsupportedOperationException(); } @Override // com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback public void writeToStream(Object obj2) { if (obj2 == null) { hierarchicalStreamWriter.startNode("null"); hierarchicalStreamWriter.endNode(); } else { ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, ExternalizableConverter.this.mapper.serializedClass(obj2.getClass()), obj2.getClass()); marshallingContext.convertAnother(obj2); hierarchicalStreamWriter.endNode(); } } }); ((Externalizable) callWriteReplace).writeExternal(customObjectOutputStream); customObjectOutputStream.popCallback(); } catch (IOException e) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("Cannot serialize "); stringBuffer.append(callWriteReplace.getClass().getName()); stringBuffer.append(" using Externalization"); throw new StreamException(stringBuffer.toString(), e); } } @Override // com.thoughtworks.xstream.converters.Converter public Object unmarshal(final HierarchicalStreamReader hierarchicalStreamReader, final UnmarshallingContext unmarshallingContext) { Class requiredType = unmarshallingContext.getRequiredType(); try { Constructor declaredConstructor = requiredType.getDeclaredConstructor(null); if (!declaredConstructor.isAccessible()) { declaredConstructor.setAccessible(true); } final Externalizable externalizable = (Externalizable) declaredConstructor.newInstance(null); CustomObjectInputStream customObjectInputStream = CustomObjectInputStream.getInstance(unmarshallingContext, new CustomObjectInputStream.StreamCallback() { // from class: com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.2 @Override // com.thoughtworks.xstream.core.util.CustomObjectInputStream.StreamCallback public void close() { throw new UnsupportedOperationException("Objects are not allowed to call ObjectInput.close() from readExternal()"); } @Override // com.thoughtworks.xstream.core.util.CustomObjectInputStream.StreamCallback public void defaultReadObject() { throw new UnsupportedOperationException(); } @Override // com.thoughtworks.xstream.core.util.CustomObjectInputStream.StreamCallback public Map readFieldsFromStream() { throw new UnsupportedOperationException(); } @Override // com.thoughtworks.xstream.core.util.CustomObjectInputStream.StreamCallback public Object readFromStream() { hierarchicalStreamReader.moveDown(); Object convertAnother = unmarshallingContext.convertAnother(externalizable, HierarchicalStreams.readClassType(hierarchicalStreamReader, ExternalizableConverter.this.mapper)); hierarchicalStreamReader.moveUp(); return convertAnother; } @Override // com.thoughtworks.xstream.core.util.CustomObjectInputStream.StreamCallback public void registerValidation(ObjectInputValidation objectInputValidation, int i) throws NotActiveException { throw new NotActiveException("stream inactive"); } }, this.classLoaderReference); externalizable.readExternal(customObjectInputStream); customObjectInputStream.popCallback(); return this.serializationMembers.callReadResolve(externalizable); } catch (IOException e) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("Cannot externalize "); stringBuffer.append(requiredType.getClass()); throw new StreamException(stringBuffer.toString(), e); } catch (ClassNotFoundException e2) { throw new ConversionException("Cannot construct type", e2); } catch (IllegalAccessException e3) { throw new ObjectAccessException("Cannot construct type", e3); } catch (InstantiationException e4) { throw new ConversionException("Cannot construct type", e4); } catch (NoSuchMethodException e5) { throw new ConversionException("Missing default constructor of type", e5); } catch (InvocationTargetException e6) { throw new ConversionException("Cannot construct type", e6); } } public ExternalizableConverter(Mapper mapper, ClassLoader classLoader) { this(mapper, new ClassLoaderReference(classLoader)); } /* JADX WARN: Illegal instructions before constructor call */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public ExternalizableConverter(com.thoughtworks.xstream.mapper.Mapper r2) { /* r1 = this; java.lang.Class r0 = com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.class$com$thoughtworks$xstream$converters$reflection$ExternalizableConverter if (r0 != 0) goto Lc java.lang.String r0 = "com.thoughtworks.xstream.converters.reflection.ExternalizableConverter" java.lang.Class r0 = class$(r0) com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.class$com$thoughtworks$xstream$converters$reflection$ExternalizableConverter = r0 Lc: java.lang.ClassLoader r0 = r0.getClassLoader() r1.(r2, r0) return */ throw new UnsupportedOperationException("Method not decompiled: com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.(com.thoughtworks.xstream.mapper.Mapper):void"); } }