code: protected void logByteBuffer(String msg, ByteBuffer inBuffer) {
          if(!logger.isLoggable(DEBUG)) return;
  
          ByteBuffer bb = inBuffer.duplicate();
  
          byte[] byData = new byte[512];
          int len = Math.min(byData.length, bb.remaining());
          byte dataByte = bb.get();
          int pos = 0;
          while(pos < len && dataByte != '~') {
              byData[pos] = dataByte;
              pos++;
              dataByte = bb.get();
          }
  
          logger.log(DEBUG, msg + ". Content: " + new String(byData, 0, pos));
      }
docs: Helper method that logs the entire message buffer when at debug logging level.
  @param msg the message to print first
  @param inBuffer the buffer to be logged