Here you can find the source of writeString(OutputStream out, String s)
public static void writeString(OutputStream out, String s) throws IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.io.OutputStream; public class Main { public static void writeString(OutputStream out, String s) throws IOException { byte[] buf = s.getBytes("UTF8"); short len = (short) buf.length; out.write((len >> 8) & 0xFF); out.write(len & 0xFF);//from ww w.j av a 2 s .c om out.write(buf); } }