846 lines
32 KiB
Java
846 lines
32 KiB
Java
package com.esotericsoftware.kryo.serializers;
|
|
|
|
import c.d.b.a.a;
|
|
import com.esotericsoftware.kryo.Kryo;
|
|
import com.esotericsoftware.kryo.KryoException;
|
|
import com.esotericsoftware.kryo.KryoSerializable;
|
|
import com.esotericsoftware.kryo.Registration;
|
|
import com.esotericsoftware.kryo.Serializer;
|
|
import com.esotericsoftware.kryo.io.Input;
|
|
import com.esotericsoftware.kryo.io.Output;
|
|
import com.esotericsoftware.kryo.util.Util;
|
|
import java.lang.reflect.Constructor;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigInteger;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.nio.charset.Charset;
|
|
import java.sql.Time;
|
|
import java.sql.Timestamp;
|
|
import java.util.Calendar;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Currency;
|
|
import java.util.Date;
|
|
import java.util.EnumSet;
|
|
import java.util.GregorianCalendar;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.TimeZone;
|
|
import java.util.TreeMap;
|
|
import java.util.TreeSet;
|
|
public class DefaultSerializers {
|
|
|
|
public static class BigDecimalSerializer extends Serializer<BigDecimal> {
|
|
private final BigIntegerSerializer bigIntegerSerializer = new BigIntegerSerializer();
|
|
|
|
public BigDecimalSerializer() {
|
|
setAcceptsNull(true);
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public BigDecimal read(Kryo kryo, Input input, Class<BigDecimal> cls) {
|
|
BigInteger read = this.bigIntegerSerializer.read(kryo, input, BigInteger.class);
|
|
if (read == null) {
|
|
return null;
|
|
}
|
|
int readInt = input.readInt(false);
|
|
if (cls == BigDecimal.class || cls == null) {
|
|
return (read == BigInteger.ZERO && readInt == 0) ? BigDecimal.ZERO : new BigDecimal(read, readInt);
|
|
}
|
|
try {
|
|
Constructor<BigDecimal> constructor = cls.getConstructor(BigInteger.class, Integer.TYPE);
|
|
if (!constructor.isAccessible()) {
|
|
try {
|
|
constructor.setAccessible(true);
|
|
} catch (SecurityException unused) {
|
|
}
|
|
}
|
|
return constructor.newInstance(read, Integer.valueOf(readInt));
|
|
} catch (Exception e) {
|
|
throw new KryoException(e);
|
|
}
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, BigDecimal bigDecimal) {
|
|
if (bigDecimal == null) {
|
|
output.writeVarInt(0, true);
|
|
} else if (bigDecimal == BigDecimal.ZERO) {
|
|
this.bigIntegerSerializer.write(kryo, output, BigInteger.ZERO);
|
|
output.writeInt(0, false);
|
|
} else {
|
|
this.bigIntegerSerializer.write(kryo, output, bigDecimal.unscaledValue());
|
|
output.writeInt(bigDecimal.scale(), false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class BigIntegerSerializer extends Serializer<BigInteger> {
|
|
public BigIntegerSerializer() {
|
|
setImmutable(true);
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public BigInteger read(Kryo kryo, Input input, Class<BigInteger> cls) {
|
|
int readVarInt = input.readVarInt(true);
|
|
if (readVarInt == 0) {
|
|
return null;
|
|
}
|
|
byte[] readBytes = input.readBytes(readVarInt - 1);
|
|
if (cls == BigInteger.class || cls == null) {
|
|
if (readVarInt == 2) {
|
|
byte b = readBytes[0];
|
|
if (b == 0) {
|
|
return BigInteger.ZERO;
|
|
}
|
|
if (b == 1) {
|
|
return BigInteger.ONE;
|
|
}
|
|
if (b == 10) {
|
|
return BigInteger.TEN;
|
|
}
|
|
}
|
|
return new BigInteger(readBytes);
|
|
}
|
|
try {
|
|
Constructor<BigInteger> constructor = cls.getConstructor(byte[].class);
|
|
if (!constructor.isAccessible()) {
|
|
try {
|
|
constructor.setAccessible(true);
|
|
} catch (SecurityException unused) {
|
|
}
|
|
}
|
|
return constructor.newInstance(readBytes);
|
|
} catch (Exception e) {
|
|
throw new KryoException(e);
|
|
}
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, BigInteger bigInteger) {
|
|
if (bigInteger == null) {
|
|
output.writeVarInt(0, true);
|
|
} else if (bigInteger == BigInteger.ZERO) {
|
|
output.writeVarInt(2, true);
|
|
output.writeByte(0);
|
|
} else {
|
|
byte[] byteArray = bigInteger.toByteArray();
|
|
output.writeVarInt(byteArray.length + 1, true);
|
|
output.writeBytes(byteArray);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class BooleanSerializer extends Serializer<Boolean> {
|
|
public BooleanSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Boolean read(Kryo kryo, Input input, Class<Boolean> cls) {
|
|
return Boolean.valueOf(input.readBoolean());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Boolean bool) {
|
|
output.writeBoolean(bool.booleanValue());
|
|
}
|
|
}
|
|
|
|
public static class ByteSerializer extends Serializer<Byte> {
|
|
public ByteSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Byte read(Kryo kryo, Input input, Class<Byte> cls) {
|
|
return Byte.valueOf(input.readByte());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Byte b) {
|
|
output.writeByte(b.byteValue());
|
|
}
|
|
}
|
|
|
|
public static class CalendarSerializer extends Serializer<Calendar> {
|
|
private static final long DEFAULT_GREGORIAN_CUTOVER = -12219292800000L;
|
|
public TimeZoneSerializer timeZoneSerializer = new TimeZoneSerializer();
|
|
|
|
public Calendar copy(Kryo kryo, Calendar calendar) {
|
|
return (Calendar) calendar.clone();
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Calendar read(Kryo kryo, Input input, Class<Calendar> cls) {
|
|
Calendar instance = Calendar.getInstance(this.timeZoneSerializer.read(kryo, input, TimeZone.class));
|
|
instance.setTimeInMillis(input.readLong(true));
|
|
instance.setLenient(input.readBoolean());
|
|
instance.setFirstDayOfWeek(input.readInt(true));
|
|
instance.setMinimalDaysInFirstWeek(input.readInt(true));
|
|
long readLong = input.readLong(false);
|
|
if (readLong != -12219292800000L && (instance instanceof GregorianCalendar)) {
|
|
((GregorianCalendar) instance).setGregorianChange(new Date(readLong));
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Calendar calendar) {
|
|
this.timeZoneSerializer.write(kryo, output, calendar.getTimeZone());
|
|
output.writeLong(calendar.getTimeInMillis(), true);
|
|
output.writeBoolean(calendar.isLenient());
|
|
output.writeInt(calendar.getFirstDayOfWeek(), true);
|
|
output.writeInt(calendar.getMinimalDaysInFirstWeek(), true);
|
|
if (calendar instanceof GregorianCalendar) {
|
|
output.writeLong(((GregorianCalendar) calendar).getGregorianChange().getTime(), false);
|
|
} else {
|
|
output.writeLong(-12219292800000L, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class CharSerializer extends Serializer<Character> {
|
|
public CharSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Character read(Kryo kryo, Input input, Class<Character> cls) {
|
|
return Character.valueOf(input.readChar());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Character ch) {
|
|
output.writeChar(ch.charValue());
|
|
}
|
|
}
|
|
|
|
public static class CharsetSerializer extends Serializer<Charset> {
|
|
public CharsetSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Charset read(Kryo kryo, Input input, Class<Charset> cls) {
|
|
return Charset.forName(input.readString());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Charset charset) {
|
|
output.writeString(charset.name());
|
|
}
|
|
}
|
|
|
|
public static class ClassSerializer extends Serializer<Class> {
|
|
public ClassSerializer() {
|
|
setImmutable(true);
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Class read(Kryo kryo, Input input, Class<Class> cls) {
|
|
Registration readClass = kryo.readClass(input);
|
|
int read = input.read();
|
|
Class type = readClass != null ? readClass.getType() : null;
|
|
return (type == null || !type.isPrimitive() || read == 1) ? type : Util.getWrapperClass(type);
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Class cls) {
|
|
kryo.writeClass(output, cls);
|
|
output.writeByte((cls == null || !cls.isPrimitive()) ? 0 : 1);
|
|
}
|
|
}
|
|
|
|
public static class CollectionsEmptyListSerializer extends Serializer {
|
|
public CollectionsEmptyListSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Object read(Kryo kryo, Input input, Class cls) {
|
|
return Collections.EMPTY_LIST;
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public void write(Kryo kryo, Output output, Object obj) {
|
|
}
|
|
}
|
|
|
|
public static class CollectionsEmptyMapSerializer extends Serializer {
|
|
public CollectionsEmptyMapSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Object read(Kryo kryo, Input input, Class cls) {
|
|
return Collections.EMPTY_MAP;
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public void write(Kryo kryo, Output output, Object obj) {
|
|
}
|
|
}
|
|
|
|
public static class CollectionsEmptySetSerializer extends Serializer {
|
|
public CollectionsEmptySetSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Object read(Kryo kryo, Input input, Class cls) {
|
|
return Collections.EMPTY_SET;
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public void write(Kryo kryo, Output output, Object obj) {
|
|
}
|
|
}
|
|
|
|
public static class CollectionsSingletonListSerializer extends Serializer<List> {
|
|
public CollectionsSingletonListSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [com.esotericsoftware.kryo.Kryo, com.esotericsoftware.kryo.io.Input, java.lang.Class] */
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public List read(Kryo kryo, Input input, Class<List> cls) {
|
|
return Collections.singletonList(kryo.readClassAndObject(input));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, List list) {
|
|
kryo.writeClassAndObject(output, list.get(0));
|
|
}
|
|
}
|
|
|
|
public static class CollectionsSingletonMapSerializer extends Serializer<Map> {
|
|
public CollectionsSingletonMapSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [com.esotericsoftware.kryo.Kryo, com.esotericsoftware.kryo.io.Input, java.lang.Class] */
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Map read(Kryo kryo, Input input, Class<Map> cls) {
|
|
return Collections.singletonMap(kryo.readClassAndObject(input), kryo.readClassAndObject(input));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Map map) {
|
|
Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
|
|
kryo.writeClassAndObject(output, entry.getKey());
|
|
kryo.writeClassAndObject(output, entry.getValue());
|
|
}
|
|
}
|
|
|
|
public static class CollectionsSingletonSetSerializer extends Serializer<Set> {
|
|
public CollectionsSingletonSetSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [com.esotericsoftware.kryo.Kryo, com.esotericsoftware.kryo.io.Input, java.lang.Class] */
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Set read(Kryo kryo, Input input, Class<Set> cls) {
|
|
return Collections.singleton(kryo.readClassAndObject(input));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Set set) {
|
|
kryo.writeClassAndObject(output, set.iterator().next());
|
|
}
|
|
}
|
|
|
|
public static class CurrencySerializer extends Serializer<Currency> {
|
|
public CurrencySerializer() {
|
|
setImmutable(true);
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Currency read(Kryo kryo, Input input, Class<Currency> cls) {
|
|
String readString = input.readString();
|
|
if (readString == null) {
|
|
return null;
|
|
}
|
|
return Currency.getInstance(readString);
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Currency currency) {
|
|
output.writeString(currency == null ? null : currency.getCurrencyCode());
|
|
}
|
|
}
|
|
|
|
public static class DateSerializer extends Serializer<Date> {
|
|
private Date create(Kryo kryo, Class<? extends Date> cls, long j) throws KryoException {
|
|
if (cls == Date.class || cls == null) {
|
|
return new Date(j);
|
|
}
|
|
if (cls == Timestamp.class) {
|
|
return new Timestamp(j);
|
|
}
|
|
if (cls == java.sql.Date.class) {
|
|
return new java.sql.Date(j);
|
|
}
|
|
if (cls == Time.class) {
|
|
return new Time(j);
|
|
}
|
|
try {
|
|
Constructor<? extends Date> constructor = cls.getConstructor(Long.TYPE);
|
|
if (!constructor.isAccessible()) {
|
|
try {
|
|
constructor.setAccessible(true);
|
|
} catch (SecurityException unused) {
|
|
}
|
|
}
|
|
return (Date) constructor.newInstance(Long.valueOf(j));
|
|
} catch (Exception unused2) {
|
|
Date date = (Date) kryo.newInstance(cls);
|
|
date.setTime(j);
|
|
return date;
|
|
}
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.esotericsoftware.kryo.serializers.DefaultSerializers$DateSerializer */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public Date copy(Kryo kryo, Date date) {
|
|
return create(kryo, date.getClass(), date.getTime());
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Date read(Kryo kryo, Input input, Class<Date> cls) {
|
|
return create(kryo, cls, input.readLong(true));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Date date) {
|
|
output.writeLong(date.getTime(), true);
|
|
}
|
|
}
|
|
|
|
public static class DoubleSerializer extends Serializer<Double> {
|
|
public DoubleSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Double read(Kryo kryo, Input input, Class<Double> cls) {
|
|
return Double.valueOf(input.readDouble());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Double d) {
|
|
output.writeDouble(d.doubleValue());
|
|
}
|
|
}
|
|
|
|
public static class EnumSerializer extends Serializer<Enum> {
|
|
private Object[] enumConstants;
|
|
|
|
public EnumSerializer(Class<? extends Enum> cls) {
|
|
setImmutable(true);
|
|
setAcceptsNull(true);
|
|
Object[] enumConstants = cls.getEnumConstants();
|
|
this.enumConstants = enumConstants;
|
|
if (enumConstants == null && !Enum.class.equals(cls)) {
|
|
throw new IllegalArgumentException("The type must be an enum: " + cls);
|
|
}
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Enum read(Kryo kryo, Input input, Class<Enum> cls) {
|
|
int readVarInt = input.readVarInt(true);
|
|
if (readVarInt == 0) {
|
|
return null;
|
|
}
|
|
int i = readVarInt - 1;
|
|
if (i >= 0) {
|
|
Object[] objArr = this.enumConstants;
|
|
if (i <= objArr.length - 1) {
|
|
return (Enum) objArr[i];
|
|
}
|
|
}
|
|
StringBuilder L = a.L("Invalid ordinal for enum \"");
|
|
L.append(cls.getName());
|
|
L.append("\": ");
|
|
L.append(i);
|
|
throw new KryoException(L.toString());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Enum r3) {
|
|
if (r3 == null) {
|
|
output.writeVarInt(0, true);
|
|
} else {
|
|
output.writeVarInt(r3.ordinal() + 1, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class EnumSetSerializer extends Serializer<EnumSet> {
|
|
public EnumSet copy(Kryo kryo, EnumSet enumSet) {
|
|
return EnumSet.copyOf(enumSet);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public EnumSet read(Kryo kryo, Input input, Class<EnumSet> cls) {
|
|
Registration readClass = kryo.readClass(input);
|
|
EnumSet noneOf = EnumSet.noneOf(readClass.getType());
|
|
Serializer serializer = readClass.getSerializer();
|
|
int readInt = input.readInt(true);
|
|
for (int i = 0; i < readInt; i++) {
|
|
noneOf.add(serializer.read(kryo, input, null));
|
|
}
|
|
return noneOf;
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, EnumSet enumSet) {
|
|
Serializer serializer;
|
|
if (enumSet.isEmpty()) {
|
|
EnumSet complementOf = EnumSet.complementOf(enumSet);
|
|
if (!complementOf.isEmpty()) {
|
|
serializer = kryo.writeClass(output, complementOf.iterator().next().getClass()).getSerializer();
|
|
} else {
|
|
throw new KryoException("An EnumSet must have a defined Enum to be serialized.");
|
|
}
|
|
} else {
|
|
serializer = kryo.writeClass(output, enumSet.iterator().next().getClass()).getSerializer();
|
|
}
|
|
output.writeInt(enumSet.size(), true);
|
|
Iterator it = enumSet.iterator();
|
|
while (it.hasNext()) {
|
|
serializer.write(kryo, output, it.next());
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class FloatSerializer extends Serializer<Float> {
|
|
public FloatSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Float read(Kryo kryo, Input input, Class<Float> cls) {
|
|
return Float.valueOf(input.readFloat());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Float f) {
|
|
output.writeFloat(f.floatValue());
|
|
}
|
|
}
|
|
|
|
public static class IntSerializer extends Serializer<Integer> {
|
|
public IntSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Integer read(Kryo kryo, Input input, Class<Integer> cls) {
|
|
return Integer.valueOf(input.readInt(false));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Integer num) {
|
|
output.writeInt(num.intValue(), false);
|
|
}
|
|
}
|
|
|
|
public static class KryoSerializableSerializer extends Serializer<KryoSerializable> {
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public KryoSerializable read(Kryo kryo, Input input, Class<KryoSerializable> cls) {
|
|
KryoSerializable kryoSerializable = (KryoSerializable) kryo.newInstance(cls);
|
|
kryo.reference(kryoSerializable);
|
|
kryoSerializable.read(kryo, input);
|
|
return kryoSerializable;
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, KryoSerializable kryoSerializable) {
|
|
kryoSerializable.write(kryo, output);
|
|
}
|
|
}
|
|
|
|
public static class LocaleSerializer extends Serializer<Locale> {
|
|
public static final Locale SPAIN = new Locale("es", "ES", "");
|
|
public static final Locale SPANISH = new Locale("es", "", "");
|
|
|
|
public LocaleSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
public static boolean isSameLocale(Locale locale, String str, String str2, String str3) {
|
|
try {
|
|
return locale.getLanguage().equals(str) && locale.getCountry().equals(str2) && locale.getVariant().equals(str3);
|
|
} catch (NullPointerException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public Locale create(String str, String str2, String str3) {
|
|
Locale locale = Locale.getDefault();
|
|
if (isSameLocale(locale, str, str2, str3)) {
|
|
return locale;
|
|
}
|
|
Locale locale2 = Locale.US;
|
|
if (locale != locale2 && isSameLocale(locale2, str, str2, str3)) {
|
|
return locale2;
|
|
}
|
|
Locale locale3 = Locale.ENGLISH;
|
|
if (isSameLocale(locale3, str, str2, str3)) {
|
|
return locale3;
|
|
}
|
|
if (isSameLocale(Locale.GERMAN, str, str2, str3)) {
|
|
return Locale.GERMAN;
|
|
}
|
|
Locale locale4 = SPANISH;
|
|
if (isSameLocale(locale4, str, str2, str3)) {
|
|
return locale4;
|
|
}
|
|
if (isSameLocale(Locale.FRENCH, str, str2, str3)) {
|
|
return Locale.FRENCH;
|
|
}
|
|
if (isSameLocale(Locale.ITALIAN, str, str2, str3)) {
|
|
return Locale.ITALIAN;
|
|
}
|
|
if (isSameLocale(Locale.JAPANESE, str, str2, str3)) {
|
|
return Locale.JAPANESE;
|
|
}
|
|
if (isSameLocale(Locale.KOREAN, str, str2, str3)) {
|
|
return Locale.KOREAN;
|
|
}
|
|
if (isSameLocale(Locale.SIMPLIFIED_CHINESE, str, str2, str3)) {
|
|
return Locale.SIMPLIFIED_CHINESE;
|
|
}
|
|
if (isSameLocale(Locale.CHINESE, str, str2, str3)) {
|
|
return Locale.CHINESE;
|
|
}
|
|
if (isSameLocale(Locale.TRADITIONAL_CHINESE, str, str2, str3)) {
|
|
return Locale.TRADITIONAL_CHINESE;
|
|
}
|
|
if (isSameLocale(Locale.UK, str, str2, str3)) {
|
|
return Locale.UK;
|
|
}
|
|
if (isSameLocale(Locale.GERMANY, str, str2, str3)) {
|
|
return Locale.GERMANY;
|
|
}
|
|
Locale locale5 = SPAIN;
|
|
return isSameLocale(locale5, str, str2, str3) ? locale5 : isSameLocale(Locale.FRANCE, str, str2, str3) ? Locale.FRANCE : isSameLocale(Locale.ITALY, str, str2, str3) ? Locale.ITALY : isSameLocale(Locale.JAPAN, str, str2, str3) ? Locale.JAPAN : isSameLocale(Locale.KOREA, str, str2, str3) ? Locale.KOREA : isSameLocale(Locale.CANADA, str, str2, str3) ? Locale.CANADA : isSameLocale(Locale.CANADA_FRENCH, str, str2, str3) ? Locale.CANADA_FRENCH : new Locale(str, str2, str3);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Locale read(Kryo kryo, Input input, Class<Locale> cls) {
|
|
return create(input.readString(), input.readString(), input.readString());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Locale locale) {
|
|
output.writeAscii(locale.getLanguage());
|
|
output.writeAscii(locale.getCountry());
|
|
output.writeString(locale.getVariant());
|
|
}
|
|
}
|
|
|
|
public static class LongSerializer extends Serializer<Long> {
|
|
public LongSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Long read(Kryo kryo, Input input, Class<Long> cls) {
|
|
return Long.valueOf(input.readLong(false));
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Long l) {
|
|
output.writeLong(l.longValue(), false);
|
|
}
|
|
}
|
|
|
|
public static class ShortSerializer extends Serializer<Short> {
|
|
public ShortSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Short read(Kryo kryo, Input input, Class<Short> cls) {
|
|
return Short.valueOf(input.readShort());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, Short sh) {
|
|
output.writeShort(sh.shortValue());
|
|
}
|
|
}
|
|
|
|
public static class StringBufferSerializer extends Serializer<StringBuffer> {
|
|
public StringBufferSerializer() {
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
public StringBuffer copy(Kryo kryo, StringBuffer stringBuffer) {
|
|
return new StringBuffer(stringBuffer);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public StringBuffer read(Kryo kryo, Input input, Class<StringBuffer> cls) {
|
|
String readString = input.readString();
|
|
if (readString == null) {
|
|
return null;
|
|
}
|
|
return new StringBuffer(readString);
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, StringBuffer stringBuffer) {
|
|
output.writeString(stringBuffer);
|
|
}
|
|
}
|
|
|
|
public static class StringBuilderSerializer extends Serializer<StringBuilder> {
|
|
public StringBuilderSerializer() {
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
public StringBuilder copy(Kryo kryo, StringBuilder sb) {
|
|
return new StringBuilder(sb);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public StringBuilder read(Kryo kryo, Input input, Class<StringBuilder> cls) {
|
|
return input.readStringBuilder();
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, StringBuilder sb) {
|
|
output.writeString(sb);
|
|
}
|
|
}
|
|
|
|
public static class StringSerializer extends Serializer<String> {
|
|
public StringSerializer() {
|
|
setImmutable(true);
|
|
setAcceptsNull(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public String read(Kryo kryo, Input input, Class<String> cls) {
|
|
return input.readString();
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, String str) {
|
|
output.writeString(str);
|
|
}
|
|
}
|
|
|
|
public static class TimeZoneSerializer extends Serializer<TimeZone> {
|
|
public TimeZoneSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public TimeZone read(Kryo kryo, Input input, Class<TimeZone> cls) {
|
|
return TimeZone.getTimeZone(input.readString());
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, TimeZone timeZone) {
|
|
output.writeString(timeZone.getID());
|
|
}
|
|
}
|
|
|
|
public static class TreeMapSerializer extends MapSerializer {
|
|
private TreeMap createTreeMap(Class<? extends Map> cls, Comparator comparator) {
|
|
if (cls == TreeMap.class || cls == null) {
|
|
return new TreeMap(comparator);
|
|
}
|
|
try {
|
|
Constructor<? extends Map> constructor = cls.getConstructor(Comparator.class);
|
|
if (!constructor.isAccessible()) {
|
|
try {
|
|
constructor.setAccessible(true);
|
|
} catch (SecurityException unused) {
|
|
}
|
|
}
|
|
return (TreeMap) constructor.newInstance(comparator);
|
|
} catch (Exception e) {
|
|
throw new KryoException(e);
|
|
}
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.serializers.MapSerializer
|
|
public Map create(Kryo kryo, Input input, Class<Map> cls) {
|
|
return createTreeMap(cls, (Comparator) kryo.readClassAndObject(input));
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.esotericsoftware.kryo.serializers.DefaultSerializers$TreeMapSerializer */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.esotericsoftware.kryo.serializers.MapSerializer
|
|
public Map createCopy(Kryo kryo, Map map) {
|
|
return createTreeMap(map.getClass(), ((TreeMap) map).comparator());
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.serializers.MapSerializer
|
|
public void write(Kryo kryo, Output output, Map map) {
|
|
kryo.writeClassAndObject(output, ((TreeMap) map).comparator());
|
|
super.write(kryo, output, map);
|
|
}
|
|
}
|
|
|
|
public static class TreeSetSerializer extends CollectionSerializer {
|
|
private TreeSet createTreeSet(Class<? extends Collection> cls, Comparator comparator) {
|
|
if (cls == TreeSet.class || cls == null) {
|
|
return new TreeSet(comparator);
|
|
}
|
|
try {
|
|
Constructor<? extends Collection> constructor = cls.getConstructor(Comparator.class);
|
|
if (!constructor.isAccessible()) {
|
|
try {
|
|
constructor.setAccessible(true);
|
|
} catch (SecurityException unused) {
|
|
}
|
|
}
|
|
return (TreeSet) constructor.newInstance(comparator);
|
|
} catch (Exception e) {
|
|
throw new KryoException(e);
|
|
}
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.serializers.CollectionSerializer
|
|
public TreeSet create(Kryo kryo, Input input, Class<Collection> cls) {
|
|
return createTreeSet(cls, (Comparator) kryo.readClassAndObject(input));
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.esotericsoftware.kryo.serializers.DefaultSerializers$TreeSetSerializer */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.esotericsoftware.kryo.serializers.CollectionSerializer
|
|
public TreeSet createCopy(Kryo kryo, Collection collection) {
|
|
return createTreeSet(collection.getClass(), ((TreeSet) collection).comparator());
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.serializers.CollectionSerializer
|
|
public void write(Kryo kryo, Output output, Collection collection) {
|
|
kryo.writeClassAndObject(output, ((TreeSet) collection).comparator());
|
|
super.write(kryo, output, collection);
|
|
}
|
|
}
|
|
|
|
public static class URLSerializer extends Serializer<URL> {
|
|
public URLSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public URL read(Kryo kryo, Input input, Class<URL> cls) {
|
|
try {
|
|
return new URL(input.readString());
|
|
} catch (MalformedURLException e) {
|
|
throw new KryoException(e);
|
|
}
|
|
}
|
|
|
|
public void write(Kryo kryo, Output output, URL url) {
|
|
output.writeString(url.toExternalForm());
|
|
}
|
|
}
|
|
|
|
public static class VoidSerializer extends Serializer {
|
|
public VoidSerializer() {
|
|
setImmutable(true);
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public Object read(Kryo kryo, Input input, Class cls) {
|
|
return null;
|
|
}
|
|
|
|
@Override // com.esotericsoftware.kryo.Serializer
|
|
public void write(Kryo kryo, Output output, Object obj) {
|
|
}
|
|
}
|
|
}
|