>();
24 | int size=resList.size();
25 | if(size<=count){ //数据量不足count指定的大小
26 | ret.add(resList);
27 | }else{
28 | int pre=size/count;
29 | int last=size%count;
30 | //前面pre个集合,每个大小都是count个元素
31 | for(int i=0;i itemList=new ArrayList();
33 | for(int j=0;j0){
40 | List itemList=new ArrayList();
41 | for(int i=0;i sysConfig = new HashMap();
15 | private static ConfigUtil instance = null;
16 |
17 | private ConfigUtil() {
18 | }
19 |
20 | private static synchronized void syncInit() {
21 | if (instance == null) {
22 | instance = new ConfigUtil();
23 | }
24 | }
25 |
26 | public static ConfigUtil getInstance() {
27 | if (instance == null) {
28 | syncInit();
29 | }
30 | return instance;
31 | }
32 |
33 | @SuppressWarnings({ "unchecked", "rawtypes" })
34 | public String getConfigVal(String key, String propertiesName) {
35 | if (sysConfig.size() != 0) {
36 | if (sysConfig.get(propertiesName) != null) {
37 | return sysConfig.get(propertiesName).get(key) == null ? "": sysConfig.get(propertiesName).get(key).toString();
38 | }
39 | }
40 | InputStream inputStream = ReadProperties.class.getClassLoader().getResourceAsStream(propertiesName);
41 | Properties p = new Properties();
42 | try {
43 | p.load(inputStream);
44 | } catch (IOException e) {
45 | e.printStackTrace();
46 | }
47 | Map conf = new HashMap();
48 | conf.putAll(p);
49 | sysConfig.put(propertiesName, conf);
50 | return conf.get(key) == null ? "" : conf.get(key).toString();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/ConstantProperties.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | /**
4 | * Created by zhenjie.wang on 2015/8/19.
5 | */
6 | public class ConstantProperties {
7 | public static String DB = "conf/db.properties";
8 | public static String DB_PROP = "conf/dbone.properties";
9 | public static String SOC_PROP = "conf/soc.properties";
10 | public static String COMMON_PROP = "conf/common.properties";
11 | public static String URL_PROP = "conf/url.properties";
12 | public static String URL_SOC_PROP = "conf/url_soc.properties";
13 |
14 | public static String NO_SPLIT_HBASE_TABLE = "dbone.wdd_session,dbone.wdd_sql";
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/DesEncrypt.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import javax.crypto.Cipher;
4 | import javax.crypto.SecretKey;
5 | import javax.crypto.spec.SecretKeySpec;
6 | import java.security.MessageDigest;
7 | import java.security.NoSuchAlgorithmException;
8 | import java.security.Security;
9 |
10 | /**
11 | * Created by ${薛龙虎} on 15/3/16.
12 | */
13 | public class DesEncrypt {
14 | private static final String Algorithm = "DES"; // 定义 加密算法,可用
15 | // DES,DESede,Blowfish
16 | // src为被加密的数据缓冲区(源)
17 | public static byte[] encryptMode(byte[] keybyte, byte[] src) {
18 | try {
19 | // 生成密钥
20 | SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
21 | // 加密
22 | Cipher c1 = Cipher.getInstance(Algorithm);
23 | c1.init(Cipher.ENCRYPT_MODE, deskey);
24 | return c1.doFinal(src);
25 | } catch (NoSuchAlgorithmException e1) {
26 | e1.printStackTrace();
27 | } catch (javax.crypto.NoSuchPaddingException e2) {
28 | e2.printStackTrace();
29 | } catch (Exception e3) {
30 | e3.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | // keybyte为加密密钥,长度为24字节
36 | // src为加密后的缓冲区
37 | public static byte[] decryptMode(byte[] keybyte, byte[] src) {
38 | try {
39 | // 生成密钥
40 | SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
41 | // 解密
42 | Cipher c1 = Cipher.getInstance(Algorithm);
43 | c1.init(Cipher.DECRYPT_MODE, deskey);
44 | return c1.doFinal(src);
45 | } catch (NoSuchAlgorithmException e1) {
46 | e1.printStackTrace();
47 | } catch (javax.crypto.NoSuchPaddingException e2) {
48 | e2.printStackTrace();
49 | } catch (Exception e3) {
50 | e3.printStackTrace();
51 | }
52 | return null;
53 | }
54 |
55 | // 转换成十六进制字符串
56 | public static String byte2hex(byte[] b) {
57 | String hs = "";
58 | String stmp = "";
59 | for (int n = 0; n < b.length; n++) {
60 | stmp = (Integer.toHexString(b[n] & 0XFF));
61 | if (stmp.length() == 1)
62 | hs = hs + "0" + stmp;
63 | else
64 | hs = hs + stmp;
65 | if (n < b.length - 1)
66 | hs = hs + "";
67 | }
68 | return hs.toUpperCase();
69 | }
70 |
71 | // 16 进制 转 2 进制
72 | public static byte[] hex2byte(String hex) throws IllegalArgumentException {
73 | if (hex.length() % 2 != 0) {
74 | throw new IllegalArgumentException();
75 | }
76 | char[] arr = hex.toCharArray();
77 | byte[] b = new byte[hex.length() / 2];
78 | for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) {
79 | String swap = "" + arr[i++] + arr[i];
80 | int byteint = Integer.parseInt(swap, 16) & 0xFF;
81 | b[j] = new Integer(byteint).byteValue();
82 | }
83 | return b;
84 | }
85 |
86 | @SuppressWarnings("unused")
87 | private static byte[] hex2byte(byte[] b) {
88 | if ((b.length % 2) != 0)
89 | throw new IllegalArgumentException("长度不是偶数");
90 | byte[] b2 = new byte[b.length / 2];
91 | for (int n = 0; n < b.length; n += 2) {
92 | String item = new String(b, n, 2);
93 | b2[n / 2] = (byte) Integer.parseInt(item, 16);
94 | }
95 | return b2;
96 | }
97 |
98 | // 加密
99 | @SuppressWarnings("restriction")
100 | public static String Encrypt(String str, byte[] key) {
101 | Security.addProvider(new com.sun.crypto.provider.SunJCE());
102 | byte[] encrypt = encryptMode(key, str.getBytes());
103 | return byte2hex(encrypt);
104 | }
105 |
106 | // 加密
107 | @SuppressWarnings("restriction")
108 | public static byte[] EncryptRetByte(byte[] src, byte[] key) {
109 | Security.addProvider(new com.sun.crypto.provider.SunJCE());
110 | byte[] encrypt = encryptMode(key, src);
111 | return encrypt;
112 | }
113 |
114 | // 解密
115 | @SuppressWarnings("restriction")
116 | public static String Decrypt(String str, byte[] key) {
117 | Security.addProvider(new com.sun.crypto.provider.SunJCE());
118 | byte[] decrypt = decryptMode(key, hex2byte(str));
119 | return new String(decrypt);
120 | }
121 |
122 |
123 | public static String SHA1(String decript) {
124 | try {
125 | MessageDigest digest = MessageDigest.getInstance("SHA1");
126 | digest.update(decript.getBytes());
127 | byte messageDigest[] = digest.digest();
128 | // Create Hex String
129 | StringBuffer hexString = new StringBuffer();
130 | // 字节数组转换为 十六进制 数
131 | for (int i = 0; i < messageDigest.length; i++) {
132 | String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
133 | if (shaHex.length() < 2) {
134 | hexString.append(0);
135 | }
136 | hexString.append(shaHex);
137 | }
138 | return hexString.toString();
139 |
140 | } catch (NoSuchAlgorithmException e) {
141 | e.printStackTrace();
142 | }
143 | return "";
144 | }
145 |
146 | public static void main(String arg[]) {
147 | String str = "jdbc\\:mysql\\://127.0.0.1\\:3306/uu_db?useUnicode=true&characterEncoding=utf8";
148 |
149 | //System.out.println(str);
150 | //String strKey = SyncConstant.JAVA_DESC_KEY;
151 | //String s3 = Encrypt(str, hex2byte(strKey));
152 | //String s4 = Decrypt(s3, hex2byte(strKey));
153 | //System.out.println(s3);
154 | //System.out.println(s4);
155 |
156 | System.out.println(SHA1(str));
157 |
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/EqualValue.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import java.util.List;
4 | import java.util.Set;
5 |
6 | public class EqualValue {
7 |
8 | public static boolean equalLists(List list1, List list2) {
9 | if (list1 == null || list2 == null) {
10 | return false;
11 | }else if(list1.size() != list2.size()){
12 | return false;
13 | }else if(list1.containsAll(list2) && list2.containsAll(list1)){
14 | return true;
15 | }
16 | return false;
17 | }
18 |
19 | public static boolean equalListAndSet(Set set1, List list2) {
20 | if (set1 == null || list2 == null) {
21 | return false;
22 | }else if(set1.size() != list2.size()){
23 | return false;
24 | }else if(set1.containsAll(list2) && list2.containsAll(set1)){
25 | return true;
26 | }
27 | return false;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/IListUtil.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import java.util.List;
4 |
5 | public class IListUtil {
6 |
7 | public static String implode(List strList) {
8 | String res = "";
9 | if (strList == null || strList.size() == 0) {
10 | return res;
11 | }
12 | for (String str : strList) {
13 | res += str + ",";
14 | }
15 | return res.substring(0, res.length() - 1);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/MacOrIpconvert.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | /**
4 | * Created by zhenjie.wang on 2015/8/19.
5 | */
6 | public class MacOrIpconvert {
7 |
8 | //
9 |
10 | public static long ipToLong(String strIp){
11 | if(null==strIp || "".equals(strIp.trim())) return 0;
12 | long[] ip = new long[4];
13 | int p1 = strIp.indexOf(".");
14 | int p2 = strIp.indexOf(".",p1+1);
15 | int p3 = strIp.indexOf(".",p2+1);
16 |
17 | ip[0] = Long.parseLong(strIp.substring(0,p1));
18 | ip[1] = Long.parseLong(strIp.substring(p1+1,p2));
19 | ip[2] = Long.parseLong(strIp.substring(p2+1,p3));
20 | ip[3] = Long.parseLong(strIp.substring(p3+1));
21 |
22 | return (ip[0] << 24)+(ip[1] << 16)+(ip[2] << 8)+ip[3];
23 | }
24 |
25 | //
26 |
27 | public static String longToIp(long longIp){
28 | StringBuffer sb = new StringBuffer("");
29 | sb.append(String.valueOf((longIp >>> 24)));
30 | sb.append(".");
31 | sb.append(String.valueOf((longIp & 0x00FFFFFF) >>> 16));
32 | sb.append(".");
33 | sb.append(String.valueOf((longIp & 0x0000FFFF) >>> 8));
34 | sb.append(".");
35 | sb.append(String.valueOf((longIp & 0x000000FF)));
36 | return sb.toString();
37 | }
38 |
39 | //
40 |
41 | public static long macToString(String mac){
42 | if(null==mac || "".equals(mac.trim())) return 0;
43 | mac = mac.trim();
44 | mac = mac.replace("-","");
45 | mac = mac.replace(":","");
46 | return Long.parseLong(mac,16);
47 | }
48 |
49 | //
50 |
51 | public static String longToMac(long longMac){
52 | String strMac = Long.toHexString(longMac);
53 | while (strMac.length()<12){
54 | strMac = "0"+strMac;
55 | }
56 | String mac = "";
57 | for(int i=0;i>> 4) & 0X0F];
36 | tempArr[1] = digit[b & 0X0F];
37 | String s = new String(tempArr);
38 | return s;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/MyTaskRun.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by babylon on 2016/12/4.
7 | */
8 | public class MyTaskRun implements Runnable {
9 |
10 | private String tablename;
11 | private List puts;
12 |
13 | public MyTaskRun(String tablename, List puts) {
14 | this.tablename = tablename;
15 | this.puts = puts;
16 | }
17 | /**
18 | * 拿到线程池
19 | * */
20 | public ThreadPoolUtil threadPool= ThreadPoolUtil.init();
21 |
22 | @Override
23 | public void run() {
24 | try {
25 | // 开始执行任务
26 | //HBaseUtil.put("logs", puts);
27 | } catch (Exception e) {
28 | e.printStackTrace();
29 | }
30 | // System.out.println("taskNum 线程池中线程数目 :"+threadPool.getExecutor().getPoolSize()+",队列中等待执行的任务数目:"+
31 | // threadPool.getExecutor().getQueue().size()+",已执行玩别的任务数目:"+threadPool.getExecutor().getCompletedTaskCount());
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/RandCodeEnum.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import java.util.Random;
4 | import java.util.Set;
5 | import java.util.TreeSet;
6 |
7 | public enum RandCodeEnum {
8 | /**
9 | * 混合字符串
10 | */
11 | ALL_CHAR("0123456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), // 去除小写的l和o这个两个不容易区分的字符;
12 | /**
13 | * 字符
14 | */
15 | LETTER_CHAR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
16 | /**
17 | * 小写字母
18 | */
19 | LOWER_CHAR("abcdefghijklmnopqrstuvwxyz"),
20 | /**
21 | * 数字
22 | */
23 | NUMBER_CHAR("0123456789"),
24 | /**
25 | * 大写字符
26 | */
27 | UPPER_CHAR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
28 |
29 | /**
30 | * Hbase 离散前缀
31 | */
32 | HBASE_CHAR("123456789ABCDEF");
33 |
34 | /**
35 | * 待生成的字符串
36 | */
37 | private String charStr;
38 |
39 | private RandCodeEnum(final String charStr) {
40 | this.charStr = charStr;
41 | }
42 |
43 | public String generateStr(final int codeLength) {
44 | final StringBuffer sb = new StringBuffer();
45 | final Random random = new Random();
46 | final String sourseStr = getCharStr();
47 |
48 | for (int i = 0; i < codeLength; i++) {
49 | sb.append(sourseStr.charAt(random.nextInt(sourseStr.length())));
50 | }
51 |
52 | return sb.toString();
53 | }
54 |
55 | public String getCharStr() {
56 | return charStr;
57 | }
58 |
59 |
60 | public String[] getHbaseKeys(int pNum, int b, boolean only) {
61 | Set ts = new TreeSet();
62 | int tss = 0;
63 | while ((tss = ts.size()) < pNum) {
64 | if (!only) {
65 | for (int i = 1; i <= b; i++) {
66 | ts.add(RandCodeEnum.HBASE_CHAR.generateStr(i));
67 | }
68 | } else {
69 | ts.add(RandCodeEnum.HBASE_CHAR.generateStr(b));
70 | }
71 | }
72 | return ts.toArray(new String[tss]);
73 | }
74 |
75 | public static void main(String[] args) {
76 | String[] hbaseKeys = RandCodeEnum.HBASE_CHAR.getHbaseKeys(240,2,false);
77 | for (String s : hbaseKeys) {
78 | System.out.println(s);
79 | }
80 | System.out.println(hbaseKeys.length);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/ReadProperties.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.Properties;
6 |
7 | /**
8 | * 文件读取辅助类
9 | */
10 | public class ReadProperties {
11 |
12 | /**
13 | *
14 | * @param fileName
15 | * 文件名
16 | * @param key
17 | * key
18 | * @param defaultValue
19 | * NULL的时候默认返回值
20 | * @return
21 | */
22 | public static Object getPropertyFromConfiguration(String fileName, String key, Object defaultValue) {
23 | InputStream inputStream = ReadProperties.class.getClassLoader()
24 | .getResourceAsStream(fileName);
25 | Properties p = new Properties();
26 | try {
27 | p.load(inputStream);
28 | } catch (IOException e) {
29 |
30 | } finally {
31 | try {
32 | inputStream.close();
33 | } catch (IOException e) {
34 |
35 | }
36 | }
37 | return p.getProperty(key) == null ? defaultValue : p.getProperty(key);
38 | }
39 |
40 | /**
41 | * TODO 读取配置文件的相关项
42 | *
43 | * @param fileName
44 | * @return
45 | */
46 | public static Properties loadConfiguration(String fileName) {
47 | InputStream inputStream = ReadProperties.class.getClassLoader().getResourceAsStream(fileName);
48 | Properties p = new Properties();
49 | try {
50 | p.load(inputStream);
51 | } catch (IOException e) {
52 | } finally {
53 | try {
54 | inputStream.close();
55 | } catch (IOException e) {
56 | }
57 | }
58 | return p;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/adups/util/SocPut.java:
--------------------------------------------------------------------------------
1 | package com.adups.util;
2 |
3 | import org.apache.hadoop.hbase.client.Put;
4 |
5 | import java.util.HashMap;
6 | import java.util.LinkedList;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | /**
11 | * 扩展 Put 类
12 | * Created by babylon on 2016/12/5.
13 | */
14 | public class SocPut extends Put{
15 |
16 | private Map map;
17 | private List