當前位置: 首頁>>代碼示例>>Java>>正文


Java Kryo類代碼示例

本文整理匯總了Java中com.esotericsoftware.kryo.Kryo的典型用法代碼示例。如果您正苦於以下問題:Java Kryo類的具體用法?Java Kryo怎麽用?Java Kryo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Kryo類屬於com.esotericsoftware.kryo包,在下文中一共展示了Kryo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:18,代碼來源:ExtensionCriterionSerializer.java

示例2: write

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
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);
    }
}
 
開發者ID:yuantiku,項目名稱:ytk-mp4j,代碼行數:18,代碼來源:LongOperand.java

示例3: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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;
}
 
開發者ID:yuantiku,項目名稱:ytk-mp4j,代碼行數:25,代碼來源:ShortOperand.java

示例4: createKryoInstance

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
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;
}
 
開發者ID:olehmberg,項目名稱:T2KMatch,代碼行數:23,代碼來源:KryoFactory.java

示例5: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:23,代碼來源:RegisteredServiceSerializer.java

示例6: write

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
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);
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:20,代碼來源:IntMapSerializer.java

示例7: write

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
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);
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:21,代碼來源:ObjectFloatMapSerializer.java

示例8: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:24,代碼來源:QueueSerializer.java

示例9: write

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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()));
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:RegisteredServiceSerializer.java

示例10: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:23,代碼來源:RegisteredServiceSerializer.java

示例11: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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);
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:20,代碼來源:GraphHeader.java

示例12: write

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
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);
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:21,代碼來源:LongMapSerializer.java

示例13: serialize

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
/**
 * 序列化
 *
 * @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;
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:23,代碼來源:KryoSerializer.java

示例14: read

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:18,代碼來源:IpPrefixSerializer.java

示例15: encode

import com.esotericsoftware.kryo.Kryo; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:24,代碼來源:KryoCodec.java


注:本文中的com.esotericsoftware.kryo.Kryo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。