code: public void setBuffer(@Nonnull ByteBuffer buffer) {
  		if (buffer.hasArray()) {
  			this.buffer = buffer.array();
  			this.position = buffer.arrayOffset() + buffer.position();
  			this.end = this.position + buffer.remaining();
  		} else if (buffer.isDirect() || buffer.isReadOnly()) {
  			// TODO: FLINK-8585 handle readonly and other non array based buffers more efficiently without data copy
  			this.buffer = new byte[buffer.remaining()];
  			this.position = 0;
  			this.end = this.buffer.length;
  
  			buffer.get(this.buffer);
  		} else {
  			throw new IllegalArgumentException("The given buffer is neither an array-backed heap ByteBuffer, nor a direct ByteBuffer.");
  		}
  	}
docs: ------------------------------------------------------------------------