code: public static final int readUTF(InputStream in,
                                      char[] chars, int offset, int length)
          throws IOException
      {
          if (length == 0) {
              return 0;
          }
  
          int c, c2, c3;
  
          int charCount = 0;
          while (charCount < length) {
              c = in.read();
              if (c < 0) {
                  break;
              }
              c &= 0xff;
              switch (c >> 4) {
              case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
                  // 0xxxxxxx
                  chars[offset + charCount++] = (char)c;
                  break;
              case 12: case 13:
                  // 110x xxxx  10xx xxxx
                  c2 = in.read();
                  if (c2 < 0) {
                      throw new EOFException();
                  }
                  if ((c2 & 0xc0) != 0x80) {
                      throw new UTFDataFormatException();
                  }
                  chars[offset + charCount++] =
                      (char)(((c & 0x1f) << 6) | (c2 & 0x3f));
                  break;
              case 14:
                  // 1110 xxxx  10xx xxxx  10xx xxxx
                  c2 = in.read();
                  if (c2 < 0) {
                      throw new EOFException();
                  }
                  c3 = in.read();
                  if (c3 < 0) {
                      throw new EOFException();
                  }
                  if ((c2 & 0xc0) != 0x80 || (c3 & 0xc0) != 0x80) {
                      throw new UTFDataFormatException();
                  }
                  chars[offset + charCount++] = (char)(((c & 0x0f) << 12) |
                                                       ((c2 & 0x3f) << 6) |
                                                       (c3 & 0x3f));
                  break;
              default:
                  // 10xx xxxx,  1111 xxxx
                  throw new UTFDataFormatException();
              }
          }
  
          return (charCount == 0) ? -1 : charCount;
      }
docs: Reads UTF-8 encoded characters from the given stream, but does not read
  the length.
  
  @return number of characters actually read, or -1 if EOF reached.