Writes UTF-8 encoded characters to the given stream, but does not write
the length.
355252
public static final void writeUTF(OutputStream out,
                                      char[] chars, int offset, int length)
        throws IOException
    {
        for (int i=0; i<length; i++) {
            int c = chars[i + offset];
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out.write(c);
            }
            else if (c > 0x07FF) {
                out.write(0xe0 | ((c >> 12) & 0x0f));
                out.write(0x80 | ((c >> 6) & 0x3f));
                out.write(0x80 | (c & 0x3f));
            }
            else {
                out.write(0xc0 | ((c >> 6) & 0x1f));
                out.write(0x80 | (c & 0x3f));
            }
        }
    }
252017
public void writeBytes(byte[] buffer, int offset, int length)
        throws IOException
    {
        if (buffer == null) {
            if (SIZE < _offset + 16)
                flushBuffer();

            _buffer[_offset++] = (byte) 'N';
        }
        else {
            while (SIZE - _offset - 3 < length) {
                int sublen = SIZE - _offset - 3;

                if (sublen < 16) {
                    flushBuffer();

                    sublen = SIZE - _offset - 3;

                    if (length < sublen)
                        sublen = length;
                }

                _buffer[_offset++] = (byte) BC_BINARY_CHUNK;
                _buffer[_offset++] = (byte) (sublen >> 8);
                _buffer[_offset++] = (byte) sublen;

                System.arraycopy(buffer, offset, _buffer, _offset, sublen);
                _offset += sublen;

                length -= sublen;
                offset += sublen;

                flushBuffer();
            }

            if (SIZE < _offset + 16)
                flushBuffer();

            if (length <= BINARY_DIRECT_MAX) {
                _buffer[_offset++] = (byte) (BC_BINARY_DIRECT + length);
            }
            else if (length <= BINARY_SHORT_MAX) {
                _buffer[_offset++] = (byte) (BC_BINARY_SHORT + (length >> 8));
                _buffer[_offset++] = (byte) (length);
            }
            else {
                _buffer[_offset++] = (byte) 'B';
                _buffer[_offset++] = (byte) (length >> 8);
                _buffer[_offset++] = (byte) (length);
            }

            System.arraycopy(buffer, offset, _buffer, _offset, length);

            _offset += length;
        }
    }
1091180
void write(Writable value) throws IOException {
    byte[] bval;
    int valSize;
    if (value instanceof BytesWritable) {
      BytesWritable val = (BytesWritable) value;
      bval = val.get();
      valSize = val.getSize();
    } else if (value instanceof Text) {
      Text val = (Text) value;
      bval = val.getBytes();
      valSize = val.getLength();
    } else {
      String sval = value.toString();
      bval = sval.getBytes("UTF-8");
      valSize = bval.length;
    }
    clientOut_.write(bval, 0, valSize);
  }
145024
private void writeLengthToStream(int length, OutputStream out) throws IOException {
    sharedByteBuffer.clear();
    sharedByteBuffer.order(ByteOrder.BIG_ENDIAN).putInt(length);
    sharedByteBuffer.flip();
    out.write(sharedByteBuffer.array(), 0, Ints.BYTES);
    sharedByteBuffer.order(byteOrder);
  }
292466
def get_best_encoding(stream):
    """"""
    rv = getattr(stream, 'encoding', None) or sys.getdefaultencoding()
    if is_ascii_encoding(rv):
        return 'utf-8'
    return rv
289858
private static void encode(String word, OutputStream out) throws UnsupportedEncodingException, IOException {
        byte bytes[] = word.getBytes("UTF-8");
        int len = bytes.length;
        if (len < 0x80) {
            out.write(len);
        } else if (len < 0x4000) {
            len = len | 0x8000;
            out.write(len >> 8);
            out.write(len);
        } else if (len < 0x20000) {
            len = len | 0xC00000;
            out.write(len >> 16);
            out.write(len >> 8);
            out.write(len);
        } else if (len < 0x10000000) {
            len = len | 0xE0000000;
            out.write(len >> 24);
            out.write(len >> 16);
            out.write(len >> 8);
            out.write(len);
        } else {
            out.write(0xF0);
            out.write(len >> 24);
            out.write(len >> 16);
            out.write(len >> 8);
            out.write(len);
        }
        out.write(bytes);
    }
1318865
void write(Object value) throws IOException {
    if (clientInputSerializer != null) {
      clientInputSerializer.serialize(value);
      return;
    }

    byte[] bval;
    int valSize;
    if (value instanceof BytesWritable) {
      BytesWritable val = (BytesWritable) value;
      bval = val.getBytes();
      valSize = val.getLength();
    } else if (value instanceof Text) {
      Text val = (Text) value;
      bval = val.getBytes();
      valSize = val.getLength();
    } else {
      String sval = value.toString();
      bval = sval.getBytes("UTF-8");
      valSize = bval.length;
    }
    clientOut_.write(bval, 0, valSize);
  }
761227
function serializeStream(stream) {
      // 1. Let token be the result of reading from stream.
      // (Done in-place on array, rather than as a stream)

      // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
      // BOM flag and BOM seen flag are unset, run these subsubsteps:
      if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
          !this._ignoreBOM && !this._BOMseen) {
        if (stream.length > 0 && stream[0] === 0xFEFF) {
          // 1. If token is U+FEFF, set BOM seen flag.
          this._BOMseen = true;
          stream.shift();
        } else if (stream.length > 0) {
          // 2. Otherwise, if token is not end-of-stream, set BOM seen
          // flag and append token to stream.
          this._BOMseen = true;
        } else {
          // 3. Otherwise, if token is not end-of-stream, append token
          // to output.
          // (no-op)
        }
      }
      // 4. Otherwise, return output.
      return codePointsToString(stream);
    }
103225
public static void writeStringAsText(DataOutput stream, String str) throws IOException {
    byte[] utf8Encoded = str.getBytes(StandardCharsets.UTF_8);
    writeVLong(stream, utf8Encoded.length);
    stream.write(utf8Encoded);
  }
420056
@ThreadSafe public void stringEncode(String s, Writer writer) throws IOException {
		char[] carr = s.toCharArray();
		int len = carr.length;
		for(int i = 0; i < len; i++) {
			char c = carr[i];
			switch (c) {
			case '"':
				writer.write("\\\"");
				break;
			case '/':
				writer.write(escapeSlash ? "\\/" : "/");
				break;
			case '\\':
				writer.write("\\\\");
				break;
			case '\b':
				writer.write("\\b");
				break;
			case '\f':
				writer.write("\\f");
				break;
			case '\n':
				writer.write("\\n");
				break;
			case '\r':
				writer.write("\\r");
				break;
			case '\t':
				writer.write("\\t");
				break;
			default:
				if(unicodeEscapeAll) {
					if(c < 127) {
						writer.append(c);
					} else {
						String hex = Integer.toHexString(c);
						writer.write("\\u");
						switch (hex.length()) {
						case 1:
							writer.write("000");
							break;
						case 2:
							writer.write("00");
							break;
						case 3:
							writer.write("0");
							break;
						default:
							break;
						}
						writer.write(Integer.toHexString(c));
					}
				} else {
					writer.append(c);
				}
				break;
			}
		}
	}
371624
def write_shortstr(self, s):
        
        if isinstance(s, unicode):
            s = s.encode('utf-8')
        self.write_octet(len(s))
        self.write(s)
        return self
787477
public static void encode (char[] string, int offset, int length, boolean encodeNewline, Writer writer)
        throws IOException
    {
        encode(string, offset, length, encodeNewline, true, writer);
    }
256551
def write_byte(self, value):
        
        if isinstance(value, bytes):
            self.stream.write(value)
        elif isinstance(value, str):
            self.stream.write(value.encode('utf-8'))
        elif isinstance(value, int):
            self.stream.write(bytes([value]))
852038
def store(self, stream, linesep=os.linesep):
        

        for k, v in self.items():
            write_key_val(stream, k, v, linesep)

        stream.write(linesep.encode('utf-8'))
120398
def write_utf8_string(self, u):
        
        if not isinstance(u, python.str_types):
            raise TypeError('Expected %r, got %r' % (python.str_types, u))

        bytes = u

        if isinstance(bytes, unicode):
            bytes = u.encode("utf8")

        self.write(struct.pack("%s%ds" % (self.endian, len(bytes)), bytes))
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;
  }
869092
public void encodeToStream(Encoder thisInstance, CharSequence source, int offset, int len, EncodedAppender appender,
            EncodingState encodingState) throws IOException {
        appender.appendEncoded(thisInstance, encodingState, source, offset, len);
    }