@Override public void format(AssociationMessage message, ByteBuffer bb) { if (null == message) { throw new IllegalStateException("No ApplicationMessage set"); } setType(message.getType()); ByteBuffer bbAppMessage = ByteBuffer.allocate(5000); message.format(bbAppMessage); presentationLength.setLength( bbAppMessage.position() + message.getPresentationHeader().length + message.getPresentationTrailer().length); length.setLength( presentationLength.getByteCount() + sessionLength() + presentationLength.getLength()); bbAppMessage.flip(); Bits.putUnsignedByte(bb, type.asShort()); length.format(bb); LengthInformation li = new LengthInformation(); for (ParameterIdentifier pi : parameterIdentifiers) { Bits.putUnsignedByte(bb, pi.id); li.setLength(pi.data.length); li.format(bb); bb.put(pi.data); } presentationLength.format(bb); bb.put(message.getPresentationHeader()); bb.put(bbAppMessage); bb.put(message.getPresentationTrailer()); }