code: public void write_atom(final String atom) {
          String enc_atom;
          byte[] bytes;
  
          if (atom.codePointCount(0, atom.length()) <= OtpExternal.maxAtomLength) {
              enc_atom = atom;
          } else {
              /*
               * Throwing an exception would be better I think, but truncation
               * seems to be the way it has been done in other parts of OTP...
               */
              enc_atom = new String(OtpErlangString.stringToCodePoints(atom), 0,
                      OtpExternal.maxAtomLength);
          }
  
          try {
              bytes = enc_atom.getBytes("UTF-8");
              final int length = bytes.length;
              if (length < 256) {
                  write1(OtpExternal.smallAtomUtf8Tag);
                  write1(length);
              } else {
                  write1(OtpExternal.atomUtf8Tag);
                  write2BE(length);
              }
              writeN(bytes);
          } catch (final java.io.UnsupportedEncodingException e) {
              /*
               * Sigh, why didn't the API designer add an OtpErlangEncodeException
               * to these encoding functions?!? Instead of changing the API we
               * write an invalid atom and let it fail for whoever trying to
               * decode this... Sigh, again...
               */
              write1(OtpExternal.smallAtomUtf8Tag);
              write1(2);
              write2BE(0xffff); /* Invalid UTF-8 */
          }
      }
docs: Write a string to the stream as an Erlang atom.
  
  @param atom
  the string to write.