code: public static void writeString(String s, DataOutput out) throws IOException {
          if(s != null) {
              out.write(1);
              out.writeUTF(s);
          }
          else
              out.write(0);
      }
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 out the output stream