cdm/src/main/java/ucar/unidata/io/RandomAccessFile.java
public final void writeUTF(String str) throws IOException {
    int strlen = str.length();
    int utflen = 0;

    for (int i = 0; i < strlen; i++) {
      int c = str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        utflen++;
      } else if (c > 0x07FF) {
        utflen += 3;
      } else {
        utflen += 2;
      }
    }
    if (utflen > 65535) {
      throw new UTFDataFormatException();
    }

    write((utflen >>> 8) & 0xFF);
    write((utflen) & 0xFF);
    for (int i = 0; i < strlen; i++) {
      int c = str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        write(c);
      } else if (c > 0x07FF) {
        write(0xE0 | ((c >> 12) & 0x0F));
        write(0x80 | ((c >> 6) & 0x3F));
        write(0x80 | ((c) & 0x3F));
      } else {
        write(0xC0 | ((c >> 6) & 0x1F));
        write(0x80 | ((c) & 0x3F));
      }
    }
  }
public final void writeUTF(String str) throws IOException {
    int strlen = str.length();
    int utflen = 0;

    for (int i = 0; i < strlen; i++) {
      int c = str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        utflen++;
      } else if (c > 0x07FF) {
        utflen += 3;
      } else {
        utflen += 2;
      }
    }
    if (utflen > 65535) {
      throw new UTFDataFormatException();
    }

    write((utflen >>> 8) & 0xFF);
    write((utflen) & 0xFF);
    for (int i = 0; i < strlen; i++) {
      int c = str.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) {
        write(c);
      } else if (c > 0x07FF) {
        write(0xE0 | ((c >> 12) & 0x0F));
        write(0x80 | ((c >> 6) & 0x3F));
        write(0x80 | ((c) & 0x3F));
      } else {
        write(0xC0 | ((c >> 6) & 0x1F));
        write(0x80 | ((c) & 0x3F));
      }
    }
  }
public final void writeUTF ( String str ) throws IOException { int strlen = str . length ( ) ; int utflen = 0 ; for ( int i = 0 ; i < strlen ; i ++ ) { int c = str . charAt ( i ) ; if ( ( c >= 0x0001 ) && ( c <= 0x007F ) ) { utflen ++ ; } else if ( c > 0x07FF ) { utflen += 3 ; } else { utflen += 2 ; } } if ( utflen > 65535 ) { throw new UTFDataFormatException ( ) ; } write ( ( utflen >>> 8 ) & 0xFF ) ; write ( ( utflen ) & 0xFF ) ; for ( int i = 0 ; i < strlen ; i ++ ) { int c = str . charAt ( i ) ; if ( ( c >= 0x0001 ) && ( c <= 0x007F ) ) { write ( c ) ; } else if ( c > 0x07FF ) { write ( 0xE0 | ( ( c >> 12 ) & 0x0F ) ) ; write ( 0x80 | ( ( c >> 6 ) & 0x3F ) ) ; write ( 0x80 | ( ( c ) & 0x3F ) ) ; } else { write ( 0xC0 | ( ( c >> 6 ) & 0x1F ) ) ; write ( 0x80 | ( ( c ) & 0x3F ) ) ; } } }
Writes a string to the file using UTF-8 encoding in a
machine-independent manner.
<p/>
First, two bytes are written to the file as if by the
<code>writeShort</code> method giving the number of bytes to
follow. This value is the number of bytes actually written out,
not the length of the string. Following the length, each character
of the string is output, in sequence, using the UTF-8 encoding
for each character.

@param str a string to be written.
@throws IOException if an I/O error occurs.
Writes a string to the file using UTF - 8 encoding in a machine - independent manner . <p / > First two bytes are written to the file as if by the <code > writeShort< / code > method giving the number of bytes to follow . This value is the number of bytes actually written out not the length of the string . Following the length each character of the string is output in sequence using the UTF - 8 encoding for each character .