⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tools.java

📁 移动empp网关
💻 JAVA
字号:
package cn.madhouse.gateway.empp.util;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;public class Tools {	private static String HexCode[] = { "0", "1", "2", "3", "4", "5", "6", "7",			"8", "9", "a", "b", "c", "d", "e", "f" };	private Tools() {	}	public static String byteToHexString(byte b) {		int n = b;		if (n < 0)			n = 256 + n;		int d1 = n / 16;		int d2 = n % 16;		return HexCode[d1] + HexCode[d2];	}	public static String byteArrayToHexString(byte b[]) {		String result = "";		for (int i = 0; i < b.length; i++)			result = result + byteToHexString(b[i]);		return result;	}	public static int byte2int(byte b[], int offset) {		return b[offset + 3] & 0xff | (b[offset + 2] & 0xff) << 8				| (b[offset + 1] & 0xff) << 16 | (b[offset] & 0xff) << 24;	}	public static int byte2int(byte b[]) {		return b[3] & 0xff | (b[2] & 0xff) << 8 | (b[1] & 0xff) << 16				| (b[0] & 0xff) << 24;	}	public static long byte2long(byte b[]) {		return (long) b[7] & (long) 255 | ((long) b[6] & (long) 255) << 8				| ((long) b[5] & (long) 255) << 16				| ((long) b[4] & (long) 255) << 24				| ((long) b[3] & (long) 255) << 32				| ((long) b[2] & (long) 255) << 40				| ((long) b[1] & (long) 255) << 48 | (long) b[0] << 56;	}	public static long byte2long(byte b[], int offset) {		return (long) b[offset + 7] & (long) 255				| ((long) b[offset + 6] & (long) 255) << 8				| ((long) b[offset + 5] & (long) 255) << 16				| ((long) b[offset + 4] & (long) 255) << 24				| ((long) b[offset + 3] & (long) 255) << 32				| ((long) b[offset + 2] & (long) 255) << 40				| ((long) b[offset + 1] & (long) 255) << 48				| (long) b[offset] << 56;	}	public static byte[] int2byte(int n) {		byte b[] = new byte[4];		b[0] = (byte) (n >> 24);		b[1] = (byte) (n >> 16);		b[2] = (byte) (n >> 8);		b[3] = (byte) n;		return b;	}	/**	 * n 为待转数据,buf[]为转换后的数据,offset为buf[]中转换的起始点 转换后数据从低到高位	 */	public static void int2byte(int n, byte buf[], int offset) {		buf[offset] = (byte) (n >> 24);		buf[offset + 1] = (byte) (n >> 16);		buf[offset + 2] = (byte) (n >> 8);		buf[offset + 3] = (byte) n;	}	public static byte[] short2byte(int n) {		byte b[] = new byte[2];		b[0] = (byte) (n >> 8);		b[1] = (byte) n;		return b;	}	public static void short2byte(int n, byte buf[], int offset) {		buf[offset] = (byte) (n >> 8);		buf[offset + 1] = (byte) n;	}	public static byte[] long2byte(long n) {		byte b[] = new byte[8];		b[0] = (byte) (int) (n >> 56);		b[1] = (byte) (int) (n >> 48);		b[2] = (byte) (int) (n >> 40);		b[3] = (byte) (int) (n >> 32);		b[4] = (byte) (int) (n >> 24);		b[5] = (byte) (int) (n >> 16);		b[6] = (byte) (int) (n >> 8);		b[7] = (byte) (int) n;		return b;	}	public static void long2byte(long n, byte buf[], int offset) {		buf[offset] = (byte) (int) (n >> 56);		buf[offset + 1] = (byte) (int) (n >> 48);		buf[offset + 2] = (byte) (int) (n >> 40);		buf[offset + 3] = (byte) (int) (n >> 32);		buf[offset + 4] = (byte) (int) (n >> 24);		buf[offset + 5] = (byte) (int) (n >> 16);		buf[offset + 6] = (byte) (int) (n >> 8);		buf[offset + 7] = (byte) (int) n;	}	public static boolean checkMobile(String sMobile) {		String sF6 = "", sB7 = "", sF2 = "";		if (sMobile == null)			return false;		if (sMobile.length() != 11)			return false;		sF6 = sMobile.substring(0, 7);		sF2 = sMobile.substring(0, 2);		sB7 = sMobile.substring(7);		try {			int iT = Integer.valueOf(sF6).intValue();			iT = Integer.valueOf(sB7).intValue();			if (sF2.equals("13"))				return true;			else				return false;		} catch (Exception ex) {			return false;		}	}		public static byte[] md5(byte[] arg) {		byte[] bytes = null;		try {			MessageDigest md = MessageDigest.getInstance("MD5");			md.update(arg);			bytes = md.digest();		} catch (NoSuchAlgorithmException e) {			e.printStackTrace();		}		return bytes;	}		public static String md5(String arg) {		StringBuilder sb = new StringBuilder();		try {			MessageDigest md = MessageDigest.getInstance("MD5");			md.update(arg.getBytes());			byte[] bytes = md.digest();			for(byte b:bytes){				sb.append(Integer.toHexString((int)b&0xff));			}		} catch (NoSuchAlgorithmException e) {			e.printStackTrace();		}		return sb.toString();	}		public static byte[] trimTail(byte[] arg) {		int tag = arg.length-1;		while (tag>=0 && arg[tag]==(byte)0) {			tag--;		}		byte[] b = new byte[tag+1];		System.arraycopy(arg,0,b,0,b.length);		return b;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -