com.esotericsoftware.kryo.io.Output.setOutputStream()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(119)

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

Output.setOutputStream介绍

[英]Sets a new OutputStream. The position and total are reset, discarding any buffered bytes.
[中]设置一个新的输出流。重置位置和总数,丢弃所有缓冲字节。

代码示例

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

ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream) {
 super(bufferSize, maxBufferSize);
 super.setOutputStream(stream);
 this.stream = stream;
}

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

ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream)
{
  super(bufferSize, maxBufferSize);
  super.setOutputStream(stream);
  this.stream = stream;
}

代码示例来源:origin: io.atomix/atomix-utils

ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream) {
  super(bufferSize, maxBufferSize);
  super.setOutputStream(stream);
  this.stream = stream;
}

代码示例来源:origin: usc-cloud/goffish

@Override
public synchronized Output prepareStream(OutputStream stream) throws IOException {
  Output output = new Output(new byte[_bufferSize]);
  output.setOutputStream(stream);
  return output;
}

代码示例来源:origin: org.apache.apex/apex-common

public static void store(OutputStream stream, Object operator)
{
 synchronized (kryo) {
  Output output = new Output(4096, Integer.MAX_VALUE);
  output.setOutputStream(stream);
  kryo.writeClassAndObject(output, operator);
  output.flush();
 }
}

代码示例来源:origin: org.apache.giraph/giraph-core

raf.seek(file.length());
output.setOutputStream(new FileOutputStream(raf.getFD()));

代码示例来源:origin: co.paralleluniverse/quasar-core

@Override
public void write(OutputStream os, Object object) {
  final Output out = getOutput();
  out.clear();
  out.setOutputStream(os);
  kryo.writeClassAndObject(out, object);
  out.flush();
  out.setOutputStream(null);
}

代码示例来源:origin: dawnbreaks/NettyRPC

public static void write(Object obj, ByteBuf buf) {
  Kryo kryo = threadLocalkryoCodec.get();
  ByteBufOutputStream byteOutputStream = new ByteBufOutputStream(buf);
  Output output = new Output(1024*4, -1);
  output.setOutputStream(byteOutputStream);
  kryo.writeClassAndObject(output, output);
  output.flush();
}

代码示例来源:origin: co.paralleluniverse/galaxy

@Override
public void write(OutputStream os, Object object) {
  final Output out = getOutput();
  out.clear();
  out.setOutputStream(os);
  kryo.writeClassAndObject(out, object);
  out.flush();
  out.setOutputStream(null);
}

代码示例来源:origin: org.apache.apex/apex-engine

public void setOutputStream(@Nullable final OutputStream out) throws IOException
{
 final Output output;
 if (out != null) {
  output = new Output(4096, -1)
  {
   @Override
   public void flush() throws KryoException
   {
    super.flush();
    // Kryo does not flush internal output stream during flush. We need to flush it explicitly.
    try {
     getOutputStream().flush();
    } catch (IOException e) {
     throw new KryoException(e);
    }
   }
  };
  output.setOutputStream(out);
 } else {
  output = null;
 }
 final Output oldOut = this.output.getAndSet(output);
 if (oldOut != null && oldOut.getOutputStream() != out) {
  synchronized (oldOut) {
   oldOut.close();
  }
 }
}

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

/**
 * Serializes given data to the {@link OutputStream}.
 *
 * @param data
 *            Data to serialize.
 * @param outputStream
 *            {@link OutputStream}
 * @param closeStream
 *            If given output stream should be closed upon finish.
 * @throws SerializationException
 *             If serialization fails.
 */
protected void serializeDataToOutputStream(Object data, OutputStream outputStream, boolean closeStream) throws SerializationException {
  ISerializer serializer = serializationManagerProvider.createSerializer();
  Output output = null;
  try {
    output = new Output(outputStream);
    serializer.serialize(data, output);
  } finally {
    if (null != output) {
      if (!closeStream) {
        output.setOutputStream(null);
      }
      output.close();
    }
  }
}

代码示例来源:origin: com.ebay.jetstream/jetstream-messaging

private byte[] kryoSerialize(JetstreamEvent o) {
  KryoContext kryoContext = kryoContextHolder.get();
  Kryo kryo = kryoContext.getKryo();
  Output output = kryoContext.getOut();
  output.clear();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  output.setOutputStream(out);
  output.writeByte(KRYO_STREAM_VERSION);
  kryo.writeClassAndObject(output, o);
  output.flush();
  try {
    out.flush();
    out.close();
  } catch (IOException e) {
    //ingore
  }
  
  output.close();
  
  return out.toByteArray();
}

代码示例来源:origin: com.ebay.jetstream/jetstreamcore

@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
  KryoContext kryoContext = kryoContextHolder.get();
  Kryo kryo = kryoContext.getKryo();
  Output output = kryoContext.getOut();
  output.clear();
  ByteBufOutputStream bout = new ByteBufOutputStream(out);
  int startIdx = out.writerIndex();
  bout.write(LENGTH_PLACEHOLDER);
  output.setOutputStream(bout);
  output.writeByte(StreamMessageDecoder.KRYO_STREAM_VERSION);
  kryo.writeClassAndObject(output, msg);
  output.flush();
  bout.flush();
  bout.close();
  output.close();
  
  int endIdx = out.writerIndex();
  out.setInt(startIdx, endIdx - startIdx - 4);
}

相关文章