本文整理了Java中com.esotericsoftware.kryo.Registration
类的一些代码示例,展示了Registration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registration
类的具体详情如下:
包路径:com.esotericsoftware.kryo.Registration
类名称:Registration
[英]Describes the Serializer and class ID to use for a class.
[中]描述用于类的序列化程序和类ID。
代码示例来源:origin: EsotericSoftware/kryonet
public void read (Kryo kryo, Input input) {
objectID = input.readInt(true);
int methodClassID = input.readInt(true);
Class methodClass = kryo.getRegistration(methodClassID).getType();
byte methodIndex = input.readByte();
try {
cachedMethod = getMethods(kryo, methodClass)[methodIndex];
} catch (IndexOutOfBoundsException ex) {
throw new KryoException("Invalid method index " + methodIndex + " for class: " + methodClass.getName());
}
Serializer[] serializers = cachedMethod.serializers;
Class[] parameterTypes = cachedMethod.method.getParameterTypes();
Object[] args = new Object[serializers.length];
this.args = args;
for (int i = 0, n = args.length; i < n; i++) {
Serializer serializer = serializers[i];
if (serializer != null)
args[i] = kryo.readObjectOrNull(input, parameterTypes[i], serializer);
else
args[i] = kryo.readClassAndObject(input);
}
responseData = input.readByte();
}
}
代码示例来源:origin: atomix/atomix
Registration existing = kryo.getRegistration(id);
if (existing != null) {
boolean matches = false;
for (Class<?> type : types) {
if (existing.getType() == type) {
matches = true;
break;
friendlyName(), types, id, existing.getType());
Arrays.toString(types), id, existing.getType()));
Registration r = null;
if (serializer == null) {
r = kryo.register(type, id);
} else if (type.isInterface()) {
kryo.addDefaultSerializer(type, serializer);
} else {
r = kryo.register(type, serializer, id);
if (r.getId() != id) {
LOGGER.debug("{}: {} already registered as {}. Skipping {}.",
friendlyName(), r.getType(), r.getId(), id);
LOGGER.trace("{} registered as {}", r.getType(), r.getId());
代码示例来源:origin: spring-projects/spring-integration
@Override
public List<Registration> getRegistrations() {
return Collections.singletonList(new Registration(File.class, this.fileSerializer, this.registrationId));
}
代码示例来源:origin: stackoverflow.com
jButtonAgree.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Registration reg = new Registration(); // **** HERE *****
LayoutManager cards = reg.getCards().getLayout();
((CardLayout) cards).show(reg.getCards(),"step1");
}
});
代码示例来源:origin: stackoverflow.com
Registration registration = new Registration();
ButtonPanel buttonPanel = new ButtonPanel();
buttonPanel.setRegistration(registration);
registration.setBorder(BorderFactory.createTitledBorder("Registration Panel"));
代码示例来源:origin: com.esotericsoftware/kryo
public Object[] read (Kryo kryo, Input input, Class<Object[]> type) {
int length = input.readVarInt(true);
if (length == NULL) return null;
Object[] object = (Object[])Array.newInstance(type.getComponentType(), length - 1);
kryo.reference(object);
Class elementClass = object.getClass().getComponentType();
if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers())) {
Serializer elementSerializer = kryo.getSerializer(elementClass);
elementSerializer.setGenerics(kryo, generics);
for (int i = 0, n = object.length; i < n; i++) {
if (elementsCanBeNull)
object[i] = kryo.readObjectOrNull(input, elementClass, elementSerializer);
else
object[i] = kryo.readObject(input, elementClass, elementSerializer);
Registration registration = kryo.readClass(input);
if (registration != null) {
registration.getSerializer().setGenerics(kryo, generics);
object[i] = kryo.readObject(input, registration.getType(), registration.getSerializer());
} else {
object[i] = null;
代码示例来源:origin: com.esotericsoftware/kryo
public void read (Input input, Object object) {
try {
if (TRACE) trace("kryo", "Read field: " + this + " (" + type.getName() + ")" + " pos=" + input.position());
Object value;
Serializer serializer = this.serializer;
if (concreteType == null) {
Registration registration = kryo.readClass(input);
if (registration == null)
value = null;
else {
if (serializer == null) serializer = registration.getSerializer();
serializer.setGenerics(kryo, generics);
value = kryo.readObject(input, registration.getType(), serializer);
if (serializer == null) this.serializer = serializer = kryo.getSerializer(valueClass);
serializer.setGenerics(kryo, generics);
if (canBeNull)
value = kryo.readObjectOrNull(input, concreteType, serializer);
代码示例来源:origin: inspectIT/inspectIT
@Override
public void write(Kryo kryo, Output output) {
output.writeInt(objectID, true);
int methodClassID = kryo.getRegistration(method.getDeclaringClass()).getId();
output.writeInt(methodClassID, true);
CachedMethod[] cachedMethods = getMethods(kryo, method.getDeclaringClass());
CachedMethod cachedMethod = null;
for (int i = 0, n = cachedMethods.length; i < n; i++) {
cachedMethod = cachedMethods[i];
if (cachedMethod.method.equals(method)) {
output.writeByte(i);
break;
}
}
for (int i = 0, n = cachedMethod.serializers.length; i < n; i++) {
Serializer serializer = cachedMethod.serializers[i];
if (serializer != null) {
kryo.writeObjectOrNull(output, args[i], serializer);
} else {
kryo.writeClassAndObject(output, args[i]);
}
}
output.writeByte(responseID);
}
代码示例来源:origin: org.no-hope/serialization
@Override
public <T extends Serializable> T readObject(@Nonnull final InputStream stream,
@Nonnull final Class<T> clazz) {
try (final Input input = new Input(stream)) {
final Class<?> restoredClass = kryoThreadLocal.get().readClass(input).getType();
return clazz.cast(kryoThreadLocal.get().readObject(input, restoredClass));
}
}
}
代码示例来源:origin: apache/hive
@Override
public List<?> read(final Kryo kryo, final Input input, final Class<List<?>> type) {
final int length = input.readInt(true);
Class<?> componentType = kryo.readClass(input).getType();
if (componentType.isPrimitive()) {
componentType = getPrimitiveWrapperClass(componentType);
}
try {
final Object items = Array.newInstance(componentType, length);
for (int i = 0; i < length; i++) {
Array.set(items, i, kryo.readClassAndObject(input));
}
return Arrays.asList((Object[]) items);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.esotericsoftware.kryo/kryo
public EnumSet read (Kryo kryo, Input input, Class<EnumSet> type) {
Registration registration = kryo.readClass(input);
EnumSet object = EnumSet.noneOf(registration.getType());
Serializer serializer = registration.getSerializer();
int length = input.readInt(true);
for (int i = 0; i < length; i++)
object.add(serializer.read(kryo, input, null));
return object;
}
代码示例来源:origin: com.esotericsoftware/kryo
public void write (Kryo kryo, Output output, EnumSet object) {
Serializer serializer;
if (object.isEmpty()) {
EnumSet tmp = EnumSet.complementOf(object);
if (tmp.isEmpty()) throw new KryoException("An EnumSet must have a defined Enum to be serialized.");
serializer = kryo.writeClass(output, tmp.iterator().next().getClass()).getSerializer();
} else {
serializer = kryo.writeClass(output, object.iterator().next().getClass()).getSerializer();
}
output.writeInt(object.size(), true);
for (Object element : object)
serializer.write(kryo, output, element);
}
代码示例来源:origin: com.esotericsoftware.kryo/kryo
/** Registers the class using the specified ID and serializer. If the ID is already in use by the same type, the old entry is
* overwritten. If the ID is already in use by a different type, a {@link KryoException} is thrown. Registering a primitive
* also affects the corresponding primitive wrapper.
* <p>
* IDs must be the same at deserialization as they were for serialization.
* @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and
* String, but these IDs can be repurposed. */
public Registration register (Class type, Serializer serializer, int id) {
if (id < 0) throw new IllegalArgumentException("id must be >= 0: " + id);
return register(new Registration(type, serializer, id));
}
代码示例来源:origin: uk.gov.gchq.gaffer/spark-library
@Override
public Edge read(final Kryo kryo, final Input input, final Class<Edge> type) {
final String group = input.readString();
Registration reg = kryo.readClass(input);
final Object source = kryo.readObject(input, reg.getType());
reg = kryo.readClass(input);
final Object dest = kryo.readObject(input, reg.getType());
final boolean directed = input.readBoolean();
final Properties properties = kryo.readObjectOrNull(input, Properties.class);
return new Edge(group, source, dest, directed, null, properties);
}
}
代码示例来源:origin: DataSystemsLab/GeoSpark
private Object readUserData(Kryo kryo, Input input)
{
Object userData = null;
if (input.readBoolean()) {
Registration clazz = kryo.readClass(input);
userData = kryo.readObject(input, clazz.getType());
}
return userData;
}
代码示例来源:origin: spring-projects/spring-integration
private void register(Kryo kryo, Registration registration) {
int id = registration.getId();
Registration existing = kryo.getRegistration(id);
if (existing != null) {
throw new IllegalStateException("registration already exists " + existing);
}
if (this.log.isInfoEnabled()) {
this.log.info(String.format("registering %s with serializer %s", registration,
registration.getSerializer().getClass().getName()));
}
kryo.register(registration);
}
代码示例来源:origin: orbit/orbit
@Override
public ReferenceReplacement read(Kryo kryo, Input input, Class<ReferenceReplacement> type)
{
ReferenceReplacement referenceReplacement = new ReferenceReplacement();
referenceReplacement.interfaceClass = kryo.readClass(input).getType();
referenceReplacement.id = kryo.readClassAndObject(input);
referenceReplacement.address = readNodeAddress(input);
return referenceReplacement;
}
}
代码示例来源:origin: co.paralleluniverse/quasar-core
private void register(Registration r) {
if (r.getId() < 0 && r.getSerializer() == NULL_SERIALIZER)
kryo.register(r.getType());
else if (r.getId() < 0)
kryo.register(r.getType(), r.getSerializer());
else if (r.getSerializer() == NULL_SERIALIZER)
kryo.register(r.getType(), r.getId());
else
kryo.register(r.getType(), r.getSerializer(), r.getId());
}
代码示例来源:origin: de.javakaffee/kryo-serializers
@Override
public EnumSet read(final Kryo kryo, final Input input, final Class<? extends EnumSet<? extends Enum<?>>> type) {
final Class<Enum> elementType = kryo.readClass( input ).getType();
final EnumSet result = EnumSet.noneOf( elementType );
final int size = input.readInt(true);
final Enum<?>[] enumConstants = elementType.getEnumConstants();
for ( int i = 0; i < size; i++ ) {
result.add( enumConstants[input.readInt(true)] );
}
return result;
}
代码示例来源:origin: com.esotericsoftware/kryo
/** Reads an object or null using the registered serializer.
* @return May be null. */
public <T> T readObjectOrNull (Input input, Class<T> type) {
if (input == null) throw new IllegalArgumentException("input cannot be null.");
if (type == null) throw new IllegalArgumentException("type cannot be null.");
beginObject();
try {
T object;
if (references) {
int stackSize = readReferenceOrNull(input, type, true);
if (stackSize == REF) return (T)readObject;
object = (T)getRegistration(type).getSerializer().read(this, input, type);
if (stackSize == readReferenceIds.size) reference(object);
} else {
Serializer serializer = getRegistration(type).getSerializer();
if (!serializer.getAcceptsNull() && input.readByte() == NULL) {
if (TRACE || (DEBUG && depth == 1)) log("Read", null);
return null;
}
object = (T)serializer.read(this, input, type);
}
if (TRACE || (DEBUG && depth == 1)) log("Read", object);
return object;
} finally {
if (--depth == 0 && autoReset) reset();
}
}
内容来源于网络,如有侵权,请联系作者删除!