当前位置: 首页>>代码示例>>Java>>正文


Java Kryo.writeObject方法代码示例

本文整理汇总了Java中com.esotericsoftware.kryo.Kryo.writeObject方法的典型用法代码示例。如果您正苦于以下问题:Java Kryo.writeObject方法的具体用法?Java Kryo.writeObject怎么用?Java Kryo.writeObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.esotericsoftware.kryo.Kryo的用法示例。


在下文中一共展示了Kryo.writeObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
/**
 * 序列化
 *
 * @param obj 需要序更列化的对象
 * @return 序列化后的byte 数组
 * @throws TransactionException
 */
@Override
public byte[] serialize(Object obj) throws TransactionException {
    byte[] bytes;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        //获取kryo对象
        Kryo kryo = new Kryo();
        Output output = new Output(outputStream);
        kryo.writeObject(output, obj);
        bytes = output.toBytes();
        output.flush();
    } catch (Exception ex) {
        throw new TransactionException("kryo serialize error" + ex.getMessage());
    } finally {
        try {
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {

        }
    }
    return bytes;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:31,代码来源:KryoSerializer.java

示例2: serialize

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
/**
 * 序列化
 *
 * @param obj 需要序更列化的对象
 * @return 序列化后的byte 数组
 * @throws TccException
 */
@Override
public byte[] serialize(Object obj) throws TccException {
    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 TccException("kryo serialize error" + ex.getMessage());
    }
    return bytes;
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:23,代码来源:KryoSerializer.java

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

示例4: encode

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
    if(clazz.isInstance(o)){
        Kryo kryo = null;
        try{
        	kryo = pool.borrow();
        	ByteArrayOutputStream baos = new ByteArrayOutputStream();  
            Output output = new Output(baos);  
            kryo.writeObject(output, o);  
            output.flush();  
            output.close();  
           
            byte[] data = baos.toByteArray(); 
            byteBuf.writeInt(data.length);
            byteBuf.writeBytes(data);
            baos.close();
        }catch(Exception e){
        	LOG.warn("MessageEncoder happen exception.", e);
        }finally{
        	if(kryo != null){
        		 pool.release(kryo);
        	}
        }
        
    }

}
 
开发者ID:islittlechen,项目名称:lionrpc,代码行数:27,代码来源:MessageEncoder.java

示例5: save

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
public void save(@NonNull Context context)
{
	Kryo serialiser = createSerialiser();

	Log.d(TAG, "Save geofencing state... ");
	String path = context.getFilesDir().getAbsolutePath() + "/" + CACHE_FILE;
	Log.d(TAG, "Saving geofencing state to" + path);
	try
	{
		Output output = new Output(new FileOutputStream(path));
		serialiser.writeObject(output, this);
		output.close();
	}
	catch (FileNotFoundException e)
	{
		Log.e(TAG, "Could not serialise geofencing data", e);
	}
}
 
开发者ID:martijndeh,项目名称:react-native-region-monitor,代码行数:19,代码来源:PersistableData.java

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

示例7: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final TableMetadata table) {
  try{
    Preconditions.checkArgument(!table.isPruned(), "Cannot serialize a pruned table.");
  }catch(NamespaceException ex){
    throw Throwables.propagate(ex);
  }

  kryo.writeObject(output, table.getName().getPathComponents());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:TableMetadataSerializer.java

示例8: serialize

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Test
    public void serialize() throws Exception {
        String testFilePath = getClass().getClassLoader().getResource("lstm_har-data").getFile();
        String inputFilePath =
                testFilePath + File.separator + "test_data" + File.separator + "sensor";
        final float[][][] inputs;

        final Kryo kryo = new Kryo();
        kryo.register(float[][][].class);
        final File dataBinFile = new File("data-small.bin");
        if (dataBinFile.exists()) {
            Input input = new Input(new FileInputStream(dataBinFile));
            inputs = kryo.readObject(input, float[][][].class);
            input.close();
        } else {
            inputs = DataUtil.parseInputData(inputFilePath);
            Output output = new Output(new FileOutputStream(dataBinFile));

            kryo.writeObject(output, inputs);
            output.close();
        }

//        Gson gson = new Gson();
//        final File dataBinFile = new File("data.json");
//        if (dataBinFile.exists()) {
//            inputs = gson.fromJson(FileUtils.readFileToString(dataBinFile), float[][][].class);
//        } else {
//            inputs = DataUtil.parseInputData(inputFilePath);
//            String result = gson.toJson(inputs);
//            FileUtils.writeStringToFile(new File("data.json"), result);
//        }


    }
 
开发者ID:csarron,项目名称:MobiRNN-EMDL17,代码行数:35,代码来源:DataUtilTest.java

示例9: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final T operator) {
  final int identity = System.identityHashCode(operator);
  final Integer ordinal = OperatorPopulator.FORWARD.get(identity);
  final boolean isKnown = ordinal != null;
  kryo.writeObject(output, isKnown);
  if (isKnown) {
    kryo.writeObject(output, ordinal);
    return;
  }

  super.write(kryo, output, operator);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:14,代码来源:SqlOperatorSerializer.java

示例10: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(Kryo kryo, Output output, ImmutableMap<?, ?> object) {
    // wrapping with unmodifiableMap proxy
    // to avoid Kryo from writing only the reference marker of this instance,
    // which will be embedded right before this method call.
    kryo.writeObject(output, Collections.unmodifiableMap(object), mapSerializer);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:8,代码来源:ImmutableMapSerializer.java

示例11: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
public void write (Kryo kryo, Output output, T map) {
    int length = map.size;
    output.writeVarInt(length, true);
    output.writeBoolean(false); // whether type is written (in case future version of ObjectMap supports type awareness)

    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,代码行数:29,代码来源:ObjectMapSerializer.java

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

示例13: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final T object) {
  final boolean isKnown = collationSet.contains(object);
  kryo.writeObject(output, isKnown);
  if (isKnown) {
    kryo.writeObject(output, object.equals(RelCollations.EMPTY) ? 0 : 1);
    return;
  }

  super.write(kryo, output, object);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:12,代码来源:RelTraitSerializers.java

示例14: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final URL url) {
    kryo.writeObject(output, url.toExternalForm());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:5,代码来源:URLSerializer.java

示例15: write

import com.esotericsoftware.kryo.Kryo; //导入方法依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final ZonedDateTime dateTime) {
    kryo.writeObject(output, dateTime.toInstant().toEpochMilli());
    kryo.writeObject(output, dateTime.getZone().getId());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:6,代码来源:ZonedDateTimeTranscoder.java


注:本文中的com.esotericsoftware.kryo.Kryo.writeObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。