Here you can find the source of writeString(OutputStream os, String s)
static void writeString(OutputStream os, String s) throws IOException
//package com.java2s; /*/*from w w w . j a v a2 s. co m*/ * @(#)NodeUtil.java 1.2 05/06/27 * * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. * * See the file "LICENSE.txt" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ import java.io.*; public class Main { static void writeString(OutputStream os, String s) throws IOException { int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); if (c < 0x80) { os.write(c); } else if (c < 0x800) { os.write(0xc0 + (c >> 6)); os.write(0x80 + (c & 0x3f)); } else { os.write(0xe0 + (c >> 12)); os.write(0x80 + ((c >> 6) & 0x3f)); os.write(0x80 + (c & 0x3f)); } } } }