code: public static void putByteBuffer(ByteBuffer source, ByteBuffer target) {
          if (source.hasArray()) {
              byte[] array = source.array();
              int arrayOffset = source.arrayOffset();
              target.put(array, arrayOffset + source.position(), source.remaining());
          }
          else {
              target.put(source.duplicate());
          }
      }
docs: Writes the contents of source to target without mutating source (so safe for
  multithreaded access to source) and without GC (unless source is a direct buffer).