Here you can find the source of writeString(ByteBuffer buf, String value)
public static void writeString(ByteBuffer buf, String value)
//package com.java2s; //License from project: LGPL import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { public static void writeString(ByteBuffer buf, String value) { if (value.contains("\0")) { throw new IllegalArgumentException("Null characters are not allowed in null-terminated strings."); }/*from w w w. j ava2 s. c o m*/ int len = value.length(); for (int i = 0; i < len; i++) { buf.put((byte) value.charAt(i)); } buf.put((byte) 0); } public static void writeString(DataOutputStream buf, String value) throws IOException { if (value.contains("\0")) { throw new IllegalArgumentException("Null characters are not allowed in null-terminated strings."); } buf.writeBytes(value); buf.writeByte((byte) 0); } }