Search in sources :

Example 6 with UTFDataFormatException

use of java.io.UTFDataFormatException in project dex2jar by pxb1988.

the class Mutf8 method decode.

/**
     * Decodes bytes from {@code in} into {@code sb} until a delimiter 0x00 is encountered. Returns a new string
     * containing the decoded characters.
     */
public static String decode(ByteBuffer in, StringBuilder sb) throws UTFDataFormatException {
    while (true) {
        char a = (char) (in.get() & 0xff);
        if (a == 0) {
            return sb.toString();
        }
        if (a < '€') {
            sb.append(a);
        } else if ((a & 0xe0) == 0xc0) {
            int b = in.get() & 0xff;
            if ((b & 0xC0) != 0x80) {
                throw new UTFDataFormatException("bad second byte");
            }
            sb.append((char) (((a & 0x1F) << 6) | (b & 0x3F)));
        } else if ((a & 0xf0) == 0xe0) {
            int b = in.get() & 0xff;
            int c = in.get() & 0xff;
            if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                throw new UTFDataFormatException("bad second or third byte");
            }
            sb.append((char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)));
        } else {
            throw new UTFDataFormatException("bad byte");
        }
    }
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException)

Example 7 with UTFDataFormatException

use of java.io.UTFDataFormatException in project buck by facebook.

the class Mutf8 method decode.

/**
     * Decodes bytes from {@code in} into {@code out} until a delimiter 0x00 is
     * encountered. Returns a new string containing the decoded characters.
     */
public static String decode(ByteInput in, char[] out) throws UTFDataFormatException {
    int s = 0;
    while (true) {
        char a = (char) (in.readByte() & 0xff);
        if (a == 0) {
            return new String(out, 0, s);
        }
        out[s] = a;
        if (a < '€') {
            s++;
        } else if ((a & 0xe0) == 0xc0) {
            int b = in.readByte() & 0xff;
            if ((b & 0xC0) != 0x80) {
                throw new UTFDataFormatException("bad second byte");
            }
            out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
        } else if ((a & 0xf0) == 0xe0) {
            int b = in.readByte() & 0xff;
            int c = in.readByte() & 0xff;
            if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                throw new UTFDataFormatException("bad second or third byte");
            }
            out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
        } else {
            throw new UTFDataFormatException("bad byte");
        }
    }
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException)

Example 8 with UTFDataFormatException

use of java.io.UTFDataFormatException in project j2objc by google.

the class ModifiedUtf8 method decode.

/**
     * Decodes a byte array containing <i>modified UTF-8</i> bytes into a string.
     *
     * <p>Note that although this method decodes the (supposedly impossible) zero byte to U+0000,
     * that's what the RI does too.
     */
public static String decode(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatException {
    int count = 0, s = 0, a;
    while (count < utfSize) {
        if ((out[s] = (char) in[offset + count++]) < '€') {
            s++;
        } else if (((a = out[s]) & 0xe0) == 0xc0) {
            if (count >= utfSize) {
                throw new UTFDataFormatException("bad second byte at " + count);
            }
            int b = in[offset + count++];
            if ((b & 0xC0) != 0x80) {
                throw new UTFDataFormatException("bad second byte at " + (count - 1));
            }
            out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
        } else if ((a & 0xf0) == 0xe0) {
            if (count + 1 >= utfSize) {
                throw new UTFDataFormatException("bad third byte at " + (count + 1));
            }
            int b = in[offset + count++];
            int c = in[offset + count++];
            if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                throw new UTFDataFormatException("bad second or third byte at " + (count - 2));
            }
            out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
        } else {
            throw new UTFDataFormatException("bad byte at " + (count - 1));
        }
    }
    return new String(out, 0, s);
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException)

Example 9 with UTFDataFormatException

use of java.io.UTFDataFormatException in project XobotOS by xamarin.

the class ModifiedUtf8 method decode.

/**
     * Decodes a byte array containing <i>modified UTF-8</i> bytes into a string.
     *
     * <p>Note that although this method decodes the (supposedly impossible) zero byte to U+0000,
     * that's what the RI does too.
     */
public static String decode(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatException {
    int count = 0, s = 0, a;
    while (count < utfSize) {
        if ((out[s] = (char) in[offset + count++]) < '€') {
            s++;
        } else if (((a = out[s]) & 0xe0) == 0xc0) {
            if (count >= utfSize) {
                throw new UTFDataFormatException("bad second byte at " + count);
            }
            int b = in[offset + count++];
            if ((b & 0xC0) != 0x80) {
                throw new UTFDataFormatException("bad second byte at " + (count - 1));
            }
            out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
        } else if ((a & 0xf0) == 0xe0) {
            if (count + 1 >= utfSize) {
                throw new UTFDataFormatException("bad third byte at " + (count + 1));
            }
            int b = in[offset + count++];
            int c = in[offset + count++];
            if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                throw new UTFDataFormatException("bad second or third byte at " + (count - 2));
            }
            out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
        } else {
            throw new UTFDataFormatException("bad byte at " + (count - 1));
        }
    }
    return new String(out, 0, s);
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException)

Example 10 with UTFDataFormatException

use of java.io.UTFDataFormatException in project asterixdb by apache.

the class NonSyncDataInputBuffer method convertUTF8WithBuf.

public static String convertUTF8WithBuf(byte[] buf, char[] out, int offset, int utfSize) throws UTFDataFormatException {
    int count = 0, s = 0, a;
    while (count < utfSize) {
        if ((out[s] = (char) buf[offset + count++]) < '€') {
            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);
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException)

Aggregations

UTFDataFormatException (java.io.UTFDataFormatException)23 IOException (java.io.IOException)2 DexException (com.tencent.tinker.android.dex.DexException)1 StringData (com.tencent.tinker.android.dex.StringData)1 DataOutput (java.io.DataOutput)1 File (java.io.File)1 ObjectStreamClass (java.io.ObjectStreamClass)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1