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


Java Kryo.writeClassAndObject方法代碼示例

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


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

示例1: apply

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public byte[] apply(Object value) {
    try {
        Kryo kryo = kryoThreadLocal.get();
        ByteArrayOutputStream bos = new ByteArrayOutputStream(256);
        Output output = new Output(bos);
        output.writeInt(IDENTITY_NUMBER);
        kryo.writeClassAndObject(output, value);
        output.close();
        return bos.toByteArray();
    } catch (Exception e) {
        StringBuilder sb = new StringBuilder("Kryo Encode error. ");
        sb.append("msg=").append(e.getMessage());
        throw new CacheEncodeException(sb.toString(), e);
    }
}
 
開發者ID:alibaba,項目名稱:jetcache,代碼行數:17,代碼來源:KryoValueEncoder.java

示例2: serializationObject

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
private byte[] serializationObject(Kryo kryo, byte[] obj) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output output = new Output(baos);
    kryo.writeClassAndObject(output, obj);
    output.flush();
    output.close();

    byte[] b = baos.toByteArray();
    try {
        baos.flush();
        baos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return b;
}
 
開發者ID:PAA-NCIC,項目名稱:SparkSeq,代碼行數:18,代碼來源:TestKryo.java

示例3: write

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

示例4: 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

示例5: serializationObject

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
private <T extends Serializable> byte[] serializationObject(T obj) {
    Kryo kryo = new Kryo();
    kryo.setReferences(false);
    kryo.register(obj.getClass(), new JavaSerializer());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output output = new Output(baos);
    kryo.writeClassAndObject(output, obj);
    output.flush();
    output.close();

    byte[] b = baos.toByteArray();
    try {
        baos.flush();
        baos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return b;
}
 
開發者ID:PAA-NCIC,項目名稱:SparkSeq,代碼行數:22,代碼來源:TestMapDataSerialization.java

示例6: write

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

示例7: serialize

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
/**
 * Serializes given object to byte array using Kryo instance in pool.
 *
 * @param obj Object to serialize
 * @param bufferSize maximum size of serialized bytes
 * @return serialized bytes
 */
public byte[] serialize(final Object obj, final int bufferSize) {
    ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
    try {
        Kryo kryo = borrow();
        try {
            kryo.writeClassAndObject(out, obj);
            out.flush();
            return out.toBytes();
        } finally {
            release(kryo);
        }
    } finally {
        out.release();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:23,代碼來源:KryoNamespace.java

示例8: serialize

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void serialize(OutputStream output, Object object) throws IOException {
    Kryo kryo = pool.borrow();
    Output out = new Output(output);
    kryo.writeClassAndObject(out, object);
    out.close();
    output.close();
    pool.release(kryo);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:10,代碼來源:KryoSerialize.java

示例9: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(Kryo kryo, Output output, ImmutableList<?> object) {
    output.writeInt(object.size());
    for (Object e : object) {
        kryo.writeClassAndObject(output, e);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:8,代碼來源:ImmutableListSerializer.java

示例10: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(Kryo kryo, Output output, EncodedDiscreteResources object) {
    List<ClosedOpenRange> ranges = object.rangeSet().asRanges().stream()
            .map(ClosedOpenRange::of)
            .collect(Collectors.toList());
    kryo.writeObject(output, ranges);
    kryo.writeClassAndObject(output, object.codec());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:9,代碼來源:EncodedResourcesSerializer.java

示例11: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(final Kryo kryo, final Output output, final ImmutableList<Object> object) {
  output.writeInt(object.size(), true);
  final UnmodifiableIterator iterator = object.iterator();

  while (iterator.hasNext()) {
    final Object value = iterator.next();
    kryo.writeClassAndObject(output, value);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:11,代碼來源:ImmutableCollectionSerializers.java

示例12: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
public void write (Kryo kryo, Output output, ArrayMap map) {
    output.writeBoolean(map.ordered);
    int length = map.size;
    output.writeVarInt(length, true);
    kryo.writeClass(output, map.keys.getClass().getComponentType());
    kryo.writeClass(output, map.values.getClass().getComponentType());

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

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        ObjectMap.Entry entry = (ObjectMap.Entry)iter.next();
        if (keySerializer != null) {
            kryo.writeObject(output, entry.key, keySerializer);
        } else
            kryo.writeClassAndObject(output, entry.key);
        if (valueSerializer != null) {
            kryo.writeObjectOrNull(output, entry.value, valueSerializer);
        } else
            kryo.writeClassAndObject(output, entry.value);
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:31,代碼來源:ArrayMapSerializer.java

示例13: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(Kryo kryo, Output output, DefaultLink object) {
    kryo.writeClassAndObject(output, object.providerId());
    kryo.writeClassAndObject(output, object.src());
    kryo.writeClassAndObject(output, object.dst());
    kryo.writeClassAndObject(output, object.type());
    kryo.writeClassAndObject(output, object.state());
    output.writeBoolean(object.isDurable());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:10,代碼來源:DefaultLinkSerializer.java

示例14: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(Kryo kryo, Output output, ConnectPoint object) {
    kryo.writeClassAndObject(output, object.elementId());
    kryo.writeClassAndObject(output, object.port());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:6,代碼來源:ConnectPointSerializer.java

示例15: write

import com.esotericsoftware.kryo.Kryo; //導入方法依賴的package包/類
@Override
public void write(Kryo kryo, Output output, InternalPortEvent event) {
    kryo.writeClassAndObject(output, event.providerId());
    kryo.writeClassAndObject(output, event.deviceId());
    kryo.writeClassAndObject(output, event.portDescriptions());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:7,代碼來源:InternalPortEventSerializer.java


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