Package java.io

Examples of java.io.UTFDataFormatException


        case 12 :
        case 13 :
          // 110x xxxx   10xx xxxx
          count += 2;
          if (count > utflen)
            throw new UTFDataFormatException();
          char2= readByte();
          if ((char2 & 0xC0) != 0x80)
            throw new UTFDataFormatException();
          str[strlen++]= (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
          break;
        case 14 :
          // 1110 xxxx  10xx xxxx  10xx xxxx
          count += 3;
          if (count > utflen)
            throw new UTFDataFormatException();
          char2= readByte();
          char3= readByte();
          if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
            throw new UTFDataFormatException();
          str[strlen++]= (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
          break;
        default :
          // 10xx xxxx,  1111 xxxx
          throw new UTFDataFormatException();
      }
    }
    if (strlen < utflen)
      System.arraycopy(str, 0, str= new char[strlen], 0, strlen);
    return str;
View Full Code Here


        case 12 :
        case 13 :
          // 110x xxxx   10xx xxxx
          count += 2;
          if (count > utflen)
            throw new UTFDataFormatException();
          char2= buffer[pos++] & 0xFF;
          if ((char2 & 0xC0) != 0x80)
            throw new UTFDataFormatException();
          str[strlen++]= (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
          break;
        case 14 :
          // 1110 xxxx  10xx xxxx  10xx xxxx
          count += 3;
          if (count > utflen)
            throw new UTFDataFormatException();
          char2= buffer[pos++] & 0xFF;
          char3= buffer[pos++] & 0xFF;
          if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
            throw new UTFDataFormatException();
          str[strlen++]= (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
          break;
        default :
          // 10xx xxxx,  1111 xxxx
          throw new UTFDataFormatException();
      }
    }
    if (strlen < utflen)
      System.arraycopy(str, 0, str= new char[strlen], 0, strlen);
    return str;
View Full Code Here

                numread++;
                result[numchars++] = (char) c1;
            } else if (test == 12 || test == 13) { // two bytes
                numread += 2;
                if (numread > numbytes)
                    throw new UTFDataFormatException();
                c2 = readUnsignedByte();
                if ((c2 & 0xC0) != 0x80)
                    throw new UTFDataFormatException();
                result[numchars++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F));
            } else if (test == 14) { // three bytes
                numread += 3;
                if (numread > numbytes)
                    throw new UTFDataFormatException();
                c2 = readUnsignedByte();
                c3 = readUnsignedByte();
                if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) {
                    throw new UTFDataFormatException();
                }
                result[numchars++] = (char) (((c1 & 0x0F) << 12)
                        | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
            } else { // malformed
                throw new UTFDataFormatException();
            }
        } // end while
        return new String(result, 0, numchars);
    }
View Full Code Here

                    /* 110x xxxx   10xx xxxx*/
                    count += 2;

                    if (count > length) {
                        throw new UTFDataFormatException();
                    }

                    char2 = (int) bytearr[offset + count - 1];

                    if ((char2 & 0xC0) != 0x80) {
                        throw new UTFDataFormatException();
                    }

                    buf[bcount++] = (char) (((c & 0x1F) << 6)
                                            | (char2 & 0x3F));
                    break;

                case 14 :

                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
                    count += 3;

                    if (count > length) {
                        throw new UTFDataFormatException();
                    }

                    char2 = (int) bytearr[offset + count - 2];
                    char3 = (int) bytearr[offset + count - 1];

                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
                        throw new UTFDataFormatException();
                    }

                    buf[bcount++] = (char) (((c & 0x0F) << 12)
                                            | ((char2 & 0x3F) << 6)
                                            | ((char3 & 0x3F) << 0));
                    break;

                default :

                    /* 10xx xxxx,  1111 xxxx */
                    throw new UTFDataFormatException();
            }
        }

        // The number of chars produced may be less than length
        return new String(buf, 0, bcount);
View Full Code Here

    public void writeUTF(String str) throws IOException {

        int len = str.length();

        if (len > 0xffff) {
            throw new UTFDataFormatException();
        }

        ensureRoom(len * 3 + 2);

        //
        int initpos = count;

        count += 2;

        StringConverter.stringToUTFBytes(str, this);

        int bytecount = count - initpos - 2;

        if (bytecount > 0xffff) {
            count = initpos;

            throw new UTFDataFormatException();
        }

        buffer[initpos++] = (byte) (bytecount >>> 8);
        buffer[initpos]   = (byte) bytecount;
    }
View Full Code Here

        bytes += 3;
      }
    }
               
    if (bytes > 65535)
      throw new UTFDataFormatException("String is to long");
               
    writeShort((short)bytes);
               
    for (int i = 0; i < str.length(); i++) {
      if (str.charAt(i) >= '\u0001' && str.charAt(i) <= '\u007f') {
View Full Code Here

        case 8: // '\b'
        case 9: // '\t'
        case 10: // '\n'
        case 11: // '\013'
        default:
          throw new UTFDataFormatException("invalid first byte "
              + Integer.toBinaryString(firstByte));
      }
      for (int j = 1; j <= extraBytes; j++) {
        int nextByte = getByteOfCurrentChar(j);
        if (nextByte == -2)
          return count;
        if (nextByte == -1)
          throw new UTFDataFormatException("partial character");
        if ((nextByte & 0xc0) != 128)
          throw new UTFDataFormatException("invalid byte "
              + Integer.toBinaryString(nextByte));
        currentChar = (currentChar << 6) + (nextByte & 0x3f);
      }

      cbuf[off + count] = (char) currentChar;
View Full Code Here

                bytesSkipped++;
            } else if ((c & 0x60) == 0x40) { // 7th bit set, 6th bit unset
                // Found char of two byte width.
                if (skipPersistent(in, 1L) != 1L) {
                    // No second byte present.
                    throw new UTFDataFormatException(
                        "Second byte in two byte character missing; byte pos " +
                        bytesSkipped + " ; char pos " + charsSkipped);
                }
                bytesSkipped += 2;
            } else if ((c & 0x70) == 0x60) { // 7th and 6th bit set, 5th unset
                // Found char of three byte width.
                int skipped = 0;
                if (c == 0xe0) {
                    // Check for Derby EOF marker.
                    int c1 = in.read();
                    int c2 = in.read();
                    if (c1 == 0x00 && c2 == 0x00) {
                        // Found Derby EOF marker, exit loop.
                        charsSkipped--; // Compensate by subtracting one.
                        break;
                    }
                    // Do some rudimentary error checking.
                    // Allow everything except EOF, which is the same as done in
                    // normal processing (skipPersistent below).
                    if (c1 != -1 && c2 != -1) {
                        skipped = 2;
                    }
                } else {
                    skipped = (int)skipPersistent(in, 2L);
                }
                if (skipped != 2) {
                    // No second or third byte present
                    throw new UTFDataFormatException(
                        "Second or third byte in three byte character " +
                        "missing; byte pos " + bytesSkipped + " ; char pos " +
                        charsSkipped);
                }
                bytesSkipped += 3;
            } else {
                throw new UTFDataFormatException(
                    "Invalid UTF-8 encoding encountered: (decimal) " + c);
            }
        }
        // We don't close the stream, since it might be reused. One example of
        // this is use of Resetable streams.
View Full Code Here

      }
      else if ((char1 & 0x60) == 0x40) // we know the top bit is set here
      {
        // two byte character, make sure read of next byte is in bounds.
                if (pos >= end_pos)
          throw new UTFDataFormatException();     

                char2 = (data[pos++] & 0xff);

        if ((char2 & 0xC0) != 0x80)
          throw new UTFDataFormatException();     

        str[strlen++] = (char)(((char1 & 0x1F) << 6) | (char2 & 0x3F));
      }
      else if ((char1 & 0x70) == 0x60) // we know the top bit is set here
      {
        // three byte character

        // 3 byte character, make sure read of next 2 bytes in bounds.
                if (pos + 1 >= end_pos)
          throw new UTFDataFormatException();     

                char2 = (data[pos++] & 0xff);
                char3 = (data[pos++] & 0xff);

        if ((char1 == 0xE0) &&
                    (char2 ==    0) &&
                    (char3 ==    0) &&
                    (utflen == 0))
        {
          // we reached the end of a long string,
          // that was terminated with
          // (11100000, 00000000, 00000000)
                    break;
        }
                else if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
                {
          throw new UTFDataFormatException();     
                }
                else
                {
                    str[strlen++] = (char)
                        (((char1 & 0x0F) << 12) |
                         ((char2 & 0x3F) <<  6) |
                         ((char3 & 0x3F) <<  0));
                }
      }
      else
            {
        throw new UTFDataFormatException();
      }

    }

        // update global on successful read exit.
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

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.