/** * Preallocates a packet with internal buffer of the supplied size. * * @param size number of bytes to pre allocate */ public JMemoryPacket(int size) { super(size, 0); header.setWirelen(size); /** Bug #2878768 JMemoryPacket(int) constructor doesn't work */ super.peer(super.memory); }
/** * Initializes the packet's state and data by doing a deep copy of the contents of the buffer. * * @param buffer buffer containing both state and data in the form * <pre> * +--------------+-------------+ * | packet state | packet data | * +--------------+-------------+ * </pre> */ public JMemoryPacket(byte[] buffer) { super(Type.POINTER); final JBuffer mem = getMemoryBuffer(buffer); super.peer(mem); header.setWirelen(buffer.length); }
/** * Initializes the packet's state and data by doing a deep copy of the contents of the buffer. * * @param buffer buffer containing both state and data in the form * <pre> * +--------------+-------------+ * | packet state | packet data | * +--------------+-------------+ * </pre> * * @throws PeeringException if there is a problem peering with the buffer */ public JMemoryPacket(ByteBuffer buffer) throws PeeringException { super(Type.POINTER); final int size = buffer.limit() - buffer.position(); final JBuffer mem = getMemoryBuffer(size); super.peer(mem); transferFrom(buffer); header.setWirelen(size); }