public int writeUTF(String str) throws UTFDataFormatException
	{
		int strlen = str.length();
		int utflen = utfSizeOf(str);
		int c = 0;

		if (utflen > 65535)
			throw new UTFDataFormatException(
					"encoded string too long: " + utflen + " bytes");

		//writeByte((byte) ((utflen >>> 8) & 0xFF));
		//writeByte((byte) ((utflen) & 0xFF));

		writeShort(utflen);

		int i;
		for (i=0; i<strlen; i++) {
			c = str.charAt(i);
			if (!((c >= 0x0001) && (c <= 0x007F))) break;
			writeByte((byte) c);
		}

		for (;i < strlen; i++){
			c = str.charAt(i);
			if ((c >= 0x0001) && (c <= 0x007F)) {
				writeByte((byte) c);

			} else if (c > 0x07FF) {
				writeByte((byte) (0xE0 | ((c >> 12) & 0x0F)));
				writeByte((byte) (0x80 | ((c >>  6) & 0x3F)));
				writeByte((byte) (0x80 | ((c) & 0x3F)));
			} else {
				writeByte((byte) (0xC0 | ((c >>  6) & 0x1F)));
				writeByte((byte) (0x80 | ((c) & 0x3F)));
			}
		}

		return utflen + 2;
	}