/*
********************************************************
/* Internal methods, low-level writing; text, default
********************************************************
557807
private void _writeString(String text)
        throws IOException, JsonGenerationException
    {
        /* One check first: if String won't fit in the buffer, let's
         * segment writes. No point in extending buffer to huge sizes
         * (like if someone wants to include multi-megabyte base64
         * encoded stuff or such)
         */
        final int len = text.length();
        if (len > _outputEnd) { // Let's reserve space for entity at begin/end
            _writeLongString(text);
            return;
        }

        // Ok: we know String will fit in buffer ok
        // But do we need to flush first?
        if ((_outputTail + len) > _outputEnd) {
            _flushBuffer();
        }
        text.getChars(0, len, _outputBuffer, _outputTail);

        if (_maximumNonEscapedChar != 0) {
            _writeStringASCII(len, _maximumNonEscapedChar);
        } else {
            _writeString2(len);
        }
    }
846024
protected void writeLogging(Definition def, Writer out, int indent, String level, String content, String... params)
         throws IOException
   {
      writeIndent(out, indent);
      if (def.isSupportJbossLogging())
      {
         out.write("log.trace");
         int size = params.length;
         if (size > 0)
            out.write("f");
         out.write("(\"" + content + "(");
         for (int i = 0; i < size; i++)
         {
            out.write("%s");
            if (i < size - 1)
               out.write(", ");
         }
         out.write(")\"");
         for (int i = 0; i < size; i++)
         {
            out.write(", ");
            out.write(params[i]);
         }
         out.write(");");
      }
      else
      {
         out.write("log.finest(\"" + content + "()\");");
      }
      writeEol(out);
   }
1338649
public void writeln(String text) throws IOException {
		this.writer.write(text);
		if (text != null && text.length() > 0) {
			this.writer.write("\n"); //$NON-NLS-1$
		}
	}
1157442
static int write(FileDescriptor fd, ByteBuffer src, long position,
                     NativeDispatcher nd)
        throws IOException
    {
        if (src instanceof DirectBuffer)
            return writeFromNativeBuffer(fd, src, position, nd);

        // Substitute a native buffer
        int pos = src.position();
        int lim = src.limit();
        assert (pos <= lim);
        int rem = (pos <= lim ? lim - pos : 0);
        ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
        try {
            bb.put(src);
            bb.flip();
            // Do not update src until we see how many bytes were written
            src.position(pos);

            int n = writeFromNativeBuffer(fd, bb, position, nd);
            if (n > 0) {
                // now update src
                src.position(pos + n);
            }
            return n;
        } finally {
            Util.offerFirstTemporaryDirectBuffer(bb);
        }
    }
393729
@Override
    public void writeRaw(String text)
        throws IOException, JsonGenerationException
    {
        // Nothing to check, can just output as is
        int len = text.length();
        int room = _outputEnd - _outputTail;

        if (room == 0) {
            _flushBuffer();
            room = _outputEnd - _outputTail;
        }
        // But would it nicely fit in? If yes, it's easy
        if (room >= len) {
            text.getChars(0, len, _outputBuffer, _outputTail);
            _outputTail += len;
        } else {
            writeRawLong(text);
        }
    }
611395
function write(s) {
		var err
		var args = Array.prototype.slice.call(arguments)
		var cb = typeof args[args.length - 1] === 'function' ? args.pop() : null
		var cbCounter = 1
		if (writeToStdoutEnabled) {
			cbCounter++
			process.stdout.write(s, stdWr)
		}
		if (writeStream) {
			cbCounter++
			writeStream.write(s, wRes)
		}
		end()

		function stdWr(e) {
			if (e) {
				if (!err) err = e
				writeToStdoutEnabled = false
				write('stdout error: ' + e.message)
				self.emit('error', e)
			}
			end()
		}

		function wRes(e) {
			if (e) {
				if (!err) err = e
				writeStream = false
				write('stream error: ' + e.message)
				self.emit('error', e)
			}
			end()
		}

		function end() {
			if (!--cbCounter)
				if (cb)
					if (err) cb(err)
					else cb()
		}
	}
1145789
void writeJavadocComment(String methodComment, Writer writer) throws IOException {
		// From javadoc
		if (methodComment != null) {
			methodComment = methodComment.split("@")[0];
			int lastIndexOf = methodComment.lastIndexOf("\n");
			if (lastIndexOf >= 0) {
				methodComment = methodComment.substring(0, lastIndexOf);
			}
			String comment = methodComment.replaceAll("\n", CR+TAB2+" *");
			writer.append(TAB2).append(" *").append(comment).append(CR);
		}
	}
405851
function defaultWriteParameter(key, value, out) {
    if (key === 'headers' && value instanceof Array) {
      out.writeArrowIndentedLines(value);
      return;
    }

    // For transferred bytes, display the bytes in hex and ASCII.
    // TODO(eroman): 'hex_encoded_bytes' was removed in M73, and
    //               support for it can be removed in the future.
    if (key === 'hex_encoded_bytes' && typeof value === 'string') {
      const bytes = tryParseHexToBytes(value);
      if (bytes) {
        out.writeArrowKey(key);
        writeHexString(bytes, out);
        return;
      }
    }

    if (key === 'bytes' && typeof value === 'string') {
      const bytes = tryParseBase64ToBytes(value);
      if (bytes) {
        out.writeArrowKey(key);
        writeHexString(bytes, out);
        return;
      }
    }

    // Handle source_dependency entries - add link and map source type to
    // string.
    if (key === 'source_dependency' && typeof value === 'object') {
      const link = '#events&s=' + value.id;
      const valueStr = value.id + ' (' + EventSourceTypeNames[value.type] + ')';
      out.writeArrowKeyValue(key, valueStr, link);
      return;
    }

    if (key === 'net_error' && typeof value === 'number') {
      const valueStr = value + ' (' + netErrorToString(value) + ')';
      out.writeArrowKeyValue(key, valueStr);
      return;
    }

    if (key === 'quic_error' && typeof value === 'number') {
      const valueStr = value + ' (' + quicErrorToString(value) + ')';
      out.writeArrowKeyValue(key, valueStr);
      return;
    }

    if (key === 'quic_crypto_handshake_message' && typeof value === 'string') {
      const lines = value.split('\n');
      out.writeArrowIndentedLines(lines);
      return;
    }

    if (key === 'quic_rst_stream_error' && typeof value === 'number') {
      const valueStr = value + ' (' + quicRstStreamErrorToString(value) + ')';
      out.writeArrowKeyValue(key, valueStr);
      return;
    }

    if (key === 'load_flags' && typeof value === 'number') {
      const valueStr = value + ' (' + getLoadFlagSymbolicString(value) + ')';
      out.writeArrowKeyValue(key, valueStr);
      return;
    }

    if (key === 'load_state' && typeof value === 'number') {
      const valueStr = value + ' (' + getKeyWithValue(LoadState, value) + ')';
      out.writeArrowKeyValue(key, valueStr);
      return;
    }

    // Otherwise just default to JSON formatting of the value.
    out.writeArrowKeyValue(key, JSON.stringify(value));
  }
953985
private void internalWrite(byte[] b, int off, int len, boolean finish) throws IOException {
        coder.output = embiggen(coder.output, coder.maxOutputSize(len));
        if (!coder.process(b, off, len, finish)) {
            throw new Base64DataException("bad base-64");
        }
        out.write(coder.output, 0, coder.op);
    }
1275889
private void writeEscaped(String in)
		throws IOException
	{
		for(int i=0, n=in.length(); i<n; i++)
		{
			char c = in.charAt(i);
			if(c == '"' || c == '\\')
			{
				writer.write('\\');
				writer.write(c);
			}
			else if(c == '\r')
			{
				writer.write('\\');
				writer.write('r');
			}
			else if(c == '\n')
			{
				writer.write('\\');
				writer.write('n');
			}
			else if(c == '\t')
			{
				writer.write('\\');
				writer.write('t');
			}
			else if(c == '\b')
			{
				writer.write('\\');
				writer.write('b');
			}
			else if(c == '\f')
			{
				writer.write('\\');
				writer.write('f');
			}
			else if(c <= 0x1F)
			{
				writer.write('\\');
				writer.write('u');

				int v = c;
				int pos = 4;
				do
				{
					encoded[--pos] = DIGITS[v & HEX_MASK];
					v >>>= 4;
				}
				while (v != 0);

				for(int j=0; j<pos; j++) writer.write('0');
				writer.write(encoded, pos, 4 - pos);
			}
			else
			{
				writer.write(c);
			}
		}
	}

	/**
	 * Increase the level by one.
	 *
	 * @param list
	 */
	private void increaseLevel(boolean list)
	{
		level++;

		if(hasData.length == level)
		{
			// Grow lists when needed
			hasData = Arrays.copyOf(hasData, hasData.length * 2);
			lists = Arrays.copyOf(lists, hasData.length * 2);
		}

		hasData[level] = false;
		lists[level] = list;
	}

	/**
	 * Decrease the level by one.
	 *
	 * @throws IOException
	 */
	private void decreaseLevel()
		throws IOException
	{
		level--;

		if(beautify && hasData[level])
		{
			writer.write('\n');

			for(int i=0; i<level; i++)
			{
				writer.write("\t");
			}
		}
	}

	/**
	 * Start a write, will output commas and beautification if needed.
	 *
	 * @throws IOException
	 */
	private void startWrite()
		throws IOException
	{
		if(hasData[level]) writer.write(',');

		hasData[level] = true;

		if(beautify && level > 0)
		{
			writer.write('\n');

			for(int i=0; i<level; i++)
			{
				writer.write('\t');
			}
		}
	}

	/**
	 * Check if the name should be written or not.
	 *
	 * @return
	 */
	private boolean shouldOutputName()
	{
		return level != 0 && ! lists[level];
	}

	@Override
	public void writeObjectStart(String name)
		throws IOException
	{
		startWrite();

		if(shouldOutputName())
		{
			writer.write('"');
			writeEscaped(name);
//			writer.write("\": {");
			writer.write('"');
			writer.write(':');
		}

		writer.write('{');

		increaseLevel(false);
	}

	@Override
	public void writeObjectEnd(String name)
		throws IOException
	{
		decreaseLevel();

		writer.write('}');
	}

	@Override
	public void writeListStart(String name)
		throws IOException
	{
		startWrite();

		if(shouldOutputName())
		{
			writer.write('"');
			writeEscaped(name);
//			writer.write("\": [");
			writer.write('"');
			writer.write(':');
		}

		writer.write('[');

		increaseLevel(true);
	}

	@Override
	public void writeListEnd(String name)
		throws IOException
	{
		decreaseLevel();
		writer.write(']');
	}

	@Override
	public void write(String name, String value)
		throws IOException
	{
		startWrite();

		if(shouldOutputName())
		{
			writer.write('"');
			writeEscaped(name);
//			writer.write("\": ");
			writer.write('"');
			writer.write(':');
		}

		if(value == null)
		{
			writer.write("null");
		}
		else
		{
			writer.write('"');
			writeEscaped(value);
			writer.write('"');
		}
	}

	private void writeUnescaped(String name, String value)
		throws IOException
	{
		startWrite();

		if(shouldOutputName())
		{
			writer.write('"');
			writeEscaped(name);
//			writer.write("\": ");
			writer.write('"');
			writer.write(':');
		}

		if(value == null)
		{
			writer.write("null");
		}
		else
		{
			writer.write(value);
		}
	}

	@Override
	public void write(String name, int number)
		throws IOException
	{
		writeUnescaped(name, Integer.toString(number));
	}

	@Override
	public void write(String name, long number)
		throws IOException
	{
		writeUnescaped(name, Long.toString(number));
	}

	@Override
	public void write(String name, float number)
		throws IOException
	{
		writeUnescaped(name, Float.toString(number));
	}

	@Override
	public void write(String name, double number)
		throws IOException
	{
		writeUnescaped(name, Double.toString(number));
	}

	@Override
	public void write(String name, boolean bool)
		throws IOException
	{
		writeUnescaped(name, Boolean.toString(bool));
	}

	@Override
	public void write(String name, byte[] data)
		throws IOException
	{
		startWrite();

		if(shouldOutputName())
		{
			writer.write('"');
			writeEscaped(name);
			writer.write('"');
			writer.write(':');
		}

		if(data == null)
		{
			writer.write("null");
			return;
		}

		writer.write('"');

		int i = 0;
		for(int n=data.length - 2; i<n; i+=3)
		{
			write(data, i, 3);
		}

		if(i < data.length)
		{
			write(data, i, data.length - i);
		}

		writer.write('"');
	}

	/**
	 * Write some BASE64 encoded bytes.
	 *
	 * @param data
	 * @param pos
	 * @param chars
	 * @param len
	 * @throws IOException
	 */
	private void write(byte[] data, int pos, int len)
		throws IOException
	{
		char[] chars = BASE64;

		int loc = (len > 0 ? (data[pos] << 24) >>> 8 : 0) |
			(len > 1 ? (data[pos+1] << 24) >>> 16 : 0) |
			(len > 2 ? (data[pos+2] << 24) >>> 24 : 0);

		switch(len)
		{
			case 3:
				writer.write(chars[loc >>> 18]);
				writer.write(chars[(loc >>> 12) & 0x3f]);
				writer.write(chars[(loc >>> 6) & 0x3f]);
				writer.write(chars[loc & 0x3f]);
				break;
			case 2:
				writer.write(chars[loc >>> 18]);
				writer.write(chars[(loc >>> 12) & 0x3f]);
				writer.write(chars[(loc >>> 6) & 0x3f]);
				writer.write('=');
				break;
			case 1:
				writer.write(chars[loc >>> 18]);
				writer.write(chars[(loc >>> 12) & 0x3f]);
				writer.write('=');
				writer.write('=');
		}
	}

	@Override
	public void writeNull(String name)
		throws IOException
	{
		write(name, (String) null);
	}

	@Override
	public void flush() throws IOException
	{
		writer.flush();
	}
}
279948
function writeNode(state, level, object, block, compact, iskey) {
  state.tag = null;
  state.dump = object;

  if (!detectType(state, object, false)) {
    detectType(state, object, true);
  }

  var type = _toString.call(state.dump);

  if (block) {
    block = (state.flowLevel < 0 || state.flowLevel > level);
  }

  var objectOrArray = type === '[object Object]' || type === '[object Array]',
      duplicateIndex,
      duplicate;

  if (objectOrArray) {
    duplicateIndex = state.duplicates.indexOf(object);
    duplicate = duplicateIndex !== -1;
  }

  if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
    compact = false;
  }

  if (duplicate && state.usedDuplicates[duplicateIndex]) {
    state.dump = '*ref_' + duplicateIndex;
  } else {
    if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
      state.usedDuplicates[duplicateIndex] = true;
    }
    if (type === '[object Object]') {
      if (block && (Object.keys(state.dump).length !== 0)) {
        writeBlockMapping(state, level, state.dump, compact);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + state.dump;
        }
      } else {
        writeFlowMapping(state, level, state.dump);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
        }
      }
    } else if (type === '[object Array]') {
      var arrayLevel = (state.noArrayIndent && (level > 0)) ? level - 1 : level;
      if (block && (state.dump.length !== 0)) {
        writeBlockSequence(state, arrayLevel, state.dump, compact);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + state.dump;
        }
      } else {
        writeFlowSequence(state, arrayLevel, state.dump);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
        }
      }
    } else if (type === '[object String]') {
      if (state.tag !== '?') {
        writeScalar(state, state.dump, level, iskey);
      }
    } else {
      if (state.skipInvalid) return false;
      throw new YAMLException('unacceptable kind of an object to dump ' + type);
    }

    if (state.tag !== null && state.tag !== '?') {
      state.dump = '!<' + state.tag + '> ' + state.dump;
    }
  }

  return true;
}
1163804
function write(src, lvl, obj) {

    var stack = null;
    var lvlInt = levels[lvl];
    var msg;

    if (   typeof process.env.LOG_LEVEL == "string" 
        && levels[process.env.LOG_LEVEL.toLowerCase()] > lvlInt) {
        return false;
    }

    if (process.env.JSONCONSOLE_DISABLE_JSON_OUTPUT) {
        return src.write(util.format(obj)+os.EOL);
    }

    if (lvlInt >= 40) {
        if (obj instanceof Error) {
            stack = obj.stack;
        } else {
            stack = new Error().stack.split("\n");
            stack.splice(1, 4); // obfuscate the trace inside the logger.
            stack = stack.join('\n');
        }
    }


    if (obj instanceof RawValue) {
        msg = util.inspect(obj.raw);
    } else if (typeof obj == "string") {
        msg = obj;
    } else {
        msg = util.inspect(obj);
    }

    var log = {
        name: options.name,
        hostname,
        pid: process.pid,
        level: lvlInt,
        msg: msg,
        time: options.localDate ? formatLocalDate() : new Date().toISOString(),
        src: getCaller3Info(),        
        levelName: levelNames[lvlInt],
    };

    if (obj instanceof RawValue) {
        log.raw = obj.raw;
    }

    stack = stack && options.root ? stack.replace(new RegExp(options.root, 'g'), '{root}') : stack;
    
    if (stack) {
        log.stack = stack;
    }

    log.v = options.v;
    log.src.r = options.root;

    return src.write(JSON.stringify(log) + os.EOL);
}
513626
public final void write(Throwable e) throws IOException {
    indent();
    newLine();

    write(e.toString());

    StackTraceElement[] elements = e.getStackTrace();
    for (int i = 0; i < elements.length; i++) {
      newLine();
      write(elements[i].toString());
    }

    Throwable cause = e.getCause();
    if (cause != null) {
      newLine();
      write(cause.toString());
    }

    outdent();
  }
1344414
private void writeHeader(Writer writer)throws IOException {
        writer.write(ICAL_BEGIN);
        writer.write(COLON);
        writer.write(ICAL_VTIMEZONE);
        writer.write(NEWLINE);
        writer.write(ICAL_TZID);
        writer.write(COLON);
        writer.write(tz.getID());
        writer.write(NEWLINE);
        if (tzurl != null) {
            writer.write(ICAL_TZURL);
            writer.write(COLON);
            writer.write(tzurl);
            writer.write(NEWLINE);
        }
        if (lastmod != null) {
            writer.write(ICAL_LASTMOD);
            writer.write(COLON);
            writer.write(getUTCDateTimeString(lastmod.getTime()));
            writer.write(NEWLINE);
        }
    }
1090515
function(message, level) {
            level = level || Base.LOGLEVEL.INFO;

            if (message instanceof Error) {
                message = message.toString() + (message.stack || "");
            }

            if (Base.logger.length) {
                for (var i = 0; i < Base.logger.length; i++) {
                    Base.logger[i].log(message, level);
                }
            } else if (typeof console !== "undefined") {
                var method = (console[level] || console.log);
                if(method){
                    try {
                        method.call(console, "[ " + (new Date()) + " ]: ", message);
                    } catch (e) {
                        // nothing to do here
                    }
                }
            }
        }
621766
void writeRightCurlyBracket(Writer out, int indent) throws IOException
   {
      writeEol(out);
      writeWithIndent(out, indent, "}\n");
   }
284552
@Override
  public void writeExternal(ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeBoolean(isLeaf);
    out.writeInt(numEntries);
    // Entries will be written in subclasses
  }