Here you can find the source of writeString(ByteBuffer buf, String s)
public static void writeString(ByteBuffer buf, String s)
//package com.java2s; //License from project: LGPL import java.io.*; import java.nio.ByteBuffer; public class Main { public static void writeString(String s, DataOutput out) throws Exception { if (s != null) { out.write(1);//from w ww . j a va 2s . c om out.writeUTF(s); } else { out.write(0); } } public static void writeString(ByteBuffer buf, String s) { for (int i = 0; i < s.length(); i++) buf.put((byte) s.charAt(i)); } }