package com.qtfreet.musicuu.musicApi.MusicService;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by qtfreet on 2017/2/6.
*/
public class Util {
//将秒数转为时间
public static String secTotime(int seconds) {
int temp;
StringBuilder sb = new StringBuilder();
temp = seconds / 3600;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 / 60;
sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
temp = seconds % 3600 % 60;
sb.append((temp < 10) ? "0" + temp : "" + temp);
return sb.toString();
}
public static String UrlEncode(String str) {
try {
return URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
return "";
}
}
public static String RegexString(String regex, String text) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
return matcher.group(0);
}
return "";
}
public static boolean isNumber(String text) {
return Pattern.matches("^\\d+$", text);
}
public static String getMD5(String sourceStr) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(sourceStr.getBytes());
byte b[] = md.digest();
int i;
StringBuilder buf = new StringBuilder("");
for (byte aB : b) {
i = aB;
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
} catch (NoSuchAlgorithmException e) {
}
return result;
}
}