本文整理汇总了Java中com.esotericsoftware.kryo.KryoSerializable类的典型用法代码示例。如果您正苦于以下问题:Java KryoSerializable类的具体用法?Java KryoSerializable怎么用?Java KryoSerializable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KryoSerializable类属于com.esotericsoftware.kryo包,在下文中一共展示了KryoSerializable类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadData
import com.esotericsoftware.kryo.KryoSerializable; //导入依赖的package包/类
private int loadData(InputStream in) {
Input kryoIn = new Input(in);
int size = kryoIn.readInt();
for (int i = 0; i < size; i++) {
String key = kryoIn.readString();
Class c = kryo.readClass(kryoIn).getType();
Object v;
if (KryoSerializable.class.isAssignableFrom(c)) {
v = new DefaultSerializers.KryoSerializableSerializer().read(kryo, kryoIn, c);
} else {
v = kryo.readClassAndObject(kryoIn);
}
dataRef.put(key, v);
}
kryoIn.close();
return kryoIn.total();
}
示例2: getValueType
import com.esotericsoftware.kryo.KryoSerializable; //导入依赖的package包/类
public static ValueType getValueType(Object o) {
if (o == null) {
return ValueType.NULL;
} else if (o instanceof Boolean) {
return ValueType.BOOLEAN;
} else if (o instanceof String) {
return ValueType.STRING;
} else if (o instanceof Byte) {
return ValueType.BYTE;
} else if (o instanceof Short) {
return ValueType.SHORT;
} else if (o instanceof Integer) {
return ValueType.INT;
} else if (o instanceof Long) {
return ValueType.LONG;
} else if (o instanceof Float) {
return ValueType.FLOAT;
} else if (o instanceof Double) {
return ValueType.DOUBLE;
} else if (o instanceof BigDecimal) {
return ValueType.DECIMAL;
} else if (o instanceof LocalDate) {
return ValueType.DATE;
} else if (o instanceof LocalTime) {
return ValueType.TIME;
} else if (o instanceof LocalDateTime) {
return ValueType.TIMESTAMP;
} else if (o instanceof Duration) {
return ValueType.INTERVAL;
} else if (o instanceof byte[]) {
return ValueType.BINARY;
} else if (o instanceof Enum) {
return ValueType.ENUM;
} else if (o instanceof UUID) {
return ValueType.UUID;
} else if (o instanceof KryoSerializable) {
return ValueType.KRYO_SERIALIZABLE;
} else if (o instanceof Serializable) {
return ValueType.SERIALIZABLE;
} else {
throw new IllegalArgumentException("Unexpected data of type : " + o.getClass().getName());
}
}
示例3: write
import com.esotericsoftware.kryo.KryoSerializable; //导入依赖的package包/类
public void write (Kryo kryo, Output output, KryoSerializable object) {
object.write(kryo, output);
}
示例4: read
import com.esotericsoftware.kryo.KryoSerializable; //导入依赖的package包/类
public KryoSerializable read (Kryo kryo, Input input, Class<KryoSerializable> type) {
KryoSerializable object = kryo.newInstance(type);
kryo.reference(object);
object.read(kryo, input);
return object;
}
示例5: initialValue
import com.esotericsoftware.kryo.KryoSerializable; //导入依赖的package包/类
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.register(byte[].class);
kryo.register(char[].class);
kryo.register(short[].class);
kryo.register(int[].class);
kryo.register(long[].class);
kryo.register(float[].class);
kryo.register(double[].class);
kryo.register(boolean[].class);
kryo.register(String[].class);
kryo.register(Object[].class);
kryo.register(KryoSerializable.class);
kryo.register(BigInteger.class);
kryo.register(BigDecimal.class);
kryo.register(Class.class);
kryo.register(Date.class);
//kryo.register(Enum.class);
kryo.register(EnumSet.class);
kryo.register(Currency.class);
kryo.register(StringBuffer.class);
kryo.register(StringBuilder.class);
kryo.register(Collections.EMPTY_LIST.getClass());
kryo.register(Collections.EMPTY_MAP.getClass());
kryo.register(Collections.EMPTY_SET.getClass());
kryo.register(Collections.singletonList(null).getClass());
kryo.register(Collections.singletonMap(null, null).getClass());
kryo.register(Collections.singleton(null).getClass());
kryo.register(TreeSet.class);
kryo.register(Collection.class);
kryo.register(TreeMap.class);
kryo.register(Map.class);
try {
kryo.register(Class.forName("sun.util.calendar.ZoneInfo"));
} catch (ClassNotFoundException e) {
//Noop
}
kryo.register(Calendar.class);
kryo.register(Locale.class);
kryo.register(BitSet.class);
kryo.register(HashMap.class);
kryo.register(Timestamp.class);
kryo.register(ArrayList.class);
int size = idList.size();
for (int i = 0; i < size; i++) {
kryo.register(classList
.get(i),
serializerList
.get(i),
idList.get(i));
}
kryo.setRegistrationRequired(true);
kryo.setReferences(false);
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}