这是几个JAVA常用到的方法

 /**
     * 验证ip是否合法<pre name="code" class="java"> /**
     *
     * @function byte转String
     * @param bytes
     * @return String
     */
    public String bytes2hex03(byte[] bytes)
    {
        final String HEX = "0123456789abcdef";
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        for (byte b : bytes)
        {

            sb.append(HEX.charAt((b >> 4) & 0x0f));

            sb.append(HEX.charAt(b & 0x0f));
        }

    return sb.toString();
}


    /**
     *
     * @function String转byte
     * @param hexString
     * @return
     */
    private static byte[] HexStringToByte(String hexString)
    {
        if (hexString == null || hexString.equals(""))
        {
            return null;
        }
        hexString = hexString.toUpperCase();
        int length = hexString.length() / 2;
        char[] hexChars = hexString.toCharArray();
        byte[] returnByte = new byte[length];
        for (int i = 0; i < length; i++)
        {
            int pos = i * 2;
            returnByte[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
        }
        return returnByte;
    }

    private static byte charToByte(char c)
    {
        return (byte) "0123456789ABCDEF".indexOf(c);
    }

* * @param text * ip地址 * @return 验证信息 */ public boolean ipCheck(String text) { boolean isCorrect = false; if (text != null && !text.isEmpty()) { // 定义正则表达式 String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$"; // 判断ip地址是否与正则表达式匹配 if (text.matches(regex)) { // 返回判断信息 isCorrect = true; } else { // 返回判断信息 isCorrect = false; } } // 返回判断信息 return isCorrect; }
 

/**
     * @fuction 输入流转化为字符串
     * @param tInputStream
     * @return String
     */
    public static String getStreamString(InputStream tInputStream) {
        if (tInputStream != null) {
            try {
                BufferedReader tBufferedReader = new BufferedReader(new InputStreamReader(tInputStream));
                StringBuffer tStringBuffer = new StringBuffer();
                String sTempOneLine = new String("");
                while ((sTempOneLine = tBufferedReader.readLine()) != null) {
                    tStringBuffer.append(sTempOneLine);
                }
                return tStringBuffer.toString();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return null;
    }

 /**范类转换*/
    public static Class getGenericSuperclass(Class entity) {
        ParameterizedType type = (ParameterizedType) entity.getGenericSuperclass();
        Class entityClass = (Class) type.getActualTypeArguments()[0];
        return entityClass;
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值