public static T toObject()

in client-adapter/hbase/src/main/java/com/alibaba/otter/canal/client/adapter/hbase/support/TypeUtil.java [141:188]


    public static <T> T toObject(byte[] bytes, Type type) {
        if (bytes == null) {
            return null;
        }
        Object res = null;
        if (type == Type.STRING || type == Type.DEFAULT) {
            res = Bytes.toString(bytes);
        } else if (type == Type.INTEGER) {
            if (bytes.length == Bytes.SIZEOF_INT) {
                res = Bytes.toInt(bytes);
            }
        } else if (type == Type.LONG) {
            if (bytes.length == Bytes.SIZEOF_LONG) {
                res = Bytes.toLong(bytes);
            }
        } else if (type == Type.SHORT) {
            if (bytes.length == Bytes.SIZEOF_SHORT) {
                res = Bytes.toShort(bytes);
            }
        } else if (type == Type.BYTE) {
            if (bytes.length == Bytes.SIZEOF_BYTE) {
                res = bytes[0];
            }
        } else if (type == Type.FLOAT) {
            if (bytes.length == Bytes.SIZEOF_FLOAT) {
                res = Bytes.toFloat(bytes);
            }
        } else if (type == Type.DOUBLE) {
            if (bytes.length == Bytes.SIZEOF_DOUBLE) {
                res = Bytes.toDouble(bytes);
            }
        } else if (type == Type.BOOLEAN) {
            if (bytes.length == Bytes.SIZEOF_BOOLEAN) {
                res = Bytes.toBoolean(bytes);
            }
        } else if (type == Type.DATE) {
            if (bytes.length == Bytes.SIZEOF_LONG) {
                res = new Date(Bytes.toLong(bytes));
            }
        } else if (type == Type.BYTES) {
            res = bytes;
        } else if (type == Type.BIGDECIMAL) {
            res = Bytes.toBigDecimal(bytes);
        } else {
            throw new IllegalArgumentException("mismatch class type");
        }
        return (T) res;
    }