package com.thoughtworks.xstream.converters.collections; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Iterator; /* loaded from: classes.dex */ public class ArrayConverter extends AbstractCollectionConverter { public ArrayConverter(Mapper mapper) { super(mapper); } @Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.ConverterMatcher public boolean canConvert(Class cls) { return cls != null && cls.isArray(); } @Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.Converter public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { int length = Array.getLength(obj); for (int i = 0; i < length; i++) { writeCompleteItem(Array.get(obj, i), marshallingContext, hierarchicalStreamWriter); } } @Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.Converter public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { ArrayList arrayList = new ArrayList(); while (hierarchicalStreamReader.hasMoreChildren()) { arrayList.add(readCompleteItem(hierarchicalStreamReader, unmarshallingContext, null)); } Object newInstance = Array.newInstance(unmarshallingContext.getRequiredType().getComponentType(), arrayList.size()); int i = 0; Iterator it = arrayList.iterator(); while (it.hasNext()) { Array.set(newInstance, i, it.next()); i++; } return newInstance; } }