code: public static String getString(ByteBuffer buf, int offset, int length, Charset encoding) {
          buf = buf.duplicate();
          buf.position(buf.position() + offset);
          if (buf.hasArray()) {
              return new String(buf.array(), buf.arrayOffset() + buf.position(), length, encoding);
          } else {
              byte[] bytes = new byte[length];
              buf.get(bytes);
              return new String(bytes, encoding);
          }
      }
docs: Converts the specified number of bytes in the buffer and converts them to a String using
  the specified encoding.  Does not move the buffer position.