1. /*
  2. * @(#)DataInputStream.java 1.65 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.io;
  8. /**
  9. * A data input stream lets an application read primitive Java data
  10. * types from an underlying input stream in a machine-independent
  11. * way. An application uses a data output stream to write data that
  12. * can later be read by a data input stream.
  13. * <p>
  14. * Data input streams and data output streams represent Unicode
  15. * strings in a format that is a slight modification of UTF-8. (For
  16. * more information, see X/Open Company Ltd., "File System Safe
  17. * UCS Transformation Format (FSS_UTF)", X/Open Preliminary
  18. * Specification, Document Number: P316. This information also
  19. * appears in ISO/IEC 10646, Annex P.) Note that in the
  20. * following tables, the most significant bit appears in the
  21. * far left-hand column.
  22. * <p>
  23. * All characters in the range <code>'\u0001'</code> to
  24. * <code>'\u007F'</code> are represented by a single byte:
  25. *
  26. * <center>
  27. * <table border="3" summary="Bit values and bytes">
  28. * <tr>
  29. * <td></td>
  30. * <th id="bit" colspan=2><P ALIGN="LEFT">Bit Values</P></th>
  31. * </tr>
  32. * <tr>
  33. * <th id="byte1">Byte 1 </th>
  34. * <td headers="bit byte1"><i>0</i></td>
  35. * <td>bits 6-0</td>
  36. * </tr>
  37. * </table>
  38. * </center>
  39. *
  40. * <p>
  41. * The null character <code>'\u0000'</code> and characters in the
  42. * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
  43. * represented by a pair of bytes:
  44. *
  45. * <center>
  46. * <table border="3" summary="Bit values and bytes">
  47. * <tr>
  48. * <td></td>
  49. * <th id="bit" colspan=4><P ALIGN="LEFT">Bit Values</P></th>
  50. * </tr>
  51. * <tr>
  52. * <th id="byte1">Byte 1 </th>
  53. * <td headers="bit byte1">1</td>
  54. * <td headers="bit byte1">1</td>
  55. * <td headers="bit byte1">0</td>
  56. * <td headers="bit byte1">bits 10-6</td>
  57. * </tr>
  58. * <tr>
  59. * <th id="byte2">Byte 2 </th>
  60. * <td headers="bit byte2">1</td>
  61. * <td headers="bit byte2">0</td>
  62. * <td headers="bit byte2" colspan=2>bits 5-0</td>
  63. * </tr>
  64. * </table>
  65. * </center>
  66. *
  67. * <br>
  68. * Characters in the range <code>'\u0800'</code> to
  69. * <code>'\uFFFF'</code> are represented by three bytes:
  70. *
  71. * <center>
  72. * <table border="3" summary="Bit values and bytes">
  73. * <tr>
  74. * <td></td>
  75. * <th id="bit" colspan=5><P ALIGN="LEFT">Bit Values</P></th>
  76. * </tr>
  77. *
  78. * <tr>
  79. * <th id="byte1">Byte 1 </th>
  80. * <td headers="bit byte1">1</td>
  81. * <td headers="bit byte1">1</td>
  82. * <td headers="bit byte1">1</td>
  83. * <td headers="bit byte1">0</td>
  84. * <td headers="bit byte1">bits 15-12</td>
  85. * </tr>
  86. * <tr>
  87. * <th id="byte2">Byte 2 </th>
  88. * <td headers="bit byte2">1</td>
  89. * <td headers="bit byte2">0</td>
  90. * <td headers="bit byte2" colspan=3>bits 11-6</td>
  91. * </tr>
  92. * <tr>
  93. * <th id="byte3">Byte 3 </th>
  94. * <td headers="bit byte3">1</td>
  95. * <td headers="bit byte3">0</td>
  96. * <td headers="bit byte3" colspan=3>bits 5-0</td>
  97. * </tr>
  98. * </table>
  99. * </center>
  100. * <p>
  101. * The two differences between this format and the
  102. * "standard" UTF-8 format are the following:
  103. * <ul>
  104. * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
  105. * rather than 1-byte, so that the encoded strings never have
  106. * embedded nulls.
  107. * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
  108. * </ul>
  109. *
  110. * @author Arthur van Hoff
  111. * @version 1.65, 01/23/03
  112. * @see java.io.DataOutputStream
  113. * @since JDK1.0
  114. */
  115. public
  116. class DataInputStream extends FilterInputStream implements DataInput {
  117. /**
  118. * Creates a DataInputStream that uses the specified
  119. * underlying InputStream.
  120. *
  121. * @param in the specified input stream
  122. */
  123. public DataInputStream(InputStream in) {
  124. super(in);
  125. }
  126. /**
  127. * Reads some number of bytes from the contained input stream and
  128. * stores them into the buffer array <code>b</code>. The number of
  129. * bytes actually read is returned as an integer. This method blocks
  130. * until input data is available, end of file is detected, or an
  131. * exception is thrown.
  132. *
  133. * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
  134. * thrown. If the length of <code>b</code> is zero, then no bytes are
  135. * read and <code>0</code> is returned; otherwise, there is an attempt
  136. * to read at least one byte. If no byte is available because the
  137. * stream is at end of file, the value <code>-1</code> is returned;
  138. * otherwise, at least one byte is read and stored into <code>b</code>.
  139. *
  140. * <p>The first byte read is stored into element <code>b[0]</code>, the
  141. * next one into <code>b[1]</code>, and so on. The number of bytes read
  142. * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
  143. * be the number of bytes actually read; these bytes will be stored in
  144. * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
  145. * elements <code>b[k]</code> through <code>b[b.length-1]</code>
  146. * unaffected.
  147. *
  148. * <p>If the first byte cannot be read for any reason other than end of
  149. * file, then an <code>IOException</code> is thrown. In particular, an
  150. * <code>IOException</code> is thrown if the input stream has been closed.
  151. *
  152. * <p>The <code>read(b)</code> method has the same effect as:
  153. * <blockquote><pre>
  154. * read(b, 0, b.length)
  155. * </pre></blockquote>
  156. *
  157. * @param b the buffer into which the data is read.
  158. * @return the total number of bytes read into the buffer, or
  159. * <code>-1</code> if there is no more data because the end
  160. * of the stream has been reached.
  161. * @exception IOException if an I/O error occurs.
  162. * @see java.io.FilterInputStream#in
  163. * @see java.io.InputStream#read(byte[], int, int)
  164. */
  165. public final int read(byte b[]) throws IOException {
  166. return in.read(b, 0, b.length);
  167. }
  168. /**
  169. * Reads up to <code>len</code> bytes of data from the contained
  170. * input stream into an array of bytes. An attempt is made to read
  171. * as many as <code>len</code> bytes, but a smaller number may be read,
  172. * possibly zero. The number of bytes actually read is returned as an
  173. * integer.
  174. *
  175. * <p> This method blocks until input data is available, end of file is
  176. * detected, or an exception is thrown.
  177. *
  178. * <p> If <code>b</code> is <code>null</code>, a
  179. * <code>NullPointerException</code> is thrown.
  180. *
  181. * <p> If <code>off</code> is negative, or <code>len</code> is negative, or
  182. * <code>off+len</code> is greater than the length of the array
  183. * <code>b</code>, then an <code>IndexOutOfBoundsException</code> is
  184. * thrown.
  185. *
  186. * <p> If <code>len</code> is zero, then no bytes are read and
  187. * <code>0</code> is returned; otherwise, there is an attempt to read at
  188. * least one byte. If no byte is available because the stream is at end of
  189. * file, the value <code>-1</code> is returned; otherwise, at least one
  190. * byte is read and stored into <code>b</code>.
  191. *
  192. * <p> The first byte read is stored into element <code>b[off]</code>, the
  193. * next one into <code>b[off+1]</code>, and so on. The number of bytes read
  194. * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
  195. * bytes actually read; these bytes will be stored in elements
  196. * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
  197. * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
  198. * <code>b[off+len-1]</code> unaffected.
  199. *
  200. * <p> In every case, elements <code>b[0]</code> through
  201. * <code>b[off]</code> and elements <code>b[off+len]</code> through
  202. * <code>b[b.length-1]</code> are unaffected.
  203. *
  204. * <p> If the first byte cannot be read for any reason other than end of
  205. * file, then an <code>IOException</code> is thrown. In particular, an
  206. * <code>IOException</code> is thrown if the input stream has been closed.
  207. *
  208. * @param b the buffer into which the data is read.
  209. * @param off the start offset of the data.
  210. * @param len the maximum number of bytes read.
  211. * @return the total number of bytes read into the buffer, or
  212. * <code>-1</code> if there is no more data because the end
  213. * of the stream has been reached.
  214. * @exception IOException if an I/O error occurs.
  215. * @see java.io.FilterInputStream#in
  216. * @see java.io.InputStream#read(byte[], int, int)
  217. */
  218. public final int read(byte b[], int off, int len) throws IOException {
  219. return in.read(b, off, len);
  220. }
  221. /**
  222. * See the general contract of the <code>readFully</code>
  223. * method of <code>DataInput</code>.
  224. * <p>
  225. * Bytes
  226. * for this operation are read from the contained
  227. * input stream.
  228. *
  229. * @param b the buffer into which the data is read.
  230. * @exception EOFException if this input stream reaches the end before
  231. * reading all the bytes.
  232. * @exception IOException if an I/O error occurs.
  233. * @see java.io.FilterInputStream#in
  234. */
  235. public final void readFully(byte b[]) throws IOException {
  236. readFully(b, 0, b.length);
  237. }
  238. /**
  239. * See the general contract of the <code>readFully</code>
  240. * method of <code>DataInput</code>.
  241. * <p>
  242. * Bytes
  243. * for this operation are read from the contained
  244. * input stream.
  245. *
  246. * @param b the buffer into which the data is read.
  247. * @param off the start offset of the data.
  248. * @param len the number of bytes to read.
  249. * @exception EOFException if this input stream reaches the end before
  250. * reading all the bytes.
  251. * @exception IOException if an I/O error occurs.
  252. * @see java.io.FilterInputStream#in
  253. */
  254. public final void readFully(byte b[], int off, int len) throws IOException {
  255. if (len < 0)
  256. throw new IndexOutOfBoundsException();
  257. int n = 0;
  258. while (n < len) {
  259. int count = in.read(b, off + n, len - n);
  260. if (count < 0)
  261. throw new EOFException();
  262. n += count;
  263. }
  264. }
  265. /**
  266. * See the general contract of the <code>skipBytes</code>
  267. * method of <code>DataInput</code>.
  268. * <p>
  269. * Bytes
  270. * for this operation are read from the contained
  271. * input stream.
  272. *
  273. * @param n the number of bytes to be skipped.
  274. * @return the actual number of bytes skipped.
  275. * @exception IOException if an I/O error occurs.
  276. */
  277. public final int skipBytes(int n) throws IOException {
  278. int total = 0;
  279. int cur = 0;
  280. while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
  281. total += cur;
  282. }
  283. return total;
  284. }
  285. /**
  286. * See the general contract of the <code>readBoolean</code>
  287. * method of <code>DataInput</code>.
  288. * <p>
  289. * Bytes
  290. * for this operation are read from the contained
  291. * input stream.
  292. *
  293. * @return the <code>boolean</code> value read.
  294. * @exception EOFException if this input stream has reached the end.
  295. * @exception IOException if an I/O error occurs.
  296. * @see java.io.FilterInputStream#in
  297. */
  298. public final boolean readBoolean() throws IOException {
  299. int ch = in.read();
  300. if (ch < 0)
  301. throw new EOFException();
  302. return (ch != 0);
  303. }
  304. /**
  305. * See the general contract of the <code>readByte</code>
  306. * method of <code>DataInput</code>.
  307. * <p>
  308. * Bytes
  309. * for this operation are read from the contained
  310. * input stream.
  311. *
  312. * @return the next byte of this input stream as a signed 8-bit
  313. * <code>byte</code>.
  314. * @exception EOFException if this input stream has reached the end.
  315. * @exception IOException if an I/O error occurs.
  316. * @see java.io.FilterInputStream#in
  317. */
  318. public final byte readByte() throws IOException {
  319. int ch = in.read();
  320. if (ch < 0)
  321. throw new EOFException();
  322. return (byte)(ch);
  323. }
  324. /**
  325. * See the general contract of the <code>readUnsignedByte</code>
  326. * method of <code>DataInput</code>.
  327. * <p>
  328. * Bytes
  329. * for this operation are read from the contained
  330. * input stream.
  331. *
  332. * @return the next byte of this input stream, interpreted as an
  333. * unsigned 8-bit number.
  334. * @exception EOFException if this input stream has reached the end.
  335. * @exception IOException if an I/O error occurs.
  336. * @see java.io.FilterInputStream#in
  337. */
  338. public final int readUnsignedByte() throws IOException {
  339. int ch = in.read();
  340. if (ch < 0)
  341. throw new EOFException();
  342. return ch;
  343. }
  344. /**
  345. * See the general contract of the <code>readShort</code>
  346. * method of <code>DataInput</code>.
  347. * <p>
  348. * Bytes
  349. * for this operation are read from the contained
  350. * input stream.
  351. *
  352. * @return the next two bytes of this input stream, interpreted as a
  353. * signed 16-bit number.
  354. * @exception EOFException if this input stream reaches the end before
  355. * reading two bytes.
  356. * @exception IOException if an I/O error occurs.
  357. * @see java.io.FilterInputStream#in
  358. */
  359. public final short readShort() throws IOException {
  360. int ch1 = in.read();
  361. int ch2 = in.read();
  362. if ((ch1 | ch2) < 0)
  363. throw new EOFException();
  364. return (short)((ch1 << 8) + (ch2 << 0));
  365. }
  366. /**
  367. * See the general contract of the <code>readUnsignedShort</code>
  368. * method of <code>DataInput</code>.
  369. * <p>
  370. * Bytes
  371. * for this operation are read from the contained
  372. * input stream.
  373. *
  374. * @return the next two bytes of this input stream, interpreted as an
  375. * unsigned 16-bit integer.
  376. * @exception EOFException if this input stream reaches the end before
  377. * reading two bytes.
  378. * @exception IOException if an I/O error occurs.
  379. * @see java.io.FilterInputStream#in
  380. */
  381. public final int readUnsignedShort() throws IOException {
  382. int ch1 = in.read();
  383. int ch2 = in.read();
  384. if ((ch1 | ch2) < 0)
  385. throw new EOFException();
  386. return (ch1 << 8) + (ch2 << 0);
  387. }
  388. /**
  389. * See the general contract of the <code>readChar</code>
  390. * method of <code>DataInput</code>.
  391. * <p>
  392. * Bytes
  393. * for this operation are read from the contained
  394. * input stream.
  395. *
  396. * @return the next two bytes of this input stream as a Unicode
  397. * character.
  398. * @exception EOFException if this input stream reaches the end before
  399. * reading two bytes.
  400. * @exception IOException if an I/O error occurs.
  401. * @see java.io.FilterInputStream#in
  402. */
  403. public final char readChar() throws IOException {
  404. int ch1 = in.read();
  405. int ch2 = in.read();
  406. if ((ch1 | ch2) < 0)
  407. throw new EOFException();
  408. return (char)((ch1 << 8) + (ch2 << 0));
  409. }
  410. /**
  411. * See the general contract of the <code>readInt</code>
  412. * method of <code>DataInput</code>.
  413. * <p>
  414. * Bytes
  415. * for this operation are read from the contained
  416. * input stream.
  417. *
  418. * @return the next four bytes of this input stream, interpreted as an
  419. * <code>int</code>.
  420. * @exception EOFException if this input stream reaches the end before
  421. * reading four bytes.
  422. * @exception IOException if an I/O error occurs.
  423. * @see java.io.FilterInputStream#in
  424. */
  425. public final int readInt() throws IOException {
  426. int ch1 = in.read();
  427. int ch2 = in.read();
  428. int ch3 = in.read();
  429. int ch4 = in.read();
  430. if ((ch1 | ch2 | ch3 | ch4) < 0)
  431. throw new EOFException();
  432. return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
  433. }
  434. private byte readBuffer[] = new byte[8];
  435. /**
  436. * See the general contract of the <code>readLong</code>
  437. * method of <code>DataInput</code>.
  438. * <p>
  439. * Bytes
  440. * for this operation are read from the contained
  441. * input stream.
  442. *
  443. * @return the next eight bytes of this input stream, interpreted as a
  444. * <code>long</code>.
  445. * @exception EOFException if this input stream reaches the end before
  446. * reading eight bytes.
  447. * @exception IOException if an I/O error occurs.
  448. * @see java.io.FilterInputStream#in
  449. */
  450. public final long readLong() throws IOException {
  451. readFully(readBuffer, 0, 8);
  452. return (((long)readBuffer[0] << 56) +
  453. ((long)(readBuffer[1] & 255) << 48) +
  454. ((long)(readBuffer[2] & 255) << 40) +
  455. ((long)(readBuffer[3] & 255) << 32) +
  456. ((long)(readBuffer[4] & 255) << 24) +
  457. ((readBuffer[5] & 255) << 16) +
  458. ((readBuffer[6] & 255) << 8) +
  459. ((readBuffer[7] & 255) << 0));
  460. }
  461. /**
  462. * See the general contract of the <code>readFloat</code>
  463. * method of <code>DataInput</code>.
  464. * <p>
  465. * Bytes
  466. * for this operation are read from the contained
  467. * input stream.
  468. *
  469. * @return the next four bytes of this input stream, interpreted as a
  470. * <code>float</code>.
  471. * @exception EOFException if this input stream reaches the end before
  472. * reading four bytes.
  473. * @exception IOException if an I/O error occurs.
  474. * @see java.io.DataInputStream#readInt()
  475. * @see java.lang.Float#intBitsToFloat(int)
  476. */
  477. public final float readFloat() throws IOException {
  478. return Float.intBitsToFloat(readInt());
  479. }
  480. /**
  481. * See the general contract of the <code>readDouble</code>
  482. * method of <code>DataInput</code>.
  483. * <p>
  484. * Bytes
  485. * for this operation are read from the contained
  486. * input stream.
  487. *
  488. * @return the next eight bytes of this input stream, interpreted as a
  489. * <code>double</code>.
  490. * @exception EOFException if this input stream reaches the end before
  491. * reading eight bytes.
  492. * @exception IOException if an I/O error occurs.
  493. * @see java.io.DataInputStream#readLong()
  494. * @see java.lang.Double#longBitsToDouble(long)
  495. */
  496. public final double readDouble() throws IOException {
  497. return Double.longBitsToDouble(readLong());
  498. }
  499. private char lineBuffer[];
  500. /**
  501. * See the general contract of the <code>readLine</code>
  502. * method of <code>DataInput</code>.
  503. * <p>
  504. * Bytes
  505. * for this operation are read from the contained
  506. * input stream.
  507. *
  508. * @deprecated This method does not properly convert bytes to characters.
  509. * As of JDK 1.1, the preferred way to read lines of text is via the
  510. * <code>BufferedReader.readLine()</code> method. Programs that use the
  511. * <code>DataInputStream</code> class to read lines can be converted to use
  512. * the <code>BufferedReader</code> class by replacing code of the form:
  513. * <blockquote><pre>
  514. * DataInputStream d = new DataInputStream(in);
  515. * </pre></blockquote>
  516. * with:
  517. * <blockquote><pre>
  518. * BufferedReader d
  519. * = new BufferedReader(new InputStreamReader(in));
  520. * </pre></blockquote>
  521. *
  522. * @return the next line of text from this input stream.
  523. * @exception IOException if an I/O error occurs.
  524. * @see java.io.BufferedReader#readLine()
  525. * @see java.io.FilterInputStream#in
  526. */
  527. public final String readLine() throws IOException {
  528. char buf[] = lineBuffer;
  529. if (buf == null) {
  530. buf = lineBuffer = new char[128];
  531. }
  532. int room = buf.length;
  533. int offset = 0;
  534. int c;
  535. loop: while (true) {
  536. switch (c = in.read()) {
  537. case -1:
  538. case '\n':
  539. break loop;
  540. case '\r':
  541. int c2 = in.read();
  542. if ((c2 != '\n') && (c2 != -1)) {
  543. if (!(in instanceof PushbackInputStream)) {
  544. this.in = new PushbackInputStream(in);
  545. }
  546. ((PushbackInputStream)in).unread(c2);
  547. }
  548. break loop;
  549. default:
  550. if (--room < 0) {
  551. buf = new char[offset + 128];
  552. room = buf.length - offset - 1;
  553. System.arraycopy(lineBuffer, 0, buf, 0, offset);
  554. lineBuffer = buf;
  555. }
  556. buf[offset++] = (char) c;
  557. break;
  558. }
  559. }
  560. if ((c == -1) && (offset == 0)) {
  561. return null;
  562. }
  563. return String.copyValueOf(buf, 0, offset);
  564. }
  565. /**
  566. * See the general contract of the <code>readUTF</code>
  567. * method of <code>DataInput</code>.
  568. * <p>
  569. * Bytes
  570. * for this operation are read from the contained
  571. * input stream.
  572. *
  573. * @return a Unicode string.
  574. * @exception EOFException if this input stream reaches the end before
  575. * reading all the bytes.
  576. * @exception IOException if an I/O error occurs.
  577. * @exception UTFDataFormatException if the bytes do not represent a valid UTF-8 encoding of a string.
  578. * @see java.io.DataInputStream#readUTF(java.io.DataInput)
  579. */
  580. public final String readUTF() throws IOException {
  581. return readUTF(this);
  582. }
  583. /**
  584. * Reads from the
  585. * stream <code>in</code> a representation
  586. * of a Unicode character string encoded in
  587. * Java modified UTF-8 format; this string
  588. * of characters is then returned as a <code>String</code>.
  589. * The details of the modified UTF-8 representation
  590. * are exactly the same as for the <code>readUTF</code>
  591. * method of <code>DataInput</code>.
  592. *
  593. * @param in a data input stream.
  594. * @return a Unicode string.
  595. * @exception EOFException if the input stream reaches the end
  596. * before all the bytes.
  597. * @exception IOException if an I/O error occurs.
  598. * @exception UTFDataFormatException if the bytes do not represent a
  599. * valid Java modified UTF-8 encoding of a Unicode string.
  600. * @see java.io.DataInputStream#readUnsignedShort()
  601. */
  602. public final static String readUTF(DataInput in) throws IOException {
  603. int utflen = in.readUnsignedShort();
  604. StringBuffer str = new StringBuffer(utflen);
  605. byte bytearr [] = new byte[utflen];
  606. int c, char2, char3;
  607. int count = 0;
  608. in.readFully(bytearr, 0, utflen);
  609. while (count < utflen) {
  610. c = (int) bytearr[count] & 0xff;
  611. switch (c >> 4) {
  612. case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  613. /* 0xxxxxxx*/
  614. count++;
  615. str.append((char)c);
  616. break;
  617. case 12: case 13:
  618. /* 110x xxxx 10xx xxxx*/
  619. count += 2;
  620. if (count > utflen)
  621. throw new UTFDataFormatException();
  622. char2 = (int) bytearr[count-1];
  623. if ((char2 & 0xC0) != 0x80)
  624. throw new UTFDataFormatException();
  625. str.append((char)(((c & 0x1F) << 6) | (char2 & 0x3F)));
  626. break;
  627. case 14:
  628. /* 1110 xxxx 10xx xxxx 10xx xxxx */
  629. count += 3;
  630. if (count > utflen)
  631. throw new UTFDataFormatException();
  632. char2 = (int) bytearr[count-2];
  633. char3 = (int) bytearr[count-1];
  634. if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
  635. throw new UTFDataFormatException();
  636. str.append((char)(((c & 0x0F) << 12) |
  637. ((char2 & 0x3F) << 6) |
  638. ((char3 & 0x3F) << 0)));
  639. break;
  640. default:
  641. /* 10xx xxxx, 1111 xxxx */
  642. throw new UTFDataFormatException();
  643. }
  644. }
  645. // The number of chars produced may be less than utflen
  646. return new String(str);
  647. }
  648. }