code: @Override
    public String getPrefixedString(int prefixLength, CharsetDecoder decoder)
        throws CharacterCodingException {
      if (!prefixedDataAvailable(prefixLength)) {
        throw new BufferUnderflowException();
      }
  
      int fieldSize = 0;
  
      switch (prefixLength) {
        case 1:
          fieldSize = getUnsigned();
          break;
        case 2:
          fieldSize = getUnsignedShort();
          break;
        case 4:
          fieldSize = getInt();
          break;
      }
  
      if (fieldSize == 0) {
        return "";
      }
  
      boolean utf16 = decoder.charset().name().startsWith("UTF-16");
  
      if (utf16 && (fieldSize & 1) != 0) {
        throw new BufferDataException("fieldSize is not even for a UTF-16 string.");
      }
  
      int oldLimit = limit();
      int end = position() + fieldSize;
  
      if (oldLimit < end) {
        throw new BufferUnderflowException();
      }
  
      limit(end);
      decoder.reset();
  
      int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
      CharBuffer out = CharBuffer.allocate(expectedLength);
      for (;;) {
        CoderResult cr;
        if (hasRemaining()) {
          cr = decoder.decode(buf(), out, true);
        } else {
          cr = decoder.flush(out);
        }
  
        if (cr.isUnderflow()) {
          break;
        }
  
        if (cr.isOverflow()) {
          CharBuffer o = CharBuffer.allocate(out.capacity() + expectedLength);
          out.flip();
          o.put(out);
          out = o;
          continue;
        }
  
        cr.throwException();
      }
  
      limit(oldLimit);
      position(end);
      return out.flip().toString();
    }
docs: Reads a string which has a length field before the actual encoded string, using the specified
  <code>decoder</code> and returns it.
  
  @param prefixLength the length of the length field (1, 2, or 4)
  @param decoder the decoder to use for decoding the string
  @return the prefixed string
  @throws CharacterCodingException when decoding fails
  @throws BufferUnderflowException when there is not enough data available