Package java.io

Examples of java.io.UTFDataFormatException


                utflen += 2;
            }
        }

        if (utflen > 65535) {
            throw new UTFDataFormatException("utflen > 65536!");
        }

        byte[] b = new byte[utflen+2];
        b[boff++] = (byte) ((utflen >>> 8) & 0xFF);
        b[boff++] = (byte) ((utflen >>> 0) & 0xFF);
View Full Code Here


    utflen += 2;
      }
  }

  if (utflen > 65535) {
      throw new UTFDataFormatException("utflen > 65536!");
        }

  byte[] b = new byte[utflen+2];
  b[boff++] = (byte) ((utflen >>> 8) & 0xFF);
  b[boff++] = (byte) ((utflen >>> 0) & 0xFF);
View Full Code Here

                case 12:
                case 13:
                    /* 110x xxxx   10xx xxxx*/
                    count += 2;
                    if (count > endPos)
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    char2 = (int) bytearr[count - 1];
                    if ((char2 & 0xC0) != 0x80)
                        throw new UTFDataFormatException(
                                "malformed input around byte " + count);
                    chararr[chararr_count++] = (char) (((c & 0x1F) << 6) |
                            (char2 & 0x3F));
                    break;
                case 14:
                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
                    count += 3;
                    if (count > endPos)
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    char2 = (int) bytearr[count - 2];
                    char3 = (int) bytearr[count - 1];
                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                        throw new UTFDataFormatException(
                                "malformed input around byte " + (count - 1));
                    chararr[chararr_count++] = (char) (((c & 0x0F) << 12) |
                            ((char2 & 0x3F) << 6) |
                            ((char3 & 0x3F) << 0));
                    break;
                default:
                    /* 10xx xxxx,  1111 xxxx */
                    throw new UTFDataFormatException(
                            "malformed input around byte " + count);
            }
        }
        pos += utflen;
        // The number of chars produced may be less than utflen
View Full Code Here

                case 12:
                case 13:
                    /* 110x xxxx   10xx xxxx*/
                    count += 2;
                    if (count > utflen)
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    char2 = (int) bytearr[count - 1];
                    if ((char2 & 0xC0) != 0x80)
                        throw new UTFDataFormatException(
                                "malformed input around byte " + count);
                    chararr[chararr_count++] = (char) (((c & 0x1F) << 6) |
                            (char2 & 0x3F));
                    break;
                case 14:
                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
                    count += 3;
                    if (count > utflen)
                        throw new UTFDataFormatException(
                                "malformed input: partial character at end");
                    char2 = (int) bytearr[count - 2];
                    char3 = (int) bytearr[count - 1];
                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                        throw new UTFDataFormatException(
                                "malformed input around byte " + (count - 1));
                    chararr[chararr_count++] = (char) (((c & 0x0F) << 12) |
                            ((char2 & 0x3F) << 6) |
                            ((char3 & 0x3F) << 0));
                    break;
                default:
                    /* 10xx xxxx,  1111 xxxx */
                    throw new UTFDataFormatException(
                            "malformed input around byte " + count);
            }
        }
        // The number of chars produced may be less than utflen
        return new String(chararr, 0, chararr_count);
View Full Code Here

          result[outputLength++] = (char) c1;
          break;
        case 12:
        case 13:
          if (count + 1 > inputLength)
            throw new UTFDataFormatException();
          c2 = bytearr[count++];
          result[outputLength++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F));
          break;
        case 14:
          if (count + 2 > inputLength)
            throw new UTFDataFormatException();
          c2 = bytearr[count++];
          c3 = bytearr[count++];
          result[outputLength++] = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
          break;
        default:
          throw new UTFDataFormatException();
      }
    }
    return outputLength;
  }
View Full Code Here

            else if ((c & 0x60) == 0x40) // we know the top bit is set here
            {
                // two byte character
                count += 2;
                if (utflen != 0 && count > utflen)
                    throw new UTFDataFormatException();     
                char2 = in.readUnsignedByte();
                if ((char2 & 0xC0) != 0x80)
                    throw new UTFDataFormatException();     
                actualChar = (char)(((c & 0x1F) << 6) | (char2 & 0x3F));
            }
            else if ((c & 0x70) == 0x60) // we know the top bit is set here
            {
                // three byte character
                count += 3;
                if (utflen != 0 && count > utflen)
                    throw new UTFDataFormatException();     
                char2 = in.readUnsignedByte();
                char3 = in.readUnsignedByte();
                if ((c == 0xE0) && (char2 == 0) && (char3 == 0)
                    && (utflen == 0))
                {
                    // we reached the end of a long string,
                    // that was terminated with
                    // (11100000, 00000000, 00000000)
                    break readingLoop;
                }

                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                    throw new UTFDataFormatException();     
               
               
                actualChar = (char)(((c & 0x0F) << 12) |
                                           ((char2 & 0x3F) << 6) |
                                           ((char3 & 0x3F) << 0));
            }
            else {

                throw new UTFDataFormatException();
            }

            str[strlen++] = actualChar;
        }
View Full Code Here

    while (count < utfSize) {
      if ((out[s] = (char) buf[offset + count++]) < '\u0080')
        s++;
      else if (((a = out[s]) & 0xe0) == 0xc0) {
        if (count >= utfSize)
          throw new UTFDataFormatException();
        int b = buf[count++];
        if ((b & 0xC0) != 0x80)
          throw new UTFDataFormatException();
        out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
      } else if ((a & 0xf0) == 0xe0) {
        if (count + 1 >= utfSize)
          throw new UTFDataFormatException();
        int b = buf[count++];
        int c = buf[count++];
        if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80))
          throw new UTFDataFormatException();
        out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
      } else {
        throw new UTFDataFormatException();
      }
    }
    return new String(out, 0, s);
  }
View Full Code Here

        str.append(" of ");
        str.append(count);
        str.append("-byte UTF-8 sequence");

        String message = str.toString();
        throw new UTFDataFormatException(message);

    } // expectedByte(int,int,int)
View Full Code Here

        str.append("-byte UTF-8 sequence (0x");
        str.append(Integer.toHexString(c));
        str.append(')');

        String message = str.toString();
        throw new UTFDataFormatException(message);

    } // invalidByte(int,int,int,int)
View Full Code Here

        StringBuffer str = new StringBuffer();
        str.append("high surrogate bits in UTF-8 sequence must not exceed 0x10 but found 0x");
        str.append(Integer.toHexString(uuuuu));

        String message = str.toString();
        throw new UTFDataFormatException(message);

    } // invalidSurrogate(int)
View Full Code Here

TOP

Related Classes of java.io.UTFDataFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.