Java Code Examples for com.esotericsoftware.kryo.Kryo

The following are top voted examples for showing how to use com.esotericsoftware.kryo.Kryo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: athena   File: ExtensionCriterionSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public ExtensionCriterion read(Kryo kryo, Input input,
        Class<ExtensionCriterion> type) {
    ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input);
    DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);

    DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
    DriverHandler handler = new DefaultDriverHandler(
            new DefaultDriverData(driverService.getDriver(deviceId), deviceId));

    ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class);
    ExtensionSelector selector = resolver.getExtensionSelector(exType);

    byte[] bytes = (byte[]) kryo.readClassAndObject(input);
    selector.deserialize(bytes);
    return Criteria.extension(selector, deviceId);
}
 
Example 2
Project: ytk-mp4j   File: LongOperand.java   Source Code and License 6 votes vote down vote up
public void write(Kryo kryo, Output output, ArrayMetaData<long[]> object) {
    try {
        long[] arrData = arrayMetaData.getArrData();
        arrayMetaData.send(output);
        int arrSegNum = arrayMetaData.getSegNum();
        for (int i = 0; i < arrSegNum; i++) {
            int from = arrayMetaData.getFrom(i);
            int to = arrayMetaData.getTo(i);
            for (int j = from; j < to; j++) {
                output.writeLong(arrData[j]);
            }
        }
    } catch (IOException e) {
        LOG.error("double array write exception", e);
        System.exit(1);
    }
}
 
Example 3
Project: ytk-mp4j   File: ShortOperand.java   Source Code and License 6 votes vote down vote up
@Override
public MapMetaData<Short> read(Kryo kryo, Input input, Class<MapMetaData<Short>> type) {
    try {
        thatMapMetaData = mapMetaData.recv(input);
        int thatMapSegNum = thatMapMetaData.getSegNum();
        List<Map<String, Short>> mapDataList = new ArrayList<>(thatMapSegNum);
        thatMapMetaData.setMapDataList(mapDataList);

        for (int i = 0; i < thatMapSegNum; i++) {
            int dataNum = thatMapMetaData.getDataNum(i);
            Map<String, Short> mapData = new HashMap<>(dataNum);
            mapDataList.add(mapData);
            for (int j = 0; j < dataNum; j++) {
                String key = input.readString();
                Short val = input.readShort();
                mapData.put(key, val);
            }
        }
    } catch (IOException e) {
        LOG.error("double array read exception", e);
        System.exit(1);
    }
    return thatMapMetaData;
}
 
Example 4
Project: T2KMatch   File: KryoFactory.java   Source Code and License 6 votes vote down vote up
public static Kryo createKryoInstance() {
	Kryo kryo = new Kryo();
	
	// add custom serialisers to work with joda time (the kryo version that we get when including spark as a dependency cannot handle joda time by default)
	// see https://github.com/magro/kryo-serializers
	
	kryo.register( Arrays.asList( "" ).getClass(), new ArraysAsListSerializer() );
	kryo.register( Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() );
	kryo.register( Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer() );
	kryo.register( Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer() );
	kryo.register( Collections.singletonList( "" ).getClass(), new CollectionsSingletonListSerializer() );
	kryo.register( Collections.singleton( "" ).getClass(), new CollectionsSingletonSetSerializer() );
	kryo.register( Collections.singletonMap( "", "" ).getClass(), new CollectionsSingletonMapSerializer() );
	kryo.register( GregorianCalendar.class, new GregorianCalendarSerializer() );
	kryo.register( InvocationHandler.class, new JdkProxySerializer() );
	UnmodifiableCollectionsSerializer.registerSerializers( kryo );
	SynchronizedCollectionsSerializer.registerSerializers( kryo );

	// custom serializers for non-jdk libs
	
	return kryo;
}
 
Example 5
Project: springboot-shiro-cas-mybatis   File: RegisteredServiceSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public RegisteredService read(final Kryo kryo, final Input input, final Class<RegisteredService> type) {
    final AbstractRegisteredService svc = new RegexRegisteredService();
    svc.setServiceId(kryo.readObject(input, String.class));
    svc.setName(kryo.readObject(input, String.class));
    svc.setDescription(kryo.readObject(input, String.class));
    svc.setId(kryo.readObject(input, Long.class));
    svc.setEvaluationOrder(kryo.readObject(input, Integer.class));
    svc.setLogo(kryo.readObject(input, URL.class));
    svc.setLogoutType(kryo.readObject(input, LogoutType.class));
    svc.setLogoutUrl(kryo.readObject(input, URL.class));
    svc.setRequiredHandlers(kryo.readObject(input, ImmutableSet.class));
    svc.setTheme(kryo.readObject(input, String.class));

    svc.setPublicKey(readObjectByReflection(kryo, input, RegisteredServicePublicKey.class));
    svc.setProxyPolicy(readObjectByReflection(kryo, input, RegisteredServiceProxyPolicy.class));
    svc.setAttributeReleasePolicy(readObjectByReflection(kryo, input, RegisteredServiceAttributeReleasePolicy.class));
    svc.setUsernameAttributeProvider(readObjectByReflection(kryo, input, RegisteredServiceUsernameAttributeProvider.class));
    svc.setAccessStrategy(readObjectByReflection(kryo, input, RegisteredServiceAccessStrategy.class));

    return svc;
}
 
Example 6
Project: gdx-cclibs   File: IntMapSerializer.java   Source Code and License 6 votes vote down vote up
public void write (Kryo kryo, Output output, IntMap map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of IntMap supports type awareness)
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
        valueGenericType = null;
    }

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        IntMap.Entry entry = (IntMap.Entry)iter.next();
        output.writeInt(entry.key);
        if (valueSerializer != null) {
            kryo.writeObjectOrNull(output, entry.value, valueSerializer);
        } else
            kryo.writeClassAndObject(output, entry.value);
    }
}
 
Example 7
Project: gdx-cclibs   File: ObjectFloatMapSerializer.java   Source Code and License 6 votes vote down vote up
public void write (Kryo kryo, Output output, ObjectFloatMap map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of ObjectFloatMap supports type awareness)

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

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        ObjectFloatMap.Entry entry = (ObjectFloatMap.Entry)iter.next();
        if (keySerializer != null) {
            kryo.writeObject(output, entry.key, keySerializer);
        } else
            kryo.writeClassAndObject(output, entry.key);
        output.writeFloat(entry.value);
    }
}
 
Example 8
Project: gdx-cclibs   File: QueueSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public Queue read(Kryo kryo, Input input, Class<Queue> type) {
    int length = input.readVarInt(true);
    Registration registration = kryo.readClass(input);
    Class cls = registration == null ? Object.class : registration.getType();
    Queue queue = new Queue(length, cls);
    kryo.reference(queue);
    Class elementClass = null;
    Serializer serializer = null;
    if (genericType != null) {
        elementClass = genericType;
        serializer = kryo.getSerializer(genericType);
        genericType = null;
    }
    if (serializer != null) {
        for (int i = 0; i < length; i++)
            queue.addLast(kryo.readObjectOrNull(input, elementClass, serializer));
    } else {
        for (int i = 0; i < length; i++)
            queue.addLast(kryo.readClassAndObject(input));
    }
    return queue;
}
 
Example 9
Project: cas-5.1.0   File: RegisteredServiceSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public void write(final Kryo kryo, final Output output, final RegisteredService service) {
    kryo.writeObject(output, service.getServiceId());
    kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getName(), StringUtils.EMPTY));
    kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getDescription(), StringUtils.EMPTY));
    kryo.writeObject(output, service.getId());
    kryo.writeObject(output, service.getEvaluationOrder());
    kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogo(), getEmptyUrl()));
    kryo.writeObject(output, service.getLogoutType());
    kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogoutUrl(), getEmptyUrl()));
    kryo.writeObject(output, new HashSet<>(service.getRequiredHandlers()));
    kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getTheme(), StringUtils.EMPTY));

    writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getPublicKey(),
            new RegisteredServicePublicKeyImpl()));
    writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getProxyPolicy(),
            new RefuseRegisteredServiceProxyPolicy()));
    writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAttributeReleasePolicy(),
            new ReturnAllowedAttributeReleasePolicy()));
    writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getUsernameAttributeProvider(),
            new DefaultRegisteredServiceUsernameProvider()));
    writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAccessStrategy(),
            new DefaultRegisteredServiceAccessStrategy()));
}
 
Example 10
Project: cas-5.1.0   File: RegisteredServiceSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public RegisteredService read(final Kryo kryo, final Input input, final Class<RegisteredService> type) {
    final AbstractRegisteredService svc = new RegexRegisteredService();
    svc.setServiceId(kryo.readObject(input, String.class));
    svc.setName(kryo.readObject(input, String.class));
    svc.setDescription(kryo.readObject(input, String.class));
    svc.setId(kryo.readObject(input, Long.class));
    svc.setEvaluationOrder(kryo.readObject(input, Integer.class));
    svc.setLogo(kryo.readObject(input, URL.class));
    svc.setLogoutType(kryo.readObject(input, LogoutType.class));
    svc.setLogoutUrl(kryo.readObject(input, URL.class));
    svc.setRequiredHandlers(kryo.readObject(input, HashSet.class));
    svc.setTheme(kryo.readObject(input, String.class));

    svc.setPublicKey(readObjectByReflection(kryo, input));
    svc.setProxyPolicy(readObjectByReflection(kryo, input));
    svc.setAttributeReleasePolicy(readObjectByReflection(kryo, input));
    svc.setUsernameAttributeProvider(readObjectByReflection(kryo, input));
    svc.setAccessStrategy(readObjectByReflection(kryo, input));

    return svc;
}
 
Example 11
Project: gdx-cclibs   File: GraphHeader.java   Source Code and License 6 votes vote down vote up
@Override
public final void read (Kryo kryo, Input input) {
    pushHeader(kryo, this);
    input.readInt(true); //if this class ever evolves, version can be used for backward compatibility
    Class dataType = kryo.readClass(input).getType();
    gdxMajorVersion = input.readInt(true);
    gdxMinorVersion = input.readInt(true);
    gdxRevisionVersion = input.readInt(true);
    writtenVersion = input.readInt(true);
    minimumReadVersion = input.readInt(true);
    minimumReadVersionString = input.readString();
    useCompactColor = input.readBoolean();
    includePixmapDrawingParams = input.readBoolean();
    readExtra(kryo, input);
    if (dataType != null && minimumReadVersion <= currentReadWriteVersion){
        data = (T)kryo.readObject(input, dataType);
    }
    popHeader(kryo);
}
 
Example 12
Project: gdx-cclibs   File: LongMapSerializer.java   Source Code and License 6 votes vote down vote up
public void write (Kryo kryo, Output output, LongMap map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of LongMap supports type awareness)

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

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        LongMap.Entry entry = (LongMap.Entry)iter.next();
        output.writeLong(entry.key);
        if (valueSerializer != null) {
            kryo.writeObjectOrNull(output, entry.value, valueSerializer);
        } else
            kryo.writeClassAndObject(output, entry.value);
    }
}
 
Example 13
Project: myth   File: KryoSerializer.java   Source Code and License 6 votes vote down vote up
/**
 * 序列化
 *
 * @param obj 需要序更列化的对象
 * @return 序列化后的byte 数组
 * @throws MythException 异常
 */
@Override
public byte[] serialize(Object obj) throws MythException {
    byte[] bytes;
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        //获取kryo对象
        Kryo kryo = new Kryo();
        Output output = new Output(outputStream);
        kryo.writeObject(output, obj);
        bytes = output.toBytes();
        output.flush();
    } catch (Exception ex) {
        throw new MythException("kryo serialize error" + ex.getMessage());
    }
    return bytes;
}
 
Example 14
Project: athena   File: IpPrefixSerializer.java   Source Code and License 6 votes vote down vote up
@Override
public IpPrefix read(Kryo kryo, Input input,
        Class<IpPrefix> type) {
    int octLen = input.readInt();
    checkArgument(octLen <= IpAddress.INET6_BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    int prefLen = input.readInt();
    // Use the address size to decide whether it is IPv4 or IPv6 address
    if (octLen == IpAddress.INET_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen);
    }
    if (octLen == IpAddress.INET6_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen);
    }
    return null;    // Shouldn't be reached
}
 
Example 15
Project: JRediClients   File: KryoCodec.java   Source Code and License 6 votes vote down vote up
@Override
public ByteBuf encode(Object in) throws IOException {
    Kryo kryo = null;
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
    try {
        ByteBufOutputStream baos = new ByteBufOutputStream(out);
        Output output = new Output(baos);
        kryo = kryoPool.get();
        kryo.writeClassAndObject(output, in);
        output.close();
        return baos.buffer();
    } catch (Exception e) {
        out.release();
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RedissonKryoCodecException(e);
    } finally {
        if (kryo != null) {
            kryoPool.yield(kryo);
        }
    }
}
 
Example 16
Project: dremio-oss   File: KryoLogicalPlanSerializers.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a new {@link LogicalPlanDeserializer}
 * @param cluster cluster to inject during deserialization
 * @param catalog catalog used during deserializing tables
 * @param registry registry used during deserializing storage plugins
 */
public static LogicalPlanDeserializer forDeserialization(final RelOptCluster cluster, final CalciteCatalogReader catalog,
                                                       final StoragePluginRegistry registry) {
  final Kryo kryo = new Kryo();
  kryo.getFieldSerializerConfig().setUseAsm(true);
  final RelSerializer serializer = RelSerializer.newBuilder(kryo, cluster, catalog, registry).build();

  return new LogicalPlanDeserializer() {

    @Override
    public RelNode deserialize(final byte[] data) {
      try {
        return serializer.deserialize(data);
      } catch (Throwable e) {
        throw new KryoDeserializationException(e);
      }
    }

  };
}
 
Example 17
Project: ytk-mp4j   File: IntOperand.java   Source Code and License 6 votes vote down vote up
public void write(Kryo kryo, Output output, ArrayMetaData<int[]> object) {
    try {
        int[] arrData = arrayMetaData.getArrData();
        arrayMetaData.send(output);
        int arrSegNum = arrayMetaData.getSegNum();
        for (int i = 0; i < arrSegNum; i++) {
            int from = arrayMetaData.getFrom(i);
            int to = arrayMetaData.getTo(i);
            for (int j = from; j < to; j++) {
                output.writeInt(arrData[j]);
            }
        }
    } catch (IOException e) {
        LOG.error("double array write exception", e);
        System.exit(1);
    }
}
 
Example 18
Project: ytk-mp4j   File: DoubleOperand.java   Source Code and License 6 votes vote down vote up
public void write(Kryo kryo, Output output, MapMetaData<Double> object) {
    try {
        List<Map<String, Double>> mapDataList = mapMetaData.getMapDataList();
        mapMetaData.send(output);
        int mapSegNum = mapMetaData.getSegNum();
        for (int i = 0; i < mapSegNum; i++) {
            Map<String, Double> mapData = mapDataList.get(i);
            for (Map.Entry<String, Double> entry : mapData.entrySet()) {
                output.writeString(entry.getKey());
                output.writeDouble(entry.getValue());
            }
            if (mapMetaData.getCollective() == Collective.GATHER ||
                    mapMetaData.getCollective() == Collective.SCATTER ||
                    mapMetaData.getCollective() == Collective.REDUCE_SCATTER) {
                mapData.clear();
            }
        }

    } catch (IOException e) {
        LOG.error("double array write exception", e);
        System.exit(1);
    }
}
 
Example 19
Project: hype   File: SerializationUtil.java   Source Code and License 5 votes vote down vote up
public static Object readObject(InputStream inputStream) {
  Kryo kryo = new Kryo();
  kryo.register(java.lang.invoke.SerializedLambda.class);
  kryo.register(ClosureSerializer.Closure.class, new ClosureSerializer());
  kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

  Input input = new Input(inputStream);
  return kryo.readClassAndObject(input);
}
 
Example 20
Project: athena   File: KryoNamespace.java   Source Code and License 5 votes vote down vote up
/**
 * Register {@code type} and {@code serializer} to {@code kryo} instance.
 *
 * @param kryo       Kryo instance
 * @param type       type to register
 * @param serializer Specific serializer to register or null to use default.
 * @param id         type registration id to use
 */
private void register(Kryo kryo, Class<?> type, Serializer<?> serializer, int id) {
    Registration existing = kryo.getRegistration(id);
    if (existing != null) {
        if (existing.getType() != type) {
            log.error("{}: Failed to register {} as {}, {} was already registered.",
                      friendlyName(), type, id, existing.getType());

            throw new IllegalStateException(String.format(
                      "Failed to register %s as %s, %s was already registered.",
                      type, id, existing.getType()));
        }
        // falling through to register call for now.
        // Consider skipping, if there's reasonable
        // way to compare serializer equivalence.
    }
    Registration r;
    if (serializer == null) {
        r = kryo.register(type, id);
    } else {
        r = kryo.register(type, serializer, id);
    }
    if (r.getId() != id) {
        log.warn("{}: {} already registed as {}. Skipping {}.",
                 friendlyName(), r.getType(), r.getId(), id);
    }
    log.trace("{} registered as {}", r.getType(), r.getId());
}
 
Example 21
Project: hibatis   File: CacheContext.java   Source Code and License 5 votes vote down vote up
private <T> T  clone(T obj){
	Kryo kryo = kryoFactory.getKryo();
	try {
		Output output = new Output(1024, 1024 * 500);
		kryo.writeClassAndObject(output, obj);
		output.flush();
		Input input = new Input(output.toBytes());
		T t = (T) kryo.readClassAndObject(input);
		return t;
	} finally {
		kryoFactory.returnKryo(kryo);;
	}
}
 
Example 22
Project: ytk-mp4j   File: StringOperand.java   Source Code and License 5 votes vote down vote up
public MapMetaData<String> read(Kryo kryo, Input input, Class<MapMetaData<String>> type) {
    try {
        thatMapMetaData = mapMetaData.recv(input);
        int thatMapSegNum = thatMapMetaData.getSegNum();
        List<Map<String, String>> thatMapListData = new ArrayList<>(thatMapSegNum);
        List<Integer> thatDataNums = new ArrayList<>(thatMapSegNum);
        for (int i = 0; i < thatMapSegNum; i++) {
            Map<String, String> thisMapData = mapMetaData.getMapDataList().get(i);
            int dataNum = thatMapMetaData.getDataNum(i);
            for (int j = 0; j < dataNum; j++) {
                String key = input.readString();
                String val = input.readString();

                String thisVal = thisMapData.get(key);
                if (thisVal == null) {
                    thisMapData.put(key, val);
                } else {
                    thisMapData.put(key, operator.apply(thisVal, val));
                }
            }
            thatMapListData.add(thisMapData);
            thatDataNums.add(thisMapData.size());
        }

        thatMapMetaData.setMapDataList(thatMapListData);
        thatMapMetaData.setDataNums(thatDataNums);

    } catch (IOException e) {
        LOG.error("double array read exception", e);
        System.exit(1);
    }
    return thatMapMetaData;
}
 
Example 23
Project: gdx-cclibs   File: SegmentSerializer.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Segment segment) {
    Vector3 a = segment.a;
    output.writeFloat(a.x);
    output.writeFloat(a.y);
    output.writeFloat(a.z);
    Vector3 b = segment.b;
    output.writeFloat(b.x);
    output.writeFloat(b.y);
    output.writeFloat(b.z);
}
 
Example 24
Project: gdx-cclibs   File: RaySerializer.java   Source Code and License 5 votes vote down vote up
@Override
public Ray read(Kryo kryo, Input input, Class<Ray> type) {
    Ray ray = new Ray();
    Vector3 origin = ray.origin;
    origin.x = input.readFloat();
    origin.y = input.readFloat();
    origin.z = input.readFloat();
    Vector3 direction = ray.direction;
    direction.x = input.readFloat();
    direction.y = input.readFloat();
    direction.z = input.readFloat();
    return ray;
}
 
Example 25
Project: algorithm.annotation   File: KryoTool.java   Source Code and License 5 votes vote down vote up
public static ByteBuffer toByteBuffer(Object obj){
	Kryo kryo = new Kryo();
	Output output = new Output(1024*1024);
	kryo.writeClassAndObject(output, obj);
	output.close();
	return ByteBuffer.wrap(output.toBytes());
}
 
Example 26
Project: gdx-cclibs   File: SphereSerializer.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Sphere sphere) {
    Vector3 center = sphere.center;
    output.writeFloat(center.x);
    output.writeFloat(center.y);
    output.writeFloat(center.z);
    output.writeFloat(sphere.radius);
}
 
Example 27
Project: dremio-oss   File: RelTraitSerializers.java   Source Code and License 5 votes vote down vote up
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  final boolean isKnown = kryo.readObject(input, Boolean.class);
  final T result;
  if (isKnown) {
    final RelDistribution.Type kind = kryo.readObject(input, RelDistribution.Type.class);
    result = (T)distributionMap.get(kind);
  } else {
    result = super.read(kryo, input, type);
  }

  final T normalized = (T) result.getTraitDef().canonize(result);
  kryo.reference(normalized);
  return normalized;
}
 
Example 28
Project: athena   File: Ip4PrefixSerializer.java   Source Code and License 5 votes vote down vote up
@Override
public Ip4Prefix read(Kryo kryo, Input input,
        Class<Ip4Prefix> type) {
    int octLen = input.readInt();
    checkArgument(octLen <= Ip4Address.BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    int prefLen = input.readInt();
    return Ip4Prefix.valueOf(octs, prefLen);
}
 
Example 29
Project: springboot-shiro-cas-mybatis   File: SamlServiceSerializer.java   Source Code and License 5 votes vote down vote up
@Override
protected SamlService createService(final Kryo kryo, final Input input, final String id,
        final String originalUrl, final String artifactId) {

    final String requestId = kryo.readObject(input, String.class);
    try {
        return (SamlService) CONSTRUCTOR.newInstance(id, originalUrl, artifactId, new SimpleHttpClientFactoryBean().getObject(),
                requestId);
    } catch (final Exception e) {
        throw new IllegalStateException("Error creating SamlService", e);
    }
}
 
Example 30
Project: ytk-learn   File: SplitInfo.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, SplitInfo object) {
    output.writeFloat(object.lossChg);
    output.writeInt(object.splitIndex);
    output.writeFloat(object.splitValue);
    output.writeInt(object.splitSlotInterval.length);
    for (int i = 0; i < object.splitSlotInterval.length; i++) {
        output.writeInt(object.splitSlotInterval[i]);
    }
}
 
Example 31
Project: gdx-cclibs   File: EllipseSerializer.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Ellipse ellipse) {
    output.writeFloat(ellipse.x);
    output.writeFloat(ellipse.y);
    output.writeFloat(ellipse.width);
    output.writeFloat(ellipse.height);
}
 
Example 32
Project: dremio-oss   File: JavaSerializers.java   Source Code and License 5 votes vote down vote up
@Override
public URI read(final Kryo kryo, final Input input, final Class<URI> type) {
  final String uriString = kryo.readObject(input, String.class);
  try {
    return new URI(uriString);
  } catch (final URISyntaxException e) {
    throw new RuntimeException(String.format("unable to deserialize URI from uri string: %s", uriString), e);
  }
}
 
Example 33
Project: MMORPG_Prototype   File: PacketsRegisterer.java   Source Code and License 5 votes vote down vote up
private static Kryo registerCollection(Kryo destination, Set<Class<?>> types)
{
    List<Class<?>> sorted = sort(types);
    for (Class<?> registerableType : sorted)
        destination = registerType(destination, registerableType);

    return destination;
}
 
Example 34
Project: ytk-mp4j   File: ObjectOperand.java   Source Code and License 5 votes vote down vote up
public MapMetaData<T> read(Kryo kryo, Input input, Class<MapMetaData<T>> type) {
    try {
        thatMapMetaData = mapMetaData.recv(input);
        int thatMapSegNum = thatMapMetaData.getSegNum();
        List<Map<String, T>> thatMapListData = new ArrayList<>(thatMapSegNum);
        List<Integer> thatDataNums = new ArrayList<>(thatMapSegNum);
        for (int i = 0; i < thatMapSegNum; i++) {
            Map<String, T> thisMapData = mapMetaData.getMapDataList().get(i);
            int dataNum = thatMapMetaData.getDataNum(i);
            for (int j = 0; j < dataNum; j++) {
                String key = input.readString();
                T val = serializer.read(kryo, input, this.type);

                T thisVal = thisMapData.get(key);
                if (thisVal == null) {
                    thisMapData.put(key, val);
                } else {
                    thisMapData.put(key, operator.apply(thisVal, val));
                }
            }
            thatMapListData.add(thisMapData);
            thatDataNums.add(thisMapData.size());
        }

        thatMapMetaData.setMapDataList(thatMapListData);
        thatMapMetaData.setDataNums(thatDataNums);

    } catch (IOException e) {
        LOG.error("double array read exception", e);
        System.exit(1);
    }
    return thatMapMetaData;
}
 
Example 35
Project: cas-5.1.0   File: URLSerializer.java   Source Code and License 5 votes vote down vote up
@Override
public URL read(final Kryo kryo, final Input input, final Class<URL> type) {
    final String url = kryo.readObject(input, String.class);
    try {
        return new URL(url);
    } catch (final MalformedURLException e) {
        throw Throwables.propagate(e);
    }
}
 
Example 36
Project: gdx-cclibs   File: GridPoint3Serializer.java   Source Code and License 5 votes vote down vote up
@Override
public GridPoint3 read(Kryo kryo, Input input, Class<GridPoint3> type) {
    int x = input.readInt();
    int y = input.readInt();
    int z = input.readInt();
    return new GridPoint3(x, y, z);
}
 
Example 37
Project: ytk-mp4j   File: ProcessCommSlave.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, List<T> object) {
    output.writeInt(object.size());
    for (T val : object) {
        valSerializer.write(kryo, output, val);
    }
}
 
Example 38
Project: T2KMatch   File: KnowledgeBase.java   Source Code and License 5 votes vote down vote up
public static KnowledgeBase deserialise(File location) throws FileNotFoundException {
	System.out.println("Deserialising Knowledge Base");
	
       Kryo kryo = KryoFactory.createKryoInstance();
       
       Input input = new Input(new FileInputStream(location));
       KnowledgeBase kb = kryo.readObject(input, KnowledgeBase.class);
       input.close();
       
       return kb;
}
 
Example 39
Project: gdx-cclibs   File: AbstractBooleanArraySerializer.java   Source Code and License 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, T bitSource) {
    int numBits = numBits(bitSource);
    output.writeInt(numBits, true);
    long[] array = new long[(numBits >>> 6) + 1];
    for (int i = 0; i < numBits; i++) {
        if (get(bitSource, i)) {
            final int word = i >>> 6;
            array[word] |= 1L << (i & 0x3F);
        }
    }
    output.writeLongs(array);
}
 
Example 40
Project: JRediClients   File: KryoCodec.java   Source Code and License 5 votes vote down vote up
/**
 * Sub classes can customize the Kryo instance by overriding this method
 *
 * @return create Kryo instance
 */
protected Kryo createInstance() {
    Kryo kryo = new Kryo();
    if (classLoader != null) {
        kryo.setClassLoader(classLoader);
    }
    kryo.setReferences(false);
    for (Class<?> clazz : classes) {
        kryo.register(clazz);
    }
    return kryo;
}