| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | /** |
| | | * 16 |
| | | */ |
| | |
| | | * @return: int |
| | | * @description: 十六进制转十进制 |
| | | */ |
| | | public static int HexToInt(String content){ |
| | | int number=0; |
| | | String [] HighLetter = {"A","B","C","D","E","F"}; |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | for(int i = 0;i <= 9;i++){ |
| | | map.put(i+"",i); |
| | | } |
| | | for(int j= 10;j<HighLetter.length+10;j++){ |
| | | map.put(HighLetter[j-10],j); |
| | | } |
| | | String[]str = new String[content.length()]; |
| | | for(int i = 0; i < str.length; i++){ |
| | | str[i] = content.substring(i,i+1); |
| | | } |
| | | for(int i = 0; i < str.length; i++){ |
| | | number += map.get(str[i])*Math.pow(16,str.length-1-i); |
| | | } |
| | | return number; |
| | | } |
| | | // public static int HexToInt(String content){ |
| | | // int number=0; |
| | | // String [] HighLetter = {"A","B","C","D","E","F"}; |
| | | // Map<String,Integer> map = new HashMap<>(); |
| | | // for(int i = 0;i <= 9;i++){ |
| | | // map.put(i+"",i); |
| | | // } |
| | | // for(int j= 10;j<HighLetter.length+10;j++){ |
| | | // map.put(HighLetter[j-10],j); |
| | | // } |
| | | // String[]str = new String[content.length()]; |
| | | // for(int i = 0; i < str.length; i++){ |
| | | // str[i] = content.substring(i,i+1); |
| | | // } |
| | | // for(int i = 0; i < str.length; i++){ |
| | | // number += map.get(str[i])*Math.pow(16,str.length-1-i); |
| | | // } |
| | | // return number; |
| | | // } |
| | | |
| | | |
| | | /** |
| | |
| | | String sTemp; |
| | | for (int i = 0; i < bArray.length; i++) { |
| | | sTemp = Integer.toHexString(0xFF & bArray[i]); |
| | | if (sTemp.length() < 2) |
| | | if (sTemp.length() < 2) { |
| | | sb.append(0); |
| | | } |
| | | sb.append(sTemp.toLowerCase()); |
| | | } |
| | | return sb.toString(); |
| | |
| | | StringBuffer sb = new StringBuffer(); |
| | | String sTemp; |
| | | sTemp = Integer.toHexString(0xFF & b); |
| | | if (sTemp.length() < 2) |
| | | if (sTemp.length() < 2) { |
| | | sb.append(0); |
| | | } |
| | | sb.append(sTemp.toLowerCase()); |
| | | return sb.toString(); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public static byte[] readInputStream(InputStream inputStream) { |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | |
| | | if (inputStream != null) { |
| | | try { |
| | | byte[] buffer = new byte[91]; |
| | | int counts; |
| | | while ((counts = inputStream.read(buffer, 0, buffer.length)) > 0) { |
| | | byteArrayOutputStream.write(buffer, 0, counts); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }/* finally { |
| | | if (byteArrayOutputStream != null) { |
| | | try { |
| | | byteArrayOutputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }*/ |
| | | } |
| | | return byteArrayOutputStream.toByteArray(); |
| | | } |
| | | // public static byte[] readInputStream(InputStream inputStream) { |
| | | // ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | // |
| | | // if (inputStream != null) { |
| | | // try { |
| | | // byte[] buffer = new byte[91]; |
| | | // int counts; |
| | | // while ((counts = inputStream.read(buffer, 0, buffer.length)) > 0) { |
| | | // byteArrayOutputStream.write(buffer, 0, counts); |
| | | // } |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // }/* finally { |
| | | // if (byteArrayOutputStream != null) { |
| | | // try { |
| | | // byteArrayOutputStream.close(); |
| | | // } catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }*/ |
| | | // } |
| | | // return byteArrayOutputStream.toByteArray(); |
| | | // } |
| | | |
| | | // br = new BufferedReader(new InputStreamReader(inputStream)); |
| | | // byteArrayOutputStream = new ByteArrayOutputStream(); |