Here you can find the source of putString(ByteBuffer buf, String value)
private static void putString(ByteBuffer buf, String value)
//package com.java2s; /*/*ww w . j av a2 s.com*/ This file is part of the Greenfoot program. Copyright (C) 2005-2009,2010,2011,2012 Poul Henriksen and Michael Kolling This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This file is subject to the Classpath exception as provided in the LICENSE.txt file that accompanied this code. */ import java.nio.ByteBuffer; public class Main { private static void putString(ByteBuffer buf, String value) { if (value == null) { buf.putShort((short) -1); } else { buf.putShort((short) value.length()); //2-bytes for length for (int i = 0; i < value.length(); i++) { buf.putChar(value.charAt(i)); } } } }