code: private void _writeSegment(int end)
              throws IOException, JsonGenerationException
      {
          int ptr = 0;
          int start = ptr;
  
          output_loop:
          while (ptr < end) {
              // Fast loop for chars not needing escaping
              char c;
              while (true) {
                  c = _outputBuffer[ptr];
                  if (c == '!' || c == '\'') {
                      break;
                  }
                  if (++ptr >= end) {
                      break;
                  }
              }
  
              // Ok, bumped into something that needs escaping.
              /* First things first: need to flush the buffer.
               * Inlined, as we don't want to lose tail pointer
               */
              int flushLen = (ptr - start);
              if (flushLen > 0) {
                  _writer.write(_outputBuffer, start, flushLen);
                  if (ptr >= end) {
                      break output_loop;
                  }
              }
              // So; either try to prepend (most likely), or write directly:
              start = _prependOrWrite(_outputBuffer, ptr, '!');
              ptr++;  // advance past the char-to-be-escaped
  
              // Flush the last 1 or 2 characters if this is the last time though the loop
              if (ptr == end) {
                  _writer.write(_outputBuffer, start, ptr - start);
                  break output_loop;
              }
          }
      }
docs: Method called to output textual context which has been copied
  to the output buffer prior to call. If any escaping is needed,
  it will also be handled by the method.
  <p>
  Note: when called, textual content to write is within output
  buffer, right after buffered content (if any). That's why only
  length of that text is passed, as buffer and offset are implied.