Java Code Examples for com.esotericsoftware.kryo.Kryo.readClassAndObject()

The following are Jave code examples for showing how to use readClassAndObject() of the com.esotericsoftware.kryo.Kryo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gdx-cclibs   File: SortedIntListSerializer.java   Source Code and License Vote up 6 votes
@Override
public SortedIntList read(Kryo kryo, Input input, Class<SortedIntList> type) {
    int length = input.readVarInt(true);
    SortedIntList list = new SortedIntList();
    kryo.reference(list);
    Class elementClass = null;
    Serializer serializer = null;
    if (genericType != null) {
        elementClass = genericType;
        serializer = kryo.getSerializer(genericType);
        genericType = null;
    }
    for (int i = 0; i < length; i++) {
        int index = input.readInt();
        Object value = serializer != null ?
                kryo.readObjectOrNull(input, elementClass, serializer) : kryo.readClassAndObject(input);
        list.insert(index, value);
    }
    return list;
}
 
Example 2
Project: athena   File: DefaultLinkSerializer.java   Source Code and License Vote up 6 votes
@Override
public DefaultLink read(Kryo kryo, Input input, Class<DefaultLink> type) {
    ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
    ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
    ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
    Type linkType = (Type) kryo.readClassAndObject(input);
    State state = (State) kryo.readClassAndObject(input);
    boolean isDurable = input.readBoolean();
    return DefaultLink.builder()
            .providerId(providerId)
            .src(src)
            .dst(dst)
            .type(linkType)
            .state(state)
            .isExpected(isDurable)
            .build();
}
 
Example 3
Project: happylifeplat-transaction   File: KryoSerialize.java   Source Code and License Vote up 5 votes
@Override
public Object deserialize(InputStream input) throws IOException {
    Kryo kryo = pool.borrow();
    Input in = new Input(input);
    Object result = kryo.readClassAndObject(in);
    in.close();
    input.close();
    pool.release(kryo);
    return result;
}
 
Example 4
Project: miracle-remote   File: KryoSerialization.java   Source Code and License Vote up 5 votes
@Override
public Object deserialize(final InputStream in) throws IOException {
    Kryo kryo = kryoFactory.getKryo();
    Input input = new Input(in);
    Object result = kryo.readClassAndObject(input);
    input.close();
    kryoFactory.returnKryo(kryo);
    return result;
}
 
Example 5
Project: athena   File: HostLocationSerializer.java   Source Code and License Vote up 5 votes
@Override
public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) {
    DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
    PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input);
    long time = input.readLong();
    return new HostLocation(deviceId, portNumber, time);
}
 
Example 6
Project: athena   File: EncodedResourcesSerializer.java   Source Code and License Vote up 5 votes
@Override
public EncodedDiscreteResources read(Kryo kryo, Input input, Class<EncodedDiscreteResources> cls) {
    @SuppressWarnings("unchecked")
    List<ClosedOpenRange> ranges = kryo.readObject(input, ArrayList.class);
    DiscreteResourceCodec codec = (DiscreteResourceCodec) kryo.readClassAndObject(input);

    RangeSet<Integer> rangeSet = TreeRangeSet.create();
    ranges.stream()
            .map(x -> Range.closedOpen(x.lowerBound(), x.upperBound()))
            .forEach(rangeSet::add);
    return new EncodedDiscreteResources(rangeSet, codec);
}
 
Example 7
Project: athena   File: DefaultPortSerializer.java   Source Code and License Vote up 5 votes
@Override
public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) {
    Element element = (Element) kryo.readClassAndObject(input);
    PortNumber number = kryo.readObject(input, PortNumber.class);
    boolean isEnabled = input.readBoolean();
    Port.Type type = kryo.readObject(input, Port.Type.class);
    long portSpeed = input.readLong();
    Annotations annotations = (Annotations) kryo.readClassAndObject(input);

    return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations);
}
 
Example 8
Project: gdx-cclibs   File: ObjectMapSerializer.java   Source Code and License Vote up 5 votes
public T read (Kryo kryo, Input input, Class<T> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    T map = create(length);

    Class keyClass = null;
    Class valueClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
 
Example 9
Project: gdx-cclibs   File: ObjectFloatMapSerializer.java   Source Code and License Vote up 5 votes
public ObjectFloatMap read (Kryo kryo, Input input, Class<ObjectFloatMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    ObjectFloatMap map = create(length);

    Class keyClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        float value = input.readFloat();
        map.put(key, value);
    }
    return map;
}
 
Example 10
Project: gdx-cclibs   File: IdentityMapSerializer.java   Source Code and License Vote up 5 votes
public IdentityMap read (Kryo kryo, Input input, Class<IdentityMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    IdentityMap map = new IdentityMap(length);

    Class keyClass = null;
    Class valueClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
 
Example 11
Project: gdx-cclibs   File: LongMapSerializer.java   Source Code and License Vote up 5 votes
public LongMap read (Kryo kryo, Input input, Class<LongMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    LongMap map = new LongMap(length);

    Class valueClass = null;

    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        long key = input.readLong();
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
 
Example 12
Project: gdx-cclibs   File: IntMapSerializer.java   Source Code and License Vote up 5 votes
public IntMap read (Kryo kryo, Input input, Class<IntMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    IntMap map = new IntMap(length);

    Class valueClass = null;

    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        int key = input.readInt();
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
 
Example 13
Project: gdx-cclibs   File: ObjectIntMapSerializer.java   Source Code and License Vote up 5 votes
public ObjectIntMap read (Kryo kryo, Input input, Class<ObjectIntMap> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    ObjectIntMap map = create(length);

    Class keyClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        int value = input.readInt();
        map.put(key, value);
    }
    return map;
}
 
Example 14
Project: athena   File: KryoNamespace.java   Source Code and License Vote up 5 votes
/**
 * Deserializes given byte array to Object using Kryo instance in pool.
 *
 * @param bytes serialized bytes
 * @param <T> deserialized Object type
 * @return deserialized Object
 */
public <T> T deserialize(final byte[] bytes) {
    Input in = new Input(bytes);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
 
Example 15
Project: athena   File: KryoNamespace.java   Source Code and License Vote up 5 votes
/**
 * Deserializes given byte buffer to Object using Kryo instance in pool.
 *
 * @param buffer input with serialized bytes
 * @param <T> deserialized Object type
 * @return deserialized Object
 */
public <T> T deserialize(final ByteBuffer buffer) {
    ByteBufferInput in = new ByteBufferInput(buffer);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
 
Example 16
Project: athena   File: KryoNamespace.java   Source Code and License Vote up 5 votes
/**
 * Deserializes given InputStream to an Object using Kryo instance in pool.
 *
 * @param stream input stream
 * @param <T> deserialized Object type
 * @return deserialized Object
 * @param bufferSize size of the buffer in front of the stream
 */
public <T> T deserialize(final InputStream stream, final int bufferSize) {
    ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
 
Example 17
Project: dremio-oss   File: ImmutableCollectionSerializers.java   Source Code and License Vote up 5 votes
@Override
public ImmutableList<Object> read(final Kryo kryo, final Input input, final Class<ImmutableList<Object>> type) {
  final int size = input.readInt(true);
  final Object[] values = new Object[size];

  for (int i = 0; i < size; ++i) {
    values[i] = kryo.readClassAndObject(input);
  }

  final ImmutableList<Object> result = ImmutableList.copyOf(values);
  kryo.reference(result);
  return result;
}
 
Example 18
Project: gdx-cclibs   File: ArrayMapSerializer.java   Source Code and License Vote up 4 votes
public ArrayMap read (Kryo kryo, Input input, Class<ArrayMap> type) {
    boolean ordered = input.readBoolean();
    int length = input.readVarInt(true);
    Class knownKeyClass = kryo.readClass(input).getType();
    Class knownValueClass = kryo.readClass(input).getType();

    ArrayMap map = new ArrayMap(ordered, length, knownKeyClass, knownValueClass);

    Class keyClass = null;
    Class valueClass = null;

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        keyClass = keyGenericType;
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass);
        keyGenericType = null;
    }
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        valueClass = valueGenericType;
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass);
        valueGenericType = null;
    }

    kryo.reference(map);

    for (int i = 0; i < length; i++) {
        Object key;
        if (keySerializer != null) {
            key = kryo.readObject(input, keyClass, keySerializer);
        } else
            key = kryo.readClassAndObject(input);
        Object value;
        if (valueSerializer != null) {
            value = kryo.readObjectOrNull(input, valueClass, valueSerializer);
        } else
            value = kryo.readClassAndObject(input);
        map.put(key, value);
    }
    return map;
}
 
Example 19
Project: algorithm.annotation   File: KryoTool.java   Source Code and License Vote up 4 votes
public static Object toObject(ByteBuffer buf){
	Kryo kryo = new Kryo();
	Input input = new Input(buf.array());
	input.close();
	return kryo.readClassAndObject(input);
}
 
Example 20
Project: athena   File: LinkKeySerializer.java   Source Code and License Vote up 4 votes
@Override
public LinkKey read(Kryo kryo, Input input, Class<LinkKey> type) {
    ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
    ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
    return LinkKey.linkKey(src, dst);
}