code: @Override
      public AbstractIoBufferEx putString(CharSequence val, int fieldSize,
              CharsetEncoder encoder) throws CharacterCodingException {
          checkFieldSize(fieldSize);
  
          if (fieldSize == 0) {
              return this;
          }
  
          autoExpand(fieldSize);
  
          boolean utf16 = encoder.charset().name().startsWith("UTF-16");
  
          if (utf16 && (fieldSize & 1) != 0) {
              throw new IllegalArgumentException("fieldSize is not even.");
          }
  
          int oldLimit = limit();
          int end = position() + fieldSize;
  
          if (oldLimit < end) {
              throw new BufferOverflowException();
          }
  
          if (val.length() == 0) {
              if (!utf16) {
                  put((byte) 0x00);
              } else {
                  put((byte) 0x00);
                  put((byte) 0x00);
              }
              position(end);
              return this;
          }
  
          CharBuffer in = CharBuffer.wrap(val);
          limit(end);
          encoder.reset();
  
          for (;;) {
              CoderResult cr;
              if (in.hasRemaining()) {
                  cr = encoder.encode(in, buf(), true);
              } else {
                  cr = encoder.flush(buf());
              }
  
              if (cr.isUnderflow() || cr.isOverflow()) {
                  break;
              }
              cr.throwException();
          }
  
          limit(oldLimit);
  
          if (position() < end) {
              if (!utf16) {
                  put((byte) 0x00);
              } else {
                  put((byte) 0x00);
                  put((byte) 0x00);
              }
          }
  
          position(end);
          return this;
      }
docs: {@inheritDoc}