for (int i = 0; i < len && sum <= 65535; ++i)
if (buf == null) buf = new byte[512];  do
  public final synchronized void writeUTF(String value) throws IOException  {    int len = value.length();    int sum = 0;    for (int i = 0; i < len && sum <= 65535; ++i)      {	char c = value.charAt(i);	if (c >= '\u0001' && c <= '\u007f')	  sum += 1;	else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))	  sum += 2;	else	  sum += 3;      }    if (sum > 65535)      throw new UTFDataFormatException ();    int pos = 0;    byte[] buf = new byte[sum];    for (int i = 0; i < len; ++i)      {	char c = value.charAt(i);	if (c >= '\u0001' && c <= '\u007f')          buf[pos++] = (byte) c;	else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))	  {	    buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6)));	    buf[pos++] = (byte) (0x80 | (0x3f & c));	  }	else	  {	    // JSL says the first byte should be or'd with 0xc0, but	    // that is a typo.  Unicode says 0xe0, and that is what is	    // consistent with DataInputStream.	    buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12)));	    buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6)));	    buf[pos++] = (byte) (0x80 | (0x3f & c));	  }      }        writeShort (sum);    write(buf, 0, sum);  }