Package java.io

Examples of java.io.UTFDataFormatException


            } else if (a == 0) {
                builder.append('\0');
            } else if (a < 0x80) {
                builder.append((char) a);
            } else if (a < 0xc0) {
                throw new UTFDataFormatException(INVALID_BYTE);
            } else if (a < 0xe0) {
                if (++i < len) {
                    final int b = input.read();
                    if (b == -1) {
                        throw new EOFException("Expected " + (len - i) + " more bytes");
                    } else if ((b & 0xc0) != 0x80) {
                        throw new UTFDataFormatException(INVALID_BYTE);
                    }
                    builder.append((char) ((a & 0x1f) << 6 | b & 0x3f));
                } else {
                    throw new UTFDataFormatException(MALFORMED);
                }
            } else if (a < 0xf0) {
                if (++i < len) {
                    final int b = input.read();
                    if (b == -1) {
                        throw new EOFException("Expected " + (len - i) + " more bytes");
                    } else if ((b & 0xc0) != 0x80) {
                        throw new UTFDataFormatException(INVALID_BYTE);
                    }
                    if (++i < len) {
                        final int c1 = input.read();
                        if (c1 == -1) {
                            throw new EOFException("Expected " + (len - i) + " more bytes");
                        } else if ((c1 & 0xc0) != 0x80) {
                            throw new UTFDataFormatException(INVALID_BYTE);
                        }
                        builder.append((char) ((a & 0x0f) << 12 | (b & 0x3f) << 6 | c1 & 0x3f));
                    } else {
                        throw new UTFDataFormatException(MALFORMED);
                    }
                } else {
                    throw new UTFDataFormatException(MALFORMED);
                }
            } else {
                throw new UTFDataFormatException(INVALID_BYTE);
            }
        }
        return builder.toString();
    }
View Full Code Here


        } else if (a == 0) {
            return -1;
        } else if (a < 0x80) {
            return (char)a;
        } else if (a < 0xc0) {
            throw new UTFDataFormatException(INVALID_BYTE);
        } else if (a < 0xe0) {
            final int b = input.read();
            if (b == -1) {
                throw new EOFException();
            } else if ((b & 0xc0) != 0x80) {
                throw new UTFDataFormatException(INVALID_BYTE);
            }
            return (a & 0x1f) << 6 | b & 0x3f;
        } else if (a < 0xf0) {
            final int b = input.read();
            if (b == -1) {
                throw new EOFException();
            } else if ((b & 0xc0) != 0x80) {
                throw new UTFDataFormatException(INVALID_BYTE);
            }
            final int c = input.read();
            if (c == -1) {
                throw new EOFException();
            } else if ((c & 0xc0) != 0x80) {
                throw new UTFDataFormatException(INVALID_BYTE);
            }
            return (a & 0x0f) << 12 | (b & 0x3f) << 6 | c & 0x3f;
        } else {
            throw new UTFDataFormatException(INVALID_BYTE);
        }
    }
View Full Code Here

                utflen += 2;
            }
        }

        if (utflen > 65535)
            throw new UTFDataFormatException(
              "encoded string too long: " + utflen + " bytes");

        byte[] bytearr=new byte[utflen+2];

        bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
View Full Code Here

    private void expectedByte(int position, int count)
        throws UTFDataFormatException {

        String message = fFormatter.formatMessage(fLocale, "ExpectedByte",
                new Object[] {Integer.toString(position), Integer.toString(count)});
        throw new UTFDataFormatException(message);

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

    private void invalidByte(int position, int count, int c)
        throws UTFDataFormatException {

        String message = fFormatter.formatMessage(fLocale, "InvalidByte",
                new Object [] {Integer.toString(position), Integer.toString(count)});
        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");

        String message = fFormatter.formatMessage(fLocale, "InvalidHighSurrogate",
                new Object[] {Integer.toHexString(uuuuu)});
        throw new UTFDataFormatException(message);

    } // invalidSurrogate(int)
View Full Code Here

        for (int i = 0, n = length; i < n;) {
            byte b = data.get();
            i++;
            if (STRICTLY_CHECK_FORMAT && !ALLOW_NORMAL_UTF8)
                if (b == 0)
                    throw new UTFDataFormatException(
                        "0 byte encountered at location " + (i - 1));
            if (b >= 0) { // < 0x80 unsigned
                // in the range '\001' to '\177'
                result[result_index++] = (char) b;
                continue;
            }
            try {
                byte nb = data.get();
                i++;
                if (b < -32) { // < 0xe0 unsigned
                    // '\000' or in the range '\200' to '\u07FF'
                    char c = result[result_index++] = (char) (((b & 0x1f) << 6) | (nb & 0x3f));
                    if (STRICTLY_CHECK_FORMAT) {
                        if (((b & 0xe0) != 0xc0) || ((nb & 0xc0) != 0x80))
                            throw new UTFDataFormatException(
                                "invalid marker bits for double byte char at location "
                                    + (i - 2));
                        if (c < '\200') {
                            if (!ALLOW_PSEUDO_UTF8 || (c != '\000'))
                                throw new UTFDataFormatException(
                                    "encountered double byte char that should have been single byte at location "
                                        + (i - 2));
                        } else if (c > '\u07FF')
                            throw new UTFDataFormatException(
                                "encountered double byte char that should have been triple byte at location "
                                    + (i - 2));
                    }
                } else {
                    byte nnb = data.get();
                    i++;
                    // in the range '\u0800' to '\uFFFF'
                    char c = result[result_index++] = (char) (((b & 0x0f) << 12) | ((nb & 0x3f) << 6) | (nnb & 0x3f));
                    if (STRICTLY_CHECK_FORMAT) {
                        if (((b & 0xf0) != 0xe0) || ((nb & 0xc0) != 0x80)
                            || ((nnb & 0xc0) != 0x80))
                            throw new UTFDataFormatException(
                                "invalid marker bits for triple byte char at location "
                                    + (i - 3));
                        if (c < '\u0800')
                            throw new UTFDataFormatException(
                                "encountered triple byte char that should have been fewer bytes at location "
                                    + (i - 3));
                    }
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new UTFDataFormatException("unexpected end at location "
                    + i);
            }
        }
        return InternString.internString(new String(result, 0, result_index));
    }
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

    public void writeUTF(String str) throws IOException {

        int len = str.length();

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

        int bytecount = StringConverter.getUTFSize(str);

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

        //
        writeChar(bytecount);
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.