"Java-modifikatsiya qilingan UTF-8 kodlash" degani nimani anglatadi?

"Java-modifikatsiya qilingan UTF-8 kodlash" degani nimani anglatadi? Bu oddiy UTF-8 kodlashdan qanday farq qiladi?

7
Java, har doim hamma narsani qilishni xohlaydi.
qo'shib qo'ydi muallif BoltClock, manba
qo'shib qo'ydi muallif Tomasz Nurkiewicz, manba
Bu qaerda?
qo'shib qo'ydi muallif millimoose, manba
@BoltClock Juda konstruktiv sharh yo'q. Java bu o'zgartirilgan kodlashni faqat String 0x00 tugallangan qatorlardan foydalanadigan muhitda tugashi mumkin bo'lgan hollarda ishlatadi.
qo'shib qo'ydi muallif Mark Rotteveel, manba

3 javoblar

Bu batafsil javadoc-da batafsil tavsiflanadi. DataInput :

Modified UTF-8

Implementations of the DataInput and DataOutput interfaces represent Unicode strings in a format that is a slight modification of UTF-8. (For information regarding the standard UTF-8 format, see section 3.9 Unicode Encoding Forms of The Unicode Standard, Version 4.0). Note that in the following tables, the most significant bit appears in the far left-hand column.

... (some tables, please click the javadoc link to see yourself) ...

The differences between this format and the standard UTF-8 format are the following:

  • The null byte '\u0000' is encoded in 2-byte format rather than 1-byte, so that the encoded strings never have embedded nulls.
  • Only the 1-byte, 2-byte, and 3-byte formats are used.
  • Supplementary characters are represented in the form of surrogate pairs.

Buni qanday o'qiladi, da javadoc-da batafsil tavsiflanadi. DataInput # readUTF() :

readUTF

String readUTF()
           throws IOException

Reads in a string that has been encoded using a modified UTF-8 format. The general contract of readUTF is that it reads a representation of a Unicode character string encoded in modified UTF-8 format; this string of characters is then returned as a String.

First, two bytes are read and used to construct an unsigned 16-bit integer in exactly the manner of the readUnsignedShort method . This integer value is called the UTF length and specifies the number of additional bytes to be read. These bytes are then converted to characters by considering them in groups. The length of each group is computed from the value of the first byte of the group. The byte following a group, if any, is the first byte of the next group.

If the first byte of a group matches the bit pattern 0xxxxxxx (where x means "may be 0 or 1"), then the group consists of just that byte. The byte is zero-extended to form a character.

If the first byte of a group matches the bit pattern 110xxxxx, then the group consists of that byte a and a second byte b. If there is no byte b (because byte a was the last of the bytes to be read), or if byte b does not match the bit pattern 10xxxxxx, then a UTFDataFormatException is thrown. Otherwise, the group is converted to the character:

(char)(((a& 0x1F) << 6) | (b & 0x3F))

If the first byte of a group matches the bit pattern 1110xxxx, then the group consists of that byte a and two more bytes b and c. If there is no byte c (because byte a was one of the last two of the bytes to be read), or either byte b or byte c does not match the bit pattern 10xxxxxx, then a UTFDataFormatException is thrown. Otherwise, the group is converted to the character:

(char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))

If the first byte of a group matches the pattern 1111xxxx or the pattern 10xxxxxx, then a UTFDataFormatException is thrown.

If end of file is encountered at any time during this entire process, then an EOFException is thrown.

After every group has been converted to a character by this process, the characters are gathered, in the same order in which their corresponding groups were read from the input stream, to form a String, which is returned.

The writeUTF method of interface DataOutput may be used to write data that is suitable for reading by this method.

8
qo'shib qo'ydi
"null bayt 2 bayt shaklida kodlangan" - bu 11000000 10000000 deb kodlangan degan ma'noni anglatadimi?
qo'shib qo'ydi muallif MC Emperor, manba

UTF-16 ni ichki matn ko'rinishi uchun ishlatadigan Java dasturlash tili UTF-8 ning stray seriyali uchun standart bo'lmagan modifikatsiyasini qo'llab-quvvatlaydi. Ushbu kodlash o'zgartirilgan UTF-8 deb ataladi. O'zgartirilgan va standart UTF-8 o'rtasida ikkita farq mavjud. Birinchi farq shundaki, bo'sh belgilar (U + 0000) bir emas, balki 11000000 dan 10000000 gacha bo'lgan ikki bayt bilan kodlangan.

3
qo'shib qo'ydi

Probably this: http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8

"Oddiy foydalanishda Java dasturlash tili standartni qo'llab-quvvatlaydi   InputStreamReader va. Orqali satrlarni o'qish va yozishda UTF-8   OutputStreamWriter. Biroq ob'ekt uchun o'zgartirilgan UTF-8 dan foydalaniladi   ketma-ketlashtirish, Java native interfeysi uchun va   doimiy fayllarni sinfi fayllariga qo'shish ".

1
qo'shib qo'ydi