code: public static byte[] getBytes(ByteBuffer buf) {
      int savedPos = buf.position();
      byte [] newBytes = new byte[buf.remaining()];
      buf.get(newBytes);
      buf.position(savedPos);
      return newBytes;
    }
docs: This method will get a sequence of bytes from pos -> limit,
  but will restore pos after.
  @param buf
  @return byte array