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; import java.io.IOException; import java.io.OutputStream; public class Main { public static void writeString(OutputStream out, String s) throws IOException { if (s == null) { writeInt(out, 0);//from w ww. j a va 2s . c o m } else { byte[] bytes = s.getBytes("UTF-8"); writeInt(out, bytes.length); out.write(bytes); } } public static void writeInt(OutputStream out, int v) throws IOException { out.write((v >>> 24) & 0xFF); out.write((v >>> 16) & 0xFF); out.write((v >>> 8) & 0xFF); out.write((v) & 0xFF); } }