code: @Override
    public int encodedLength(CharSequence in) {
      final Cache cache = CACHE.get();
      int estimated = (int) (in.length() * cache.encoder.maxBytesPerChar());
      if (cache.lastOutput == null || cache.lastOutput.capacity() < estimated) {
        cache.lastOutput = ByteBuffer.allocate(Math.max(128, estimated));
      }
      cache.lastOutput.clear();
      cache.lastInput = in;
      CharBuffer wrap = (in instanceof CharBuffer) ?
                            (CharBuffer) in : CharBuffer.wrap(in);
      CoderResult result = cache.encoder.encode(wrap, cache.lastOutput, true);
      if (result.isError()) {
        try {
          result.throwException();
        } catch (CharacterCodingException e) {
          throw new IllegalArgumentException("bad character encoding", e);
        }
      }
      return cache.lastOutput.remaining();
    }
docs: the length of the encoded string.