code: private static Pointer computePointer(ByteBuffer buffer)
      {
          Pointer result = null;
          if (buffer.isDirect())
          {
              int oldPosition = buffer.position();
              buffer.position(0);
              result = Pointer.to(buffer.slice()).withByteOffset(
                  oldPosition * Sizeof.BYTE);
              buffer.position(oldPosition);
          }
          else if (buffer.hasArray())
          {
              ByteBuffer t = ByteBuffer.wrap(buffer.array());
              int elementOffset = buffer.position() + buffer.arrayOffset();
              result = Pointer.to(t).withByteOffset(
                  elementOffset * Sizeof.BYTE);
          }
          return result;
      }
docs: Creates a new Pointer to the given buffer, taking into
  account the position and array offset of the given buffer.
  The buffer is assumed to be non-<code>null</code>, and
  be either direct or have a backing array.
  
  @param buffer The buffer
  @return The pointer