/**
* 验证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;
}