public MessagePackGenerator( int features, ObjectCodec codec, OutputStream out, MessagePack.PackerConfig packerConfig, boolean reuseResourceInGenerator) throws IOException { super(features, codec); this.output = out; OutputStreamBufferOutput messageBufferOutput; if (reuseResourceInGenerator) { messageBufferOutput = messageBufferOutputHolder.get(); if (messageBufferOutput == null) { messageBufferOutput = new OutputStreamBufferOutput(out); messageBufferOutputHolder.set(messageBufferOutput); } else { messageBufferOutput.reset(out); } } else { messageBufferOutput = new OutputStreamBufferOutput(out); } this.messagePacker = packerConfig.newPacker(messageBufferOutput); this.packerConfig = packerConfig; this.stack = new LinkedList<StackItem>(); }
/** * Creates a packer that serializes objects into the specified output. * <p> * {@link org.msgpack.core.buffer.MessageBufferOutput} is an interface that lets applications customize memory * allocation of internal buffer of {@link MessagePacker}. You may prefer {@link #newDefaultBufferPacker()}, * {@link #newDefaultPacker(OutputStream)}, or {@link #newDefaultPacker(WritableByteChannel)} methods instead. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>. * * @param out A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in them * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(MessageBufferOutput out) { return DEFAULT_PACKER_CONFIG.newPacker(out); }
/** * Creates a packer that serializes objects into the specified output stream. * <p> * Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering * internally. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>. * * @param out The output stream that receives sequence of bytes * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(OutputStream out) { return DEFAULT_PACKER_CONFIG.newPacker(out); }
/** * Creates a packer that serializes objects into the specified output stream. * <p> * Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering * internally. * * @param out The output stream that receives sequence of bytes * @return A new MessagePacker instance */ public MessagePacker newPacker(OutputStream out) { return newPacker(new OutputStreamBufferOutput(out, bufferSize)); }
/** * Creates a packer that serializes objects into the specified writable channel. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(channel)</code>. * * @param channel The output channel that receives sequence of bytes * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(WritableByteChannel channel) { return DEFAULT_PACKER_CONFIG.newPacker(channel); }
/** * Creates a packer that serializes objects into the specified writable channel. * * @param channel The output channel that receives sequence of bytes * @return A new MessagePacker instance */ public MessagePacker newPacker(WritableByteChannel channel) { return newPacker(new ChannelBufferOutput(channel, bufferSize)); }