ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream) { super(bufferSize, maxBufferSize); super.setOutputStream(stream); this.stream = stream; }
ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream) { super(bufferSize, maxBufferSize); super.setOutputStream(stream); this.stream = stream; }
ByteArrayOutput(final int bufferSize, final int maxBufferSize, final BufferAwareByteArrayOutputStream stream) { super(bufferSize, maxBufferSize); super.setOutputStream(stream); this.stream = stream; }
@Override public synchronized Output prepareStream(OutputStream stream) throws IOException { Output output = new Output(new byte[_bufferSize]); output.setOutputStream(stream); return output; }
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(); } }
raf.seek(file.length()); output.setOutputStream(new FileOutputStream(raf.getFD()));
@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); }
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(); }
@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); }
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(); } } }
/** * 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(); } } }
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(); }
@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); }