rt/emul/mini/src/main/java/java/io/DataInputStream.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 17 Jan 2017 07:04:06 +0100
changeset 1985 cd1cc103a03c
parent 772 d382dacfd73f
permissions -rw-r--r--
Implementation of ClassValue for bck2brwsr
     1 /*
     2  * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 package java.io;
    27 
    28 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    29 import org.apidesign.bck2brwsr.emul.lang.System;
    30 
    31 /**
    32  * A data input stream lets an application read primitive Java data
    33  * types from an underlying input stream in a machine-independent
    34  * way. An application uses a data output stream to write data that
    35  * can later be read by a data input stream.
    36  * <p>
    37  * DataInputStream is not necessarily safe for multithreaded access.
    38  * Thread safety is optional and is the responsibility of users of
    39  * methods in this class.
    40  *
    41  * @author  Arthur van Hoff
    42  * @see     java.io.DataOutputStream
    43  * @since   JDK1.0
    44  */
    45 public
    46 class DataInputStream extends FilterInputStream implements DataInput {
    47 
    48     /**
    49      * Creates a DataInputStream that uses the specified
    50      * underlying InputStream.
    51      *
    52      * @param  in   the specified input stream
    53      */
    54     public DataInputStream(InputStream in) {
    55         super(in);
    56     }
    57 
    58     /**
    59      * working arrays initialized on demand by readUTF
    60      */
    61     private byte bytearr[] = new byte[80];
    62     private char chararr[] = new char[80];
    63 
    64     /**
    65      * Reads some number of bytes from the contained input stream and
    66      * stores them into the buffer array <code>b</code>. The number of
    67      * bytes actually read is returned as an integer. This method blocks
    68      * until input data is available, end of file is detected, or an
    69      * exception is thrown.
    70      *
    71      * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
    72      * thrown. If the length of <code>b</code> is zero, then no bytes are
    73      * read and <code>0</code> is returned; otherwise, there is an attempt
    74      * to read at least one byte. If no byte is available because the
    75      * stream is at end of file, the value <code>-1</code> is returned;
    76      * otherwise, at least one byte is read and stored into <code>b</code>.
    77      *
    78      * <p>The first byte read is stored into element <code>b[0]</code>, the
    79      * next one into <code>b[1]</code>, and so on. The number of bytes read
    80      * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
    81      * be the number of bytes actually read; these bytes will be stored in
    82      * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
    83      * elements <code>b[k]</code> through <code>b[b.length-1]</code>
    84      * unaffected.
    85      *
    86      * <p>The <code>read(b)</code> method has the same effect as:
    87      * <blockquote><pre>
    88      * read(b, 0, b.length)
    89      * </pre></blockquote>
    90      *
    91      * @param      b   the buffer into which the data is read.
    92      * @return     the total number of bytes read into the buffer, or
    93      *             <code>-1</code> if there is no more data because the end
    94      *             of the stream has been reached.
    95      * @exception  IOException if the first byte cannot be read for any reason
    96      * other than end of file, the stream has been closed and the underlying
    97      * input stream does not support reading after close, or another I/O
    98      * error occurs.
    99      * @see        java.io.FilterInputStream#in
   100      * @see        java.io.InputStream#read(byte[], int, int)
   101      */
   102     public final int read(byte b[]) throws IOException {
   103         return in.read(b, 0, b.length);
   104     }
   105 
   106     /**
   107      * Reads up to <code>len</code> bytes of data from the contained
   108      * input stream into an array of bytes.  An attempt is made to read
   109      * as many as <code>len</code> bytes, but a smaller number may be read,
   110      * possibly zero. The number of bytes actually read is returned as an
   111      * integer.
   112      *
   113      * <p> This method blocks until input data is available, end of file is
   114      * detected, or an exception is thrown.
   115      *
   116      * <p> If <code>len</code> is zero, then no bytes are read and
   117      * <code>0</code> is returned; otherwise, there is an attempt to read at
   118      * least one byte. If no byte is available because the stream is at end of
   119      * file, the value <code>-1</code> is returned; otherwise, at least one
   120      * byte is read and stored into <code>b</code>.
   121      *
   122      * <p> The first byte read is stored into element <code>b[off]</code>, the
   123      * next one into <code>b[off+1]</code>, and so on. The number of bytes read
   124      * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
   125      * bytes actually read; these bytes will be stored in elements
   126      * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
   127      * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
   128      * <code>b[off+len-1]</code> unaffected.
   129      *
   130      * <p> In every case, elements <code>b[0]</code> through
   131      * <code>b[off]</code> and elements <code>b[off+len]</code> through
   132      * <code>b[b.length-1]</code> are unaffected.
   133      *
   134      * @param      b     the buffer into which the data is read.
   135      * @param off the start offset in the destination array <code>b</code>
   136      * @param      len   the maximum number of bytes read.
   137      * @return     the total number of bytes read into the buffer, or
   138      *             <code>-1</code> if there is no more data because the end
   139      *             of the stream has been reached.
   140      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   141      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   142      * <code>len</code> is negative, or <code>len</code> is greater than
   143      * <code>b.length - off</code>
   144      * @exception  IOException if the first byte cannot be read for any reason
   145      * other than end of file, the stream has been closed and the underlying
   146      * input stream does not support reading after close, or another I/O
   147      * error occurs.
   148      * @see        java.io.FilterInputStream#in
   149      * @see        java.io.InputStream#read(byte[], int, int)
   150      */
   151     public final int read(byte b[], int off, int len) throws IOException {
   152         return in.read(b, off, len);
   153     }
   154 
   155     /**
   156      * See the general contract of the <code>readFully</code>
   157      * method of <code>DataInput</code>.
   158      * <p>
   159      * Bytes
   160      * for this operation are read from the contained
   161      * input stream.
   162      *
   163      * @param      b   the buffer into which the data is read.
   164      * @exception  EOFException  if this input stream reaches the end before
   165      *             reading all the bytes.
   166      * @exception  IOException   the stream has been closed and the contained
   167      *             input stream does not support reading after close, or
   168      *             another I/O error occurs.
   169      * @see        java.io.FilterInputStream#in
   170      */
   171     public final void readFully(byte b[]) throws IOException {
   172         readFully(b, 0, b.length);
   173     }
   174 
   175     /**
   176      * See the general contract of the <code>readFully</code>
   177      * method of <code>DataInput</code>.
   178      * <p>
   179      * Bytes
   180      * for this operation are read from the contained
   181      * input stream.
   182      *
   183      * @param      b     the buffer into which the data is read.
   184      * @param      off   the start offset of the data.
   185      * @param      len   the number of bytes to read.
   186      * @exception  EOFException  if this input stream reaches the end before
   187      *               reading all the bytes.
   188      * @exception  IOException   the stream has been closed and the contained
   189      *             input stream does not support reading after close, or
   190      *             another I/O error occurs.
   191      * @see        java.io.FilterInputStream#in
   192      */
   193     public final void readFully(byte b[], int off, int len) throws IOException {
   194         if (len < 0)
   195             throw new IndexOutOfBoundsException();
   196         int n = 0;
   197         while (n < len) {
   198             int count = in.read(b, off + n, len - n);
   199             if (count < 0)
   200                 throw new EOFException();
   201             n += count;
   202         }
   203     }
   204 
   205     /**
   206      * See the general contract of the <code>skipBytes</code>
   207      * method of <code>DataInput</code>.
   208      * <p>
   209      * Bytes for this operation are read from the contained
   210      * input stream.
   211      *
   212      * @param      n   the number of bytes to be skipped.
   213      * @return     the actual number of bytes skipped.
   214      * @exception  IOException  if the contained input stream does not support
   215      *             seek, or the stream has been closed and
   216      *             the contained input stream does not support
   217      *             reading after close, or another I/O error occurs.
   218      */
   219     public final int skipBytes(int n) throws IOException {
   220         int total = 0;
   221         int cur = 0;
   222 
   223         while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
   224             total += cur;
   225         }
   226 
   227         return total;
   228     }
   229 
   230     /**
   231      * See the general contract of the <code>readBoolean</code>
   232      * method of <code>DataInput</code>.
   233      * <p>
   234      * Bytes for this operation are read from the contained
   235      * input stream.
   236      *
   237      * @return     the <code>boolean</code> value read.
   238      * @exception  EOFException  if this input stream has reached the end.
   239      * @exception  IOException   the stream has been closed and the contained
   240      *             input stream does not support reading after close, or
   241      *             another I/O error occurs.
   242      * @see        java.io.FilterInputStream#in
   243      */
   244     public final boolean readBoolean() throws IOException {
   245         int ch = in.read();
   246         if (ch < 0)
   247             throw new EOFException();
   248         return (ch != 0);
   249     }
   250 
   251     /**
   252      * See the general contract of the <code>readByte</code>
   253      * method of <code>DataInput</code>.
   254      * <p>
   255      * Bytes
   256      * for this operation are read from the contained
   257      * input stream.
   258      *
   259      * @return     the next byte of this input stream as a signed 8-bit
   260      *             <code>byte</code>.
   261      * @exception  EOFException  if this input stream has reached the end.
   262      * @exception  IOException   the stream has been closed and the contained
   263      *             input stream does not support reading after close, or
   264      *             another I/O error occurs.
   265      * @see        java.io.FilterInputStream#in
   266      */
   267     public final byte readByte() throws IOException {
   268         int ch = in.read();
   269         if (ch < 0)
   270             throw new EOFException();
   271         return (byte)(ch);
   272     }
   273 
   274     /**
   275      * See the general contract of the <code>readUnsignedByte</code>
   276      * method of <code>DataInput</code>.
   277      * <p>
   278      * Bytes
   279      * for this operation are read from the contained
   280      * input stream.
   281      *
   282      * @return     the next byte of this input stream, interpreted as an
   283      *             unsigned 8-bit number.
   284      * @exception  EOFException  if this input stream has reached the end.
   285      * @exception  IOException   the stream has been closed and the contained
   286      *             input stream does not support reading after close, or
   287      *             another I/O error occurs.
   288      * @see         java.io.FilterInputStream#in
   289      */
   290     public final int readUnsignedByte() throws IOException {
   291         int ch = in.read();
   292         if (ch < 0)
   293             throw new EOFException();
   294         return ch;
   295     }
   296 
   297     /**
   298      * See the general contract of the <code>readShort</code>
   299      * method of <code>DataInput</code>.
   300      * <p>
   301      * Bytes
   302      * for this operation are read from the contained
   303      * input stream.
   304      *
   305      * @return     the next two bytes of this input stream, interpreted as a
   306      *             signed 16-bit number.
   307      * @exception  EOFException  if this input stream reaches the end before
   308      *               reading two bytes.
   309      * @exception  IOException   the stream has been closed and the contained
   310      *             input stream does not support reading after close, or
   311      *             another I/O error occurs.
   312      * @see        java.io.FilterInputStream#in
   313      */
   314     public final short readShort() throws IOException {
   315         int ch1 = in.read();
   316         int ch2 = in.read();
   317         if ((ch1 | ch2) < 0)
   318             throw new EOFException();
   319         return (short)((ch1 << 8) + (ch2 << 0));
   320     }
   321 
   322     /**
   323      * See the general contract of the <code>readUnsignedShort</code>
   324      * method of <code>DataInput</code>.
   325      * <p>
   326      * Bytes
   327      * for this operation are read from the contained
   328      * input stream.
   329      *
   330      * @return     the next two bytes of this input stream, interpreted as an
   331      *             unsigned 16-bit integer.
   332      * @exception  EOFException  if this input stream reaches the end before
   333      *             reading two bytes.
   334      * @exception  IOException   the stream has been closed and the contained
   335      *             input stream does not support reading after close, or
   336      *             another I/O error occurs.
   337      * @see        java.io.FilterInputStream#in
   338      */
   339     public final int readUnsignedShort() throws IOException {
   340         int ch1 = in.read();
   341         int ch2 = in.read();
   342         if ((ch1 | ch2) < 0)
   343             throw new EOFException();
   344         return (ch1 << 8) + (ch2 << 0);
   345     }
   346 
   347     /**
   348      * See the general contract of the <code>readChar</code>
   349      * method of <code>DataInput</code>.
   350      * <p>
   351      * Bytes
   352      * for this operation are read from the contained
   353      * input stream.
   354      *
   355      * @return     the next two bytes of this input stream, interpreted as a
   356      *             <code>char</code>.
   357      * @exception  EOFException  if this input stream reaches the end before
   358      *               reading two bytes.
   359      * @exception  IOException   the stream has been closed and the contained
   360      *             input stream does not support reading after close, or
   361      *             another I/O error occurs.
   362      * @see        java.io.FilterInputStream#in
   363      */
   364     public final char readChar() throws IOException {
   365         int ch1 = in.read();
   366         int ch2 = in.read();
   367         if ((ch1 | ch2) < 0)
   368             throw new EOFException();
   369         return (char)((ch1 << 8) + (ch2 << 0));
   370     }
   371 
   372     /**
   373      * See the general contract of the <code>readInt</code>
   374      * method of <code>DataInput</code>.
   375      * <p>
   376      * Bytes
   377      * for this operation are read from the contained
   378      * input stream.
   379      *
   380      * @return     the next four bytes of this input stream, interpreted as an
   381      *             <code>int</code>.
   382      * @exception  EOFException  if this input stream reaches the end before
   383      *               reading four bytes.
   384      * @exception  IOException   the stream has been closed and the contained
   385      *             input stream does not support reading after close, or
   386      *             another I/O error occurs.
   387      * @see        java.io.FilterInputStream#in
   388      */
   389     public final int readInt() throws IOException {
   390         int ch1 = in.read();
   391         int ch2 = in.read();
   392         int ch3 = in.read();
   393         int ch4 = in.read();
   394         if ((ch1 | ch2 | ch3 | ch4) < 0)
   395             throw new EOFException();
   396         return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
   397     }
   398 
   399     private byte readBuffer[] = new byte[8];
   400 
   401     /**
   402      * See the general contract of the <code>readLong</code>
   403      * method of <code>DataInput</code>.
   404      * <p>
   405      * Bytes
   406      * for this operation are read from the contained
   407      * input stream.
   408      *
   409      * @return     the next eight bytes of this input stream, interpreted as a
   410      *             <code>long</code>.
   411      * @exception  EOFException  if this input stream reaches the end before
   412      *               reading eight bytes.
   413      * @exception  IOException   the stream has been closed and the contained
   414      *             input stream does not support reading after close, or
   415      *             another I/O error occurs.
   416      * @see        java.io.FilterInputStream#in
   417      */
   418     public final long readLong() throws IOException {
   419         readFully(readBuffer, 0, 8);
   420         return (((long)readBuffer[0] << 56) +
   421                 ((long)(readBuffer[1] & 255) << 48) +
   422                 ((long)(readBuffer[2] & 255) << 40) +
   423                 ((long)(readBuffer[3] & 255) << 32) +
   424                 ((long)(readBuffer[4] & 255) << 24) +
   425                 ((readBuffer[5] & 255) << 16) +
   426                 ((readBuffer[6] & 255) <<  8) +
   427                 ((readBuffer[7] & 255) <<  0));
   428     }
   429 
   430     /**
   431      * See the general contract of the <code>readFloat</code>
   432      * method of <code>DataInput</code>.
   433      * <p>
   434      * Bytes
   435      * for this operation are read from the contained
   436      * input stream.
   437      *
   438      * @return     the next four bytes of this input stream, interpreted as a
   439      *             <code>float</code>.
   440      * @exception  EOFException  if this input stream reaches the end before
   441      *               reading four bytes.
   442      * @exception  IOException   the stream has been closed and the contained
   443      *             input stream does not support reading after close, or
   444      *             another I/O error occurs.
   445      * @see        java.io.DataInputStream#readInt()
   446      * @see        java.lang.Float#intBitsToFloat(int)
   447      */
   448     public final float readFloat() throws IOException {
   449         return Float.intBitsToFloat(readInt());
   450     }
   451 
   452     /**
   453      * See the general contract of the <code>readDouble</code>
   454      * method of <code>DataInput</code>.
   455      * <p>
   456      * Bytes
   457      * for this operation are read from the contained
   458      * input stream.
   459      *
   460      * @return     the next eight bytes of this input stream, interpreted as a
   461      *             <code>double</code>.
   462      * @exception  EOFException  if this input stream reaches the end before
   463      *               reading eight bytes.
   464      * @exception  IOException   the stream has been closed and the contained
   465      *             input stream does not support reading after close, or
   466      *             another I/O error occurs.
   467      * @see        java.io.DataInputStream#readLong()
   468      * @see        java.lang.Double#longBitsToDouble(long)
   469      */
   470     public final double readDouble() throws IOException {
   471         return Double.longBitsToDouble(readLong());
   472     }    
   473 
   474     private char lineBuffer[];
   475 
   476     /**
   477      * See the general contract of the <code>readLine</code>
   478      * method of <code>DataInput</code>.
   479      * <p>
   480      * Bytes
   481      * for this operation are read from the contained
   482      * input stream.
   483      *
   484      * @deprecated This method does not properly convert bytes to characters.
   485      * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
   486      * <code>BufferedReader.readLine()</code> method.  Programs that use the
   487      * <code>DataInputStream</code> class to read lines can be converted to use
   488      * the <code>BufferedReader</code> class by replacing code of the form:
   489      * <blockquote><pre>
   490      *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
   491      * </pre></blockquote>
   492      * with:
   493      * <blockquote><pre>
   494      *     BufferedReader d
   495      *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
   496      * </pre></blockquote>
   497      *
   498      * @return     the next line of text from this input stream.
   499      * @exception  IOException  if an I/O error occurs.
   500      * @see        java.io.BufferedReader#readLine()
   501      * @see        java.io.FilterInputStream#in
   502      */
   503     @Deprecated
   504     public final String readLine() throws IOException {
   505         char buf[] = lineBuffer;
   506 
   507         if (buf == null) {
   508             buf = lineBuffer = new char[128];
   509         }
   510 
   511         int room = buf.length;
   512         int offset = 0;
   513         int c;
   514 
   515 loop:   while (true) {
   516             switch (c = in.read()) {
   517               case -1:
   518               case '\n':
   519                 break loop;
   520 
   521               case '\r':
   522                 int c2 = in.read();
   523                 if ((c2 != '\n') && (c2 != -1)) {
   524                     if (!(in instanceof PushbackInputStream)) {
   525                         this.in = new PushbackInputStream(in);
   526                     }
   527                     ((PushbackInputStream)in).unread(c2);
   528                 }
   529                 break loop;
   530 
   531               default:
   532                 if (--room < 0) {
   533                     buf = new char[offset + 128];
   534                     room = buf.length - offset - 1;
   535                     System.arraycopy(lineBuffer, 0, buf, 0, offset);
   536                     lineBuffer = buf;
   537                 }
   538                 buf[offset++] = (char) c;
   539                 break;
   540             }
   541         }
   542         if ((c == -1) && (offset == 0)) {
   543             return null;
   544         }
   545         return String.copyValueOf(buf, 0, offset);
   546     }
   547 
   548     /**
   549      * See the general contract of the <code>readUTF</code>
   550      * method of <code>DataInput</code>.
   551      * <p>
   552      * Bytes
   553      * for this operation are read from the contained
   554      * input stream.
   555      *
   556      * @return     a Unicode string.
   557      * @exception  EOFException  if this input stream reaches the end before
   558      *               reading all the bytes.
   559      * @exception  IOException   the stream has been closed and the contained
   560      *             input stream does not support reading after close, or
   561      *             another I/O error occurs.
   562      * @exception  UTFDataFormatException if the bytes do not represent a valid
   563      *             modified UTF-8 encoding of a string.
   564      * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
   565      */
   566     public final String readUTF() throws IOException {
   567         return readUTF(this);
   568     }
   569 
   570     /**
   571      * Reads from the
   572      * stream <code>in</code> a representation
   573      * of a Unicode  character string encoded in
   574      * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
   575      * this string of characters is then returned as a <code>String</code>.
   576      * The details of the modified UTF-8 representation
   577      * are  exactly the same as for the <code>readUTF</code>
   578      * method of <code>DataInput</code>.
   579      *
   580      * @param      in   a data input stream.
   581      * @return     a Unicode string.
   582      * @exception  EOFException            if the input stream reaches the end
   583      *               before all the bytes.
   584      * @exception  IOException   the stream has been closed and the contained
   585      *             input stream does not support reading after close, or
   586      *             another I/O error occurs.
   587      * @exception  UTFDataFormatException  if the bytes do not represent a
   588      *               valid modified UTF-8 encoding of a Unicode string.
   589      * @see        java.io.DataInputStream#readUnsignedShort()
   590      */
   591     public final static String readUTF(DataInput in) throws IOException {
   592         int utflen = in.readUnsignedShort();
   593         byte[] bytearr = null;
   594         char[] chararr = null;
   595         if (in instanceof DataInputStream) {
   596             DataInputStream dis = (DataInputStream)in;
   597             if (dis.bytearr.length < utflen){
   598                 dis.bytearr = new byte[utflen*2];
   599                 dis.chararr = new char[utflen*2];
   600             }
   601             chararr = dis.chararr;
   602             bytearr = dis.bytearr;
   603         } else {
   604             bytearr = new byte[utflen];
   605             chararr = new char[utflen];
   606         }
   607 
   608         int c, char2, char3;
   609         int count = 0;
   610         int chararr_count=0;
   611 
   612         in.readFully(bytearr, 0, utflen);
   613 
   614         while (count < utflen) {
   615             c = (int) bytearr[count] & 0xff;
   616             if (c > 127) break;
   617             count++;
   618             chararr[chararr_count++]=(char)c;
   619         }
   620 
   621         while (count < utflen) {
   622             c = (int) bytearr[count] & 0xff;
   623             switch (c >> 4) {
   624                 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
   625                     /* 0xxxxxxx*/
   626                     count++;
   627                     chararr[chararr_count++]=(char)c;
   628                     break;
   629                 case 12: case 13:
   630                     /* 110x xxxx   10xx xxxx*/
   631                     count += 2;
   632                     if (count > utflen)
   633                         throw new UTFDataFormatException(
   634                             "malformed input: partial character at end");
   635                     char2 = (int) bytearr[count-1];
   636                     if ((char2 & 0xC0) != 0x80)
   637                         throw new UTFDataFormatException(
   638                             "malformed input around byte " + count);
   639                     chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
   640                                                     (char2 & 0x3F));
   641                     break;
   642                 case 14:
   643                     /* 1110 xxxx  10xx xxxx  10xx xxxx */
   644                     count += 3;
   645                     if (count > utflen)
   646                         throw new UTFDataFormatException(
   647                             "malformed input: partial character at end");
   648                     char2 = (int) bytearr[count-2];
   649                     char3 = (int) bytearr[count-1];
   650                     if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
   651                         throw new UTFDataFormatException(
   652                             "malformed input around byte " + (count-1));
   653                     chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
   654                                                     ((char2 & 0x3F) << 6)  |
   655                                                     ((char3 & 0x3F) << 0));
   656                     break;
   657                 default:
   658                     /* 10xx xxxx,  1111 xxxx */
   659                     throw new UTFDataFormatException(
   660                         "malformed input around byte " + count);
   661             }
   662         }
   663         // The number of chars produced may be less than utflen
   664         return new String(chararr, 0, chararr_count);
   665     }
   666 }