code: public static void writeString(String s, ByteBuffer buf) {
          buf.put((byte)(s != null? 1 : 0));
          if(s != null) {
              byte[] bytes=s.getBytes();
              writeInt(bytes.length, buf);
              buf.put(bytes);
          }
      }
docs: Writes a string to buf. The length of the string is written first, followed by the chars (as single-byte values).
  Multi-byte values are truncated: only the lower byte of each multi-byte char is written, similar to
  {@link DataOutput#writeChars(String)}.
  @param s the string
  @param buf the buffer