// Path: src/main/java/com/mpush/util/IOUtils.java
// public final class IOUtils {
// 
//     public static void close(Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (Exception e) {
//             }
//         }
//     }
// 
//     public static byte[] compress(byte[] data) {
//         ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length / 4);
//         DeflaterOutputStream zipOut = new DeflaterOutputStream(byteStream);
//         try {
//             zipOut.write(data);
//             zipOut.finish();
//             zipOut.close();
//         } catch (IOException e) {
//             return Constants.EMPTY_BYTES;
//         } finally {
//             close(zipOut);
//         }
//         return byteStream.toByteArray();
//     }
// 
//     public static byte[] uncompress(byte[] data) {
//         InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
//         ByteArrayOutputStream out = new ByteArrayOutputStream(data.length * 4);
//         byte[] buffer = new byte[1024];
//         int length;
//         try {
//             while ((length = in.read(buffer)) != -1) {
//                 out.write(buffer, 0, length);
//             }
//         } catch (IOException e) {
//             return Constants.EMPTY_BYTES;
//         } finally {
//             close(in);
//         }
//         return out.toByteArray();
//     }
// }
// 
// Path: src/main/java/com/mpush/api/Constants.java
// public interface Constants {
//     Charset UTF_8 = Charset.forName("UTF-8");
// 
//     int DEFAULT_SO_TIMEOUT = 1000 * 3;//客户端连接超时时间
// 
//     int DEFAULT_WRITE_TIMEOUT = 1000 * 10;//10s默认packet写超时
// 
//     byte[] EMPTY_BYTES = new byte[0];
// 
//     int DEF_HEARTBEAT = 4 * 60 * 1000;//5min 默认心跳时间
// 
//     int DEF_COMPRESS_LIMIT = 1024;//1k 启用压缩阈值
// 
//     String DEF_OS_NAME = "android";//客户端OS
// 
//     int MAX_RESTART_COUNT = 10;//客户端重连次数超过该值，重连线程休眠10min后再重试
//     int MAX_TOTAL_RESTART_COUNT = 1000;//客户端重连次数超过该值，将不再尝试重连
// 
//     int MAX_HB_TIMEOUT_COUNT = 2;
// 
//     String HTTP_HEAD_READ_TIMEOUT = "readTimeout";
// }
// 
// Path: src/main/java/com/mpush/util/Strings.java
// public final class Strings {
//     public static final String EMPTY = "";
// 
//     public static boolean isBlank(CharSequence text) {
//         if (text == null || text.length() == 0) return true;
//         for (int i = 0, L = text.length(); i < L; i++) {
//             if (!Character.isWhitespace(text.charAt(i))) return false;
//         }
//         return true;
//     }
// 
//     public static long toLong(String text, long defaultVal) {
//         try {
//             return Long.parseLong(text);
//         } catch (NumberFormatException e) {
//         }
//         return defaultVal;
//     }
// 
//     public static int toInt(String text, int defaultVal) {
//         try {
//             return Integer.parseInt(text);
//         } catch (NumberFormatException e) {
//         }
//         return defaultVal;
//     }
// }


import java.security.MessageDigest;
import com.mpush.util.IOUtils;
import com.mpush.api.Constants;
import com.mpush.util.Strings;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
/*
 * (C) Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     ohun@live.cn (夜色)
 */

package com.mpush.util.crypto;





/**
 * Created by ohun on 2015/12/25.
 *
 * @author ohun@live.cn (夜色)
 */
public final class MD5Utils {
    public static String encrypt(File file) {
        InputStream in = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            in = new FileInputStream(file);
            byte[] buffer = new byte[10240];//10k
            int readLen;
            while ((readLen = in.read(buffer)) != -1) {
                digest.update(buffer, 0, readLen);
            }
            return toHex(digest.digest());
        } catch (Exception e) {
// Path: src/main/java/com/mpush/util/IOUtils.java
// public final class IOUtils {
// 
//     public static void close(Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (Exception e) {
//             }
//         }
//     }
// 
//     public static byte[] compress(byte[] data) {
//         ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length / 4);
//         DeflaterOutputStream zipOut = new DeflaterOutputStream(byteStream);
//         try {
//             zipOut.write(data);
//             zipOut.finish();
//             zipOut.close();
//         } catch (IOException e) {
//             return Constants.EMPTY_BYTES;
//         } finally {
//             close(zipOut);
//         }
//         return byteStream.toByteArray();
//     }
// 
//     public static byte[] uncompress(byte[] data) {
//         InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
//         ByteArrayOutputStream out = new ByteArrayOutputStream(data.length * 4);
//         byte[] buffer = new byte[1024];
//         int length;
//         try {
//             while ((length = in.read(buffer)) != -1) {
//                 out.write(buffer, 0, length);
//             }
//         } catch (IOException e) {
//             return Constants.EMPTY_BYTES;
//         } finally {
//             close(in);
//         }
//         return out.toByteArray();
//     }
// }
// 
// Path: src/main/java/com/mpush/api/Constants.java
// public interface Constants {
//     Charset UTF_8 = Charset.forName("UTF-8");
// 
//     int DEFAULT_SO_TIMEOUT = 1000 * 3;//客户端连接超时时间
// 
//     int DEFAULT_WRITE_TIMEOUT = 1000 * 10;//10s默认packet写超时
// 
//     byte[] EMPTY_BYTES = new byte[0];
// 
//     int DEF_HEARTBEAT = 4 * 60 * 1000;//5min 默认心跳时间
// 
//     int DEF_COMPRESS_LIMIT = 1024;//1k 启用压缩阈值
// 
//     String DEF_OS_NAME = "android";//客户端OS
// 
//     int MAX_RESTART_COUNT = 10;//客户端重连次数超过该值，重连线程休眠10min后再重试
//     int MAX_TOTAL_RESTART_COUNT = 1000;//客户端重连次数超过该值，将不再尝试重连
// 
//     int MAX_HB_TIMEOUT_COUNT = 2;
// 
//     String HTTP_HEAD_READ_TIMEOUT = "readTimeout";
// }
// 
// Path: src/main/java/com/mpush/util/Strings.java
// public final class Strings {
//     public static final String EMPTY = "";
// 
//     public static boolean isBlank(CharSequence text) {
//         if (text == null || text.length() == 0) return true;
//         for (int i = 0, L = text.length(); i < L; i++) {
//             if (!Character.isWhitespace(text.charAt(i))) return false;
//         }
//         return true;
//     }
// 
//     public static long toLong(String text, long defaultVal) {
//         try {
//             return Long.parseLong(text);
//         } catch (NumberFormatException e) {
//         }
//         return defaultVal;
//     }
// 
//     public static int toInt(String text, int defaultVal) {
//         try {
//             return Integer.parseInt(text);
//         } catch (NumberFormatException e) {
//         }
//         return defaultVal;
//     }
// }


// Path: src/main/java/com/mpush/util/crypto/MD5Utils.java
import java.security.MessageDigest;
import com.mpush.util.IOUtils;
import com.mpush.api.Constants;
import com.mpush.util.Strings;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/*
 * (C) Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     ohun@live.cn (夜色)
 */

package com.mpush.util.crypto;





/**
 * Created by ohun on 2015/12/25.
 *
 * @author ohun@live.cn (夜色)
 */
public final class MD5Utils {
    public static String encrypt(File file) {
        InputStream in = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            in = new FileInputStream(file);
            byte[] buffer = new byte[10240];//10k
            int readLen;
            while ((readLen = in.read(buffer)) != -1) {
                digest.update(buffer, 0, readLen);
            }
            return toHex(digest.digest());
        } catch (Exception e) {
            return Strings.EMPTY;