本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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;
}
示例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());
}
示例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);
// }
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}