Here you can find the source of writeString(final String text, final ByteBuffer out)
private static void writeString(final String text, final ByteBuffer out)
//package com.java2s; //License from project: LGPL import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Objects; public class Main { private static void writeString(final String text, final ByteBuffer out) { Objects.requireNonNull(text, "text can not be null!"); Objects.requireNonNull(out, "out can not be null!"); out.putShort((short) text.length()); out.put(text.getBytes(StandardCharsets.UTF_8)); }//from w w w . j av a2 s. co m }