code: private static void writeIterator(Iterator<?> iterator, CharBuf buffer) {
          if (iterator.hasNext()) {
              buffer.addChar('[');
              Object it = iterator.next();
              writeObject(it, buffer);
              while (iterator.hasNext()) {
                  it = iterator.next();
                  buffer.addChar(',');
                  writeObject(it, buffer);
              }
              buffer.addChar(']');
          } else {
              buffer.addChars(EMPTY_LIST_CHARS);
          }
      }
docs: Serializes iterator and writes it into specified buffer.