Here you can find the source of writeString(ByteBuffer byteBuffer, String str)
public static void writeString(ByteBuffer byteBuffer, String str)
//package com.java2s; /*/*from w w w . j a v a 2 s.co m*/ * (C) 2007-2010 Alibaba Group Holding Limited. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ import java.nio.ByteBuffer; public class Main { public static void writeString(ByteBuffer byteBuffer, String str) { if (str == null) { byteBuffer.putInt(0); } else { byte[] b = str.getBytes(); byteBuffer.putInt(b.length + 1); byteBuffer.put(b); byteBuffer.put((byte) 0); } } }