Here you can find the source of putStr(ByteBuffer buff, String str)
public static void putStr(ByteBuffer buff, String str)
//package com.java2s; //License from project: Open Source License import java.nio.*; public class Main { /**/*w ww. j a v a2 s. co m*/ * write a String to a ByteBuffer, * prepended with a short integer representing the length of the String */ public static void putStr(ByteBuffer buff, String str) { if (str == null) { buff.putShort((short) 0); } else { buff.putShort((short) str.length()); buff.put(str.getBytes()); } } }