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


Java Serializer類代碼示例

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


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

示例1: KryoTranscoderTests

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
public KryoTranscoderTests(final int bufferSize) {

        this.principalAttributes = new HashMap<String, Object>();
        this.principalAttributes.put(ST_ID, TGT_ID);

        transcoder = new KryoTranscoder(bufferSize);
        final Map<Class<?>, Serializer> serializerMap = new HashMap<Class<?>, Serializer>();
        serializerMap.put(
                MockServiceTicket.class,
                new FieldSerializer(transcoder.getKryo(), MockServiceTicket.class));
        serializerMap.put(
                MockTicketGrantingTicket.class,
                new FieldSerializer(transcoder.getKryo(), MockTicketGrantingTicket.class));
        serializerMap.put(
                TicketGrantingTicketImpl.class,
                new FieldSerializer(transcoder.getKryo(), TicketGrantingTicketImpl.class));
        serializerMap.put(
                ServiceTicketImpl.class,
                new FieldSerializer(transcoder.getKryo(), ServiceTicketImpl.class));
        transcoder.setSerializerMap(serializerMap);
        transcoder.initialize();
    }
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:23,代碼來源:KryoTranscoderTests.java

示例2: read

import com.esotericsoftware.kryo.Serializer; //導入依賴的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

示例3: write

import com.esotericsoftware.kryo.Serializer; //導入依賴的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

示例4: write

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
@Override
public void write(Kryo kryo, Output output, SortedIntList list) {
    output.writeVarInt(list.size(), true);
    Serializer serializer = null;
    if (genericType != null) {
        if (serializer == null) serializer = kryo.getSerializer(genericType);
        genericType = null;
    }
    for (Iterator<SortedIntList.Node> iter = list.iterator(); iter.hasNext();){
        SortedIntList.Node node = iter.next();
        output.writeInt(node.index);
        if (serializer != null) {
            kryo.writeObjectOrNull(output, node.value, serializer);
        } else {
            kryo.writeClassAndObject(output, node.value);
        }
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:19,代碼來源:SortedIntListSerializer.java

示例5: read

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

示例6: read

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
    int length = input.readVarInt(true);
    boolean ordered = input.readBoolean();
    Class cls = kryo.readClass(input).getType();
    T array = create(ordered, length, cls);
    kryo.reference(array);
    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++)
            array.add(kryo.readObjectOrNull(input, elementClass, serializer));
    } else {
        for (int i = 0; i < length; i++)
            array.add(kryo.readClassAndObject(input));
    }
    return array;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:24,代碼來源:ArraySerializer.java

示例7: read

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
    int length = input.readVarInt(true);
    input.readBoolean(); // currently unused
    T objectSet = create(length);

    kryo.reference(objectSet);

    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++)
            objectSet.add(kryo.readObject(input, elementClass, serializer));
    } else {
        for (int i = 0; i < length; i++)
            objectSet.add(kryo.readClassAndObject(input));
    }
    return objectSet;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:25,代碼來源:ObjectSetSerializer.java

示例8: write

import com.esotericsoftware.kryo.Serializer; //導入依賴的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

示例9: write

import com.esotericsoftware.kryo.Serializer; //導入依賴的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

示例10: write

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
public void write (Kryo kryo, Output output, ObjectIntMap map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of ObjectIntMap 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();) {
        ObjectIntMap.Entry entry = (ObjectIntMap.Entry)iter.next();
        if (keySerializer != null) {
            kryo.writeObject(output, entry.key, keySerializer);
        } else
            kryo.writeClassAndObject(output, entry.key);
        output.writeInt(entry.value);
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:21,代碼來源:ObjectIntMapSerializer.java

示例11: create

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
/**
 * Creates a Kryo instance.
 *
 * @return Kryo instance
 */
@Override
public Kryo create() {
    log.trace("Creating Kryo instance for {}", this);
    Kryo kryo = new Kryo();
    kryo.setRegistrationRequired(registrationRequired);

    // TODO rethink whether we want to use StdInstantiatorStrategy
    kryo.setInstantiatorStrategy(
            new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

    for (RegistrationBlock block : registeredBlocks) {
        int id = block.begin();
        if (id == FLOATING_ID) {
            id = kryo.getNextRegistrationId();
        }
        for (Pair<Class<?>, Serializer<?>> entry : block.types()) {
            register(kryo, entry.getLeft(), entry.getRight(), id++);
        }
    }
    return kryo;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:KryoNamespace.java

示例12: createKryo

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
private Kryo createKryo() {
    Kryo result = new KryoReflectionFactorySupport() {
        
        @Override
        public Serializer<?> getDefaultSerializer(@SuppressWarnings("rawtypes") final Class clazz) {
            if (EnumMap.class.isAssignableFrom(clazz)) {
                return new EnumMapSerializer();
            }
            if (SubListSerializers.ArrayListSubListSerializer.canSerialize(clazz) || SubListSerializers.JavaUtilSubListSerializer.canSerialize(clazz)) {
                return SubListSerializers.createFor(clazz);
            }
            return super.getDefaultSerializer(clazz);
        }
    };
    result.register(Collections.singletonList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(result);
    return result;
}
 
開發者ID:terrymanu,項目名稱:miracle-remote,代碼行數:19,代碼來源:PooledKryoFactory.java

示例13: reduceMapSetUnion

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
/**
 * Set union, the set with the same key will be reduced(union) together in the root process.
 * @param mapData map set data
 * @param rootRank root rank
 * @param elementSerializer element object Kryo serializer
 * @param elementType element obejct class

 * @return if this process is root, the set with the same key will be reduced together,
 *         otherwise, invalid map or null is returned.
 * @throws Mp4jException
 */
public <T> Map<String, Set<T>> reduceMapSetUnion(Map<String, Set<T>> mapData, int rootRank, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {

    Operand operand = Operands.OBJECT_OPERAND(new Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
    IOperator operator = new IObjectOperator<Set<T>>() {
        @Override
        public Set<T> apply(Set<T> o1, Set<T> o2) {
            for (T val : o2) {
                o1.add(val);
            }
            return o1;
        }
    };

    return reduceMap(mapData, operand, operator, rootRank);

}
 
開發者ID:yuantiku,項目名稱:ytk-mp4j,代碼行數:28,代碼來源:ProcessCommSlave.java

示例14: allreduceMapSetUnion

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
/**
 * Set union, the set with the same key will be reduced(union) together.
 * @param mapData map set data
 * @param elementSerializer element object Kryo serializer
 * @param elementType element object class

 * @return the set with the same key will be reduced together.
 * @throws Mp4jException
 */
public <T> Map<String, Set<T>> allreduceMapSetUnion(Map<String, Set<T>> mapData, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {

    Operand operand = Operands.OBJECT_OPERAND(new Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
    IOperator operator = new IObjectOperator<Set<T>>() {
        @Override
        public Set<T> apply(Set<T> o1, Set<T> o2) {
            for (T val : o2) {
                o1.add(val);
            }
            return o1;
        }
    };

    return allreduceMap(mapData, operand, operator);

}
 
開發者ID:yuantiku,項目名稱:ytk-mp4j,代碼行數:26,代碼來源:ProcessCommSlave.java

示例15: reduceMapSetUnion

import com.esotericsoftware.kryo.Serializer; //導入依賴的package包/類
/**
 * Set union, the set with the same key will be reduced(union) together in the root process and thread.
 * @param mapData map set data
 * @param rootRank root rank
 * @param elementSerializer element object Kryo serializer
 * @param elementType element object class

 * @return if this process and thread is root, the set with the same key will be reduced together,
 *         otherwise, invalid map or null is returned.
 * @throws Mp4jException
 */
public <T> Map<String, Set<T>> reduceMapSetUnion(Map<String, Set<T>> mapData, int rootRank, int rootThreadId, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {

    Operand operand = Operands.OBJECT_OPERAND(new ProcessCommSlave.Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
    IOperator operator = new IObjectOperator<Set<T>>() {
        @Override
        public Set<T> apply(Set<T> o1, Set<T> o2) {
            for (T val : o2) {
                o1.add(val);
            }
            return o1;
        }
    };

    return reduceMap(mapData, operand, operator, rootRank, rootThreadId);

}
 
開發者ID:yuantiku,項目名稱:ytk-mp4j,代碼行數:28,代碼來源:ThreadCommSlave.java


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