// 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";
// }


import java.io.*;
import com.mpush.api.Constants;
/*
 * (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;





/**
 * <p>
 * BASE64编码解码工具包
 * </p>
 * <p>
 * 依赖javabase64-1.3.1.jar
 * </p>
 */
public class Base64Utils {

    /**
     * 文件读取缓冲区大小
     */
    private static final int CACHE_SIZE = 1024;

    /**
     * <p>
     * BASE64字符串解码为二进制数据
     * </p>
     *
     * @param base64 xxx
     * @return return
     * @throws Exception xxx
     */
    public static byte[] decode(String base64) throws Exception {
        return Base64.getDecoder().decode(base64);
    }

    /**
     * <p>
     * 二进制数据编码为BASE64字符串
     * </p>
     *
     * @param bytes xxx
     * @return return
     * @throws Exception xxx
     */
    public static String encode(byte[] bytes) throws Exception {
// 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/crypto/Base64Utils.java
import java.io.*;
import com.mpush.api.Constants;

/*
 * (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;





/**
 * <p>
 * BASE64编码解码工具包
 * </p>
 * <p>
 * 依赖javabase64-1.3.1.jar
 * </p>
 */
public class Base64Utils {

    /**
     * 文件读取缓冲区大小
     */
    private static final int CACHE_SIZE = 1024;

    /**
     * <p>
     * BASE64字符串解码为二进制数据
     * </p>
     *
     * @param base64 xxx
     * @return return
     * @throws Exception xxx
     */
    public static byte[] decode(String base64) throws Exception {
        return Base64.getDecoder().decode(base64);
    }

    /**
     * <p>
     * 二进制数据编码为BASE64字符串
     * </p>
     *
     * @param bytes xxx
     * @return return
     * @throws Exception xxx
     */
    public static String encode(byte[] bytes) throws Exception {
        return new String(Base64.getEncoder().encode(bytes), Constants.UTF_8);