Writes UTF-8 encoded characters to the given stream, but does not write
the length.

@param workspace temporary buffer to store characters in
162347
public static final void writeUTF(OutputStream out,
                                      String str, char[] workspace)
        throws IOException
    {
        writeUTF(out, str, 0, str.length(), workspace);
    }
1220590
public void writeBytes(byte[] buffer, int offset, int length)
        throws IOException
    {
        if (buffer == null) {
            os.write('N');
        }
        else {
            while (length > 0x8000) {
                int sublen = 0x8000;

                os.write('b');
                os.write(sublen >> 8);
                os.write(sublen);

                os.write(buffer, offset, sublen);

                length -= sublen;
                offset += sublen;
            }

            os.write('B');
            os.write(length >> 8);
            os.write(length);
            os.write(buffer, offset, length);
        }
    }
772270
protected String writeInputStreamAsString(InputStream instream) {
    String value = null;
    try {
      value = IOUtils.toString(instream, "UTF-8");
      System.out.println(value);

    } catch(IOException ioe) {
      //Do nothing
    }
    return value;
  }
780703
public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    int end = offset + length;
    while (offset < end) {
      int ch1 = buf[offset++] & 0xff;

      if (ch1 < 0x80)
        os.write(ch1);
      else if ((ch1 & 0xe0) == 0xc0) {
        if (offset >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        os.write(((ch1 & 0x1f) << 6) + (ch2 & 0x3f));
      }
      else if ((ch1 & 0xf0) == 0xe0) {
        if (offset + 1 >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        int ch3 = buf[offset++] & 0xff;
      
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        if ((ch3 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        os.write(((ch1 & 0x1f) << 12) + ((ch2 & 0x3f) << 6) + (ch3 & 0x3f));
      }
      else
        throw new CharConversionException("illegal utf8 encoding at (" +
                                          (int) ch1 + ")");
    }
  }
658978
public void write(final String s) throws IOException
  {

    // We multiply the length by three since this is the maximum length
    // of the characters that we can put into the buffer.  It is possible
    // for each Unicode character to expand to three bytes.
    final int length = s.length();
    int lengthx3 = 3*length;

    if (lengthx3 >= BYTES_MAX - count)
    {
      // The requested length is greater than the unused part of the buffer
      flushBuffer();

      if (lengthx3 > BYTES_MAX)
      {
        /*
         * The requested length exceeds the size of the buffer,
         * so break it up in chunks that don't exceed the buffer size.
         */
         final int start = 0;
         int split = length/CHARS_MAX; 
         final int chunks;
         if (length % CHARS_MAX > 0) 
             chunks = split + 1;
         else
             chunks = split;
         int end_chunk = 0;
         for (int chunk = 1; chunk <= chunks; chunk++)
         {
             int start_chunk = end_chunk;
             end_chunk = start + (int) ((((long) length) * chunk) / chunks);
             s.getChars(start_chunk,end_chunk, m_inputChars,0);
             int len_chunk = (end_chunk - start_chunk);

             // Adjust the end of the chunk if it ends on a high char 
             // of a Unicode surrogate pair and low char of the pair
             // is not going to be in the same chunk
             final char c = m_inputChars[len_chunk - 1];
             if (c >= 0xD800 && c <= 0xDBFF) {
                 // Exclude char in this chunk, 
                 // to avoid spanning a Unicode character 
                 // that is in two Java chars as a high/low surrogate
                 end_chunk--;
                 len_chunk--;
                 if (chunk == chunks) {
                     /* TODO: error message needed.
                      * The String incorrectly ends in a high char
                      * of a high/low surrogate pair, but there is
                      * no corresponding low as the high is the last char
                      * Recover by ignoring this last char.
                      */
                 }
             }

             this.write(m_inputChars,0, len_chunk);
         }
         return;
      }
    }


    s.getChars(0, length , m_inputChars, 0);
    final char[] chars = m_inputChars;
    final int n = length;
    final byte[] buf_loc = m_outputBytes; // local reference for faster access
    int count_loc = count;      // local integer for faster access
    int i = 0;
    {
        /* This block could be omitted and the code would produce
         * the same result. But this block exists to give the JIT
         * a better chance of optimizing a tight and common loop which
         * occurs when writing out ASCII characters. 
         */ 
        char c;
        for(; i < n && (c = chars[i])< 0x80 ; i++ )
            buf_loc[count_loc++] = (byte)c;
    }
    for (; i < n; i++)
    {

      final char c = chars[i];

      if (c < 0x80)
        buf_loc[count_loc++] = (byte) (c);
      else if (c < 0x800)
      {
        buf_loc[count_loc++] = (byte) (0xc0 + (c >> 6));
        buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f));
      }
    /**
      * The following else if condition is added to support XML 1.1 Characters for 
      * UTF-8:   [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]*
      * Unicode: [1101 10ww] [wwzz zzyy] (high surrogate)
      *          [1101 11yy] [yyxx xxxx] (low surrogate)
      *          * uuuuu = wwww + 1
      */
    else if (c >= 0xD800 && c <= 0xDBFF) 
    {
        char high, low;
        high = c;
        i++;
        low = chars[i];

        buf_loc[count_loc++] = (byte) (0xF0 | (((high + 0x40) >> 8) & 0xf0));
        buf_loc[count_loc++] = (byte) (0x80 | (((high + 0x40) >> 2) & 0x3f));
        buf_loc[count_loc++] = (byte) (0x80 | ((low >> 6) & 0x0f) + ((high << 4) & 0x30));
        buf_loc[count_loc++] = (byte) (0x80 | (low & 0x3f));
    }
      else
      {
        buf_loc[count_loc++] = (byte) (0xe0 + (c >> 12));
        buf_loc[count_loc++] = (byte) (0x80 + ((c >> 6) & 0x3f));
        buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f));
      }
    }
    // Store the local integer back into the instance variable
    count = count_loc;

  }
545387
def write(text, path):
    
    with open(path, "wb") as f:
        f.write(text.encode("utf-8"))
748573
public static void writeUTF(@NotNull final OutputStream stream, @NotNull final String str) throws IOException {
        try (DataOutputStream dataStream = new DataOutputStream(stream)) {
            int len = str.length();
            if (len < SINGLE_UTF_CHUNK_SIZE) {
                dataStream.writeUTF(str);
            } else {
                int startIndex = 0;
                int endIndex;
                do {
                    endIndex = startIndex + SINGLE_UTF_CHUNK_SIZE;
                    if (endIndex > len) {
                        endIndex = len;
                    }
                    dataStream.writeUTF(str.substring(startIndex, endIndex));
                    startIndex += SINGLE_UTF_CHUNK_SIZE;
                } while (endIndex < len);
            }
        }
    }
106927
public void writeBytes(byte value, int len) throws IOException {
    if (len > buf.length - pos) {
      //not enough space remaining
      byte[] arr = new byte[len];
      Arrays.fill(arr, value);
      write(arr, 0, len);
      return;
    }

    for (int i = pos; i < pos + len; i++) {
      buf[i] = value;
    }
    pos += len;
  }
602494
public void write(DataOutput out) throws IOException {
    UTF8.writeString(out, file);
    out.writeLong(start);
    out.writeLong(length);
  }
183980
public static void write(final CharSequence data, final File file) throws IOException {
		Validate.notNull(file);
		Validate.notNull(data);

		try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charsets.UTF_8)) {
			writer.append(data);
		}
	}
94966
public static void saveAsFile(String data, String charset, String addr) throws IOException {
        charset = StringUtils.isEmpty(charset) ? "UTF8" : charset;
        saveAsFile(data.getBytes(charset), addr);
    }
991447
@Override
  public void write (@Nonnull final byte [] aBytes,
                     @Nonnegative final int nOfs,
                     @Nonnegative final int nLen) throws IOException
  {
    // Encoding suspended?
    if (m_bSuspendEncoding)
    {
      out.write (aBytes, nOfs, nLen);
      return;
    }

    for (int i = 0; i < nLen; i++)
      write (aBytes[nOfs + i]);
  }

  /**
   * Method added by PHIL. [Thanks, PHIL. -Rob] This pads the buffer without
   * closing the stream.
   *
   * @throws IOException
   *         if there's an error.
   */
  public void flushBase64 () throws IOException
  {
    if (m_nPosition > 0)
    {
      if (m_bEncode)
      {
        out.write (Base64._encode3to4 (m_aB4, m_aBuffer, m_nPosition, m_nOptions));
        m_nPosition = 0;
      }
      else
      {
        throw new IOException ("Base64 input not properly padded.");
      }
    }
  }

  /**
   * Flushes and closes (I think, in the superclass) the stream.
   *
   * @since 1.3
   */
  @Override
  public void close () throws IOException
  {
    // 1. Ensure that pending characters are written
    flushBase64 ();

    // 2. Actually close the stream
    // Base class both flushes and closes.
    if (out != null)
      super.close ();

    m_aBuffer = null;
    out = null;
  }

  /**
   * Suspends encoding of the stream. May be helpful if you need to embed a
   * piece of base64-encoded data in a stream.
   *
   * @throws IOException
   *         if there's an error flushing
   * @since 1.5.1
   */
  public void suspendEncoding () throws IOException
  {
    flushBase64 ();
    m_bSuspendEncoding = true;
  }

  /**
   * Resumes encoding of the stream. May be helpful if you need to embed a piece
   * of base64-encoded data in a stream.
   *
   * @since 1.5.1
   */
  public void resumeEncoding ()
  {
    m_bSuspendEncoding = false;
  }
}
651536
@Override
    public void setCharacterEncoding(String charset) {
        if (null != this.outWriter || isCommitted()) {
            return;
        }
        if (null != charset) {
            this.encoding = connection.getEncodingUtils().stripQuotes(charset);
        }
        if (null != this.contentType) {
            int index = this.contentType.indexOf("charset=");
            StringBuilder sb = new StringBuilder();
            if (-1 != index) {
                sb.append(this.contentType.substring(0, index - 1).trim());
            } else {
                sb.append(this.contentType);
            }
            if (this.encoding != null) {
                sb.append(";charset=").append(this.encoding);
            }

            this.contentType = sb.toString();
            this.response.setHeader("Content-Type", this.contentType);
        }
    }
403036
public static File writeUtf8String(String content, String path) throws IORuntimeException {
		return writeString(content, path, CharsetUtil.CHARSET_UTF_8);
	}
349797
public void write(char[] buf) throws IOException {
	    if (writer != null) {
	        writer.write(buf);
	    } else {
	        write(buf, 0, buf.length);
	    }
    }
1285377
private static String inputStreamToString(InputStream stream)
			throws IOException {
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		String resultString = null;
		while ((length = stream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		resultString = result.toString("UTF-8");
		return resultString;
	}
1311993
public static void writeString(String value, ByteBuffer buf) {
        if (value == null) {
            buf.putInt(VoltType.NULL_STRING_LENGTH);
            return;
        }

        byte[] strbytes = value.getBytes(Constants.UTF8ENCODING);
        int len = strbytes.length;

        buf.putInt(len);
        buf.put(strbytes);
    }