code: public void write_string(final String s) {
          final int len = s.length();
  
          switch (len) {
          case 0:
              write_nil();
              break;
          default:
              if (len <= 65535 && is8bitString(s)) { // 8-bit string
                  try {
                      final byte[] bytebuf = s.getBytes("ISO-8859-1");
                      write1(OtpExternal.stringTag);
                      write2BE(len);
                      writeN(bytebuf);
                  } catch (final UnsupportedEncodingException e) {
                      write_nil(); // it should never ever get here...
                  }
              } else { // unicode or longer, must code as list
                  final int[] codePoints = OtpErlangString.stringToCodePoints(s);
                  write_list_head(codePoints.length);
                  for (final int codePoint : codePoints) {
                      write_int(codePoint);
                  }
                  write_nil();
              }
          }
      }
docs: Write a string to the stream.
  
  @param s
  the string to write.