Lines 1708-1790
Link Here
|
1708 |
} |
1708 |
} |
1709 |
} |
1709 |
} |
1710 |
/** |
1710 |
/** |
1711 |
* Reads in a string from the specified data input stream. The |
|
|
1712 |
* string has been encoded using a modified UTF-8 format. |
1713 |
* <p> |
1714 |
* The first two bytes are read as if by |
1715 |
* <code>readUnsignedShort</code>. This value gives the number of |
1716 |
* following bytes that are in the encoded string, not |
1717 |
* the length of the resulting string. The following bytes are then |
1718 |
* interpreted as bytes encoding characters in the UTF-8 format |
1719 |
* and are converted into characters. |
1720 |
* <p> |
1721 |
* This method blocks until all the bytes are read, the end of the |
1722 |
* stream is detected, or an exception is thrown. |
1723 |
* |
1724 |
* @param in a data input stream. |
1725 |
* @return a Unicode string. |
1726 |
* @exception EOFException if the input stream reaches the end |
1727 |
* before all the bytes. |
1728 |
* @exception IOException if an I/O error occurs. |
1729 |
* @exception UTFDataFormatException if the bytes do not represent a |
1730 |
* valid UTF-8 encoding of a Unicode string. |
1731 |
* @see java.io.DataInputStream#readUnsignedShort() |
1732 |
*/ |
1733 |
public final static char[] readUTF(DataInput in) throws IOException { |
1734 |
int utflen= in.readUnsignedShort(); |
1735 |
char str[]= new char[utflen]; |
1736 |
int count= 0; |
1737 |
int strlen= 0; |
1738 |
while (count < utflen) { |
1739 |
int c= in.readUnsignedByte(); |
1740 |
int char2, char3; |
1741 |
switch (c >> 4) { |
1742 |
case 0 : |
1743 |
case 1 : |
1744 |
case 2 : |
1745 |
case 3 : |
1746 |
case 4 : |
1747 |
case 5 : |
1748 |
case 6 : |
1749 |
case 7 : |
1750 |
// 0xxxxxxx |
1751 |
count++; |
1752 |
str[strlen++]= (char) c; |
1753 |
break; |
1754 |
case 12 : |
1755 |
case 13 : |
1756 |
// 110x xxxx 10xx xxxx |
1757 |
count += 2; |
1758 |
if (count > utflen) |
1759 |
throw new UTFDataFormatException(); |
1760 |
char2= in.readUnsignedByte(); |
1761 |
if ((char2 & 0xC0) != 0x80) |
1762 |
throw new UTFDataFormatException(); |
1763 |
str[strlen++]= (char) (((c & 0x1F) << 6) | (char2 & 0x3F)); |
1764 |
break; |
1765 |
case 14 : |
1766 |
// 1110 xxxx 10xx xxxx 10xx xxxx |
1767 |
count += 3; |
1768 |
if (count > utflen) |
1769 |
throw new UTFDataFormatException(); |
1770 |
char2= in.readUnsignedByte(); |
1771 |
char3= in.readUnsignedByte(); |
1772 |
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) |
1773 |
throw new UTFDataFormatException(); |
1774 |
str[strlen++]= (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); |
1775 |
break; |
1776 |
default : |
1777 |
// 10xx xxxx, 1111 xxxx |
1778 |
throw new UTFDataFormatException(); |
1779 |
} |
1780 |
} |
1781 |
if (strlen < utflen) { |
1782 |
System.arraycopy(str, 0, str= new char[strlen], 0, strlen); |
1783 |
} |
1784 |
return str; |
1785 |
} |
1786 |
|
1787 |
/** |
1788 |
* Returns the toString() of the given full path minus the first given number of segments. |
1711 |
* Returns the toString() of the given full path minus the first given number of segments. |
1789 |
* The returned string is always a relative path (it has no leading slash) |
1712 |
* The returned string is always a relative path (it has no leading slash) |
1790 |
*/ |
1713 |
*/ |