Package java.io

Examples of java.io.UTFDataFormatException


            c = ch[i];
            utflen += (c >= 0x0001 && c <= 0x007F) ? 1 : (c > 0x07FF) ? 3 : 2;
        }
       
        if (utflen > 65535) {
            throw new UTFDataFormatException();
        }
       
        byte[] bytearr = new byte[utflen + 2];
        bytearr[count++] = (byte)(utflen >>> 8 & 0xFF);
        bytearr[count++] = (byte)(utflen >>> 0 & 0xFF);
View Full Code Here


                char3 = (int)bytearr[count - 1];
                str[i++] = (char)((c & 0x0F) << 12 | (char2 & 0x3F) << 6 | (char3 & 0x3F) << 0);
                break;
            default:
                /* 10xx xxxx,  1111 xxxx */
                throw new UTFDataFormatException();
            }
        }
       
        if (i < len) {
            char[] newstr = new char[i];
View Full Code Here

            } else {
                encodedsize += 2;
            }
        }
        if (encodedsize > 65535) {
            throw new UTFDataFormatException("encoded string too long: " + encodedsize + " bytes");
        }
        ensureEnoughBuffer(pos + encodedsize + 2);
        writeShort(encodedsize);
        for (int i = 0; i < strlen; i++) {
            int charValue = str.charAt(i);
View Full Code Here

        while (pos < endPos) {
            if ((characters[count] = (char) buf[pos++]) < '\u0080')
                count++;
            else if (((a = characters[count]) & 0xE0) == 0xC0) {
                if (pos >= endPos) {
                    throw new UTFDataFormatException("bad string");
                }
                int b = buf[pos++];
                if ((b & 0xC0) != 0x80) {
                    throw new UTFDataFormatException("bad string");
                }
                characters[count++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
            } else if ((a & 0xf0) == 0xe0) {
                if (pos + 1 >= endPos) {
                    throw new UTFDataFormatException("bad string");
                }
                int b = buf[pos++];
                int c = buf[pos++];
                if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                    throw new UTFDataFormatException("bad string");
                }
                characters[count++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
            } else {
                throw new UTFDataFormatException("bad string");
            }
        }
        return new String(characters, 0, count);
    }
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(Msg.getString("K0062",
              count));
        int b = buf[count++];
        if ((b & 0xC0) != 0x80)
          throw new UTFDataFormatException(Msg.getString("K0062",
              (count - 1)));
        out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
      } else if ((a & 0xf0) == 0xe0) {
        if (count + 1 >= utfSize)
          throw new UTFDataFormatException(Msg.getString("K0063",
              (count + 1)));
        int b = buf[count++];
        int c = buf[count++];
        if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80))
          throw new UTFDataFormatException(Msg.getString("K0064",
              (count - 2)));
        out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
      } else {
        throw new UTFDataFormatException(Msg.getString("K0065",
            (count - 1)));
      }
    }
    return new String(out, 0, s);
  }
View Full Code Here

            } else {
                encodedsize += 2;
            }
        }
        if (encodedsize > 65535) {
            throw new UTFDataFormatException("encoded string too long: " + encodedsize + " bytes");
        }
        ensureEnoughBuffer(pos + encodedsize + 2);
        writeShort(encodedsize);
        int i = 0;
        for (i = 0; i < strlen; i++) {
View Full Code Here

                break;
            case 12:
            case 13:
                pos += 2;
                if (pos > length) {
                    throw new UTFDataFormatException("bad string");
                }
                c2 = (int)buf[pos - 1];
                if ((c2 & 0xC0) != 0x80) {
                    throw new UTFDataFormatException("bad string");
                }
                characters[count++] = (char)(((c & 0x1F) << 6) | (c2 & 0x3F));
                break;
            case 14:
                pos += 3;
                if (pos > length) {
                    throw new UTFDataFormatException("bad string");
                }
                c2 = (int)buf[pos - 2];
                c3 = (int)buf[pos - 1];
                if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) {
                    throw new UTFDataFormatException("bad string");
                }
                characters[count++] = (char)(((c & 0x0F) << 12) | ((c2 & 0x3F) << 6) | ((c3 & 0x3F) << 0));
                break;
            default:
                throw new UTFDataFormatException("bad string");
            }
        }
        return new String(characters, 0, count);
    }
View Full Code Here

                case 12:
                case 13:
                    /* 110x xxxx 10xx xxxx */
                    count += 2;
                    if (count > utflen) {
                        throw new UTFDataFormatException();
                    }
                    char2 = bytearr[count - 1];
                    if ((char2 & 0xC0) != 0x80) {
                        throw new UTFDataFormatException();
                    }
                    str.append((char)(((c & 0x1F) << 6) | (char2 & 0x3F)));
                    break;
                case 14:
                    /* 1110 xxxx 10xx xxxx 10xx xxxx */
                    count += 3;
                    if (count > utflen) {
                        throw new UTFDataFormatException();
                    }
                    char2 = bytearr[count - 2]; // TODO diff: Sun code
                    char3 = bytearr[count - 1]; // TODO diff: Sun code
                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
                        throw new UTFDataFormatException();
                    }
                    str.append((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 utflen
            return new String(str);
        } else {
View Full Code Here

    public void testParserThrowsUTFDataFormatException()
      throws SAXException, IOException {
       
        XMLReader parser = XMLReaderFactory.createXMLReader(
          "org.apache.xerces.parsers.SAXParser");
        Exception cause = new UTFDataFormatException();
        XMLFilter filter = new ExceptionTester(cause);
        filter.setParent(parser);
        Builder builder = new Builder(filter);
       
        try {
View Full Code Here

            }else{
                encodedsize+=2;
            }
        }
        if(encodedsize>65535)
            throw new UTFDataFormatException("encoded string too long: "+encodedsize+" bytes");
        ensureEnoughBuffer(pos + encodedsize+2);
        writeShort(encodedsize);
        int i=0;
        for(i=0;i<strlen;i++){
            c=str.charAt(i);
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.