code: @Override
      public AbstractIoBufferEx putString(CharSequence val, CharsetEncoder encoder)
              throws CharacterCodingException {
          if (val.length() == 0) {
              return this;
          }
  
          CharBuffer in = CharBuffer.wrap(val);
          encoder.reset();
  
          int expandedState = 0;
  
          for (;;) {
              CoderResult cr;
              if (in.hasRemaining()) {
                  cr = encoder.encode(in, buf(), true);
              } else {
                  cr = encoder.flush(buf());
              }
  
              if (cr.isUnderflow()) {
                  break;
              }
              if (cr.isOverflow()) {
                  if (isAutoExpand()) {
                      switch (expandedState) {
                      case 0:
                          autoExpand((int) Math.ceil(in.remaining()
                                  * encoder.averageBytesPerChar()));
                          expandedState++;
                          break;
                      case 1:
                          autoExpand((int) Math.ceil(in.remaining()
                                  * encoder.maxBytesPerChar()));
                          expandedState++;
                          break;
                      default:
                          throw new RuntimeException("Expanded by "
                                  + (int) Math.ceil(in.remaining()
                                          * encoder.maxBytesPerChar())
                                  + " but that wasn't enough for '" + val + "'");
                      }
                      continue;
                  }
              } else {
                  expandedState = 0;
              }
              cr.throwException();
          }
          return this;
      }
docs: {@inheritDoc}