com.esotericsoftware.kryo.Kryo.writeClassAndObject()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中com.esotericsoftware.kryo.Kryo.writeClassAndObject()方法的一些代码示例,展示了Kryo.writeClassAndObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.writeClassAndObject()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:writeClassAndObject

Kryo.writeClassAndObject介绍

[英]Writes the class and object or null using the registered serializer.
[中]使用注册的序列化程序写入类和对象或null。

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
public void writeObject(Object v) throws IOException {
  // TODO carries class info every time.
  kryo.writeClassAndObject(output, v);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public void writeObject(Object v) throws IOException {
  // TODO carries class info every time.
  kryo.writeClassAndObject(output, v);
}

代码示例来源:origin: changmingxie/tcc-transaction

public byte[] execute(Kryo kryo) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Output output = new Output(byteArrayOutputStream);
    kryo.writeClassAndObject(output, object);
    output.flush();
    return byteArrayOutputStream.toByteArray();
  }
});

代码示例来源:origin: apache/storm

@Override
public byte[] serialize(T obj) {
  output.get().clear();
  kryo.get().writeClassAndObject(output.get(), obj);
  return output.get().toBytes();
}

代码示例来源:origin: atomix/atomix

@Override
public void write(Kryo kryo, Output output, ImmutableSet<?> object) {
 output.writeInt(object.size());
 for (Object e : object) {
  kryo.writeClassAndObject(output, e);
 }
}

代码示例来源:origin: atomix/atomix

@Override
public void write(Kryo kryo, Output output, ImmutableList<?> object) {
 output.writeInt(object.size());
 for (Object e : object) {
  kryo.writeClassAndObject(output, e);
 }
}

代码示例来源:origin: atomix/atomix

@Override
public void write(Kryo kryo, Output output, List<?> object) {
 output.writeInt(object.size(), true);
 for (Object elm : object) {
  kryo.writeClassAndObject(output, elm);
 }
}

代码示例来源:origin: apache/storm

private byte[] getKryoSerializedBytes (final Object obj) {
  final Kryo kryo = new Kryo();
  final ByteArrayOutputStream os = new ByteArrayOutputStream();
  final Output output = new Output(os);
  kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
  kryo.writeClassAndObject(output, obj);
  output.flush();
  return os.toByteArray();
}

代码示例来源:origin: changmingxie/tcc-transaction

public static <T> byte[] writeToByteArray(T obj) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  Output output = new Output(byteArrayOutputStream);
  Kryo kryo = getInstance();
  kryo.writeClassAndObject(output, obj);
  output.flush();
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: changmingxie/tcc-transaction

public static <T> byte[] writeToByteArray(T obj) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  Output output = new Output(byteArrayOutputStream);
  Kryo kryo = getInstance();
  kryo.writeClassAndObject(output, obj);
  output.flush();
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: apache/hive

@Override
public void write(final Kryo kryo, final Output output, final List<?> obj) {
 try {
   kryo.writeClassAndObject(output, _parentField.get(obj));
   final int parentOffset = _parentOffsetField.getInt( obj );
   final int fromIndex = parentOffset;
   output.writeInt(fromIndex, true);
   final int toIndex = fromIndex + _sizeField.getInt( obj );
   output.writeInt(toIndex, true);
 } catch (final Exception e) {
     throw new RuntimeException(e);
 }
}

代码示例来源:origin: apache/storm

/**
 * Serializes the given object into a byte array using Kryo serialization.
 *
 * @param obj Object to be serialized.
 */
public byte[] serialize(Object obj) {
  output.clear();
  kryo.writeClassAndObject(output, obj);
  return output.toBytes();
}

代码示例来源:origin: apache/storm

public byte[] serializeObject(Object obj) {
    _kryoOut.clear();
    _kryo.writeClassAndObject(_kryoOut, obj);
    return _kryoOut.toBytes();
  }
}

代码示例来源:origin: alibaba/jstorm

public byte[] serializeObject(Object obj) {
  _kryoOut.clear();
  _kryo.writeClassAndObject(_kryoOut, obj);
  return _kryoOut.toBytes();
}

代码示例来源:origin: alibaba/jstorm

@Override
public byte[] serialize(T obj) {
  output.clear();
  kryo.writeClassAndObject(output, obj);
  return output.toBytes();
}

代码示例来源:origin: alibaba/jstorm

@Override
public byte[] serialize(T obj) {
  output.clear(); 
  kryo.writeClassAndObject(output, obj);
  return output.toBytes();
}

代码示例来源:origin: apache/storm

/**
 * Serializes the given object into a {@link ByteBuffer} backed by the byte array returned by Kryo serialization.
 *
 * @param obj Object to be serialized.
 */
public ByteBuffer serializeToByteBuffer(Object obj) {
  output.clear();
  kryo.writeClassAndObject(output, obj);
  return ByteBuffer.wrap(output.getBuffer(), 0, output.position());
}

代码示例来源:origin: apache/hive

public void add(ROW row) {
 Kryo kryo = SerializationUtilities.borrowKryo();
 try {
  kryo.writeClassAndObject(output, row);
 } finally {
  SerializationUtilities.releaseKryo(kryo);
 }
 rowsOnDisk++;
}

代码示例来源:origin: yu199195/Raincat

@Override
public void serialize(final OutputStream output, final Object object) throws IOException {
  Kryo kryo = pool.borrow();
  Output out = new Output(output);
  kryo.writeClassAndObject(out, object);
  out.close();
  output.close();
  pool.release(kryo);
}

代码示例来源:origin: redisson/redisson

@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);
      }
    }
  }
};

相关文章