package cn.com.qmth.stmms.ms.commons.constant;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @Description: 系统常量
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2019/10/11
 */
public class SystemConstant {
    public static final String ENCODING = "UTF-8",
            AES = "AES",
            AES_MODE = "AES/CBC/PKCS5Padding";//用这个模式，规则必须为16位
    //    public static final String AES_RULE = "0102030405060708";
    public static final int SECRET_KEY = 0x99,//加密解密秘钥
            IMAGE = 1,//裁切原图
            THUMB = 2,//缩略图
            SHEET = 3,//原图
            WATER_MARK = 4;//分数水印图

    /**
     * 流写入
     *
     * @param inputStream
     * @param outputStream
     * @return
     * @throws IOException
     */
    public static OutputStream writeStream(InputStream inputStream, OutputStream outputStream) throws IOException {
        int index = 0;
        byte[] bytes = new byte[1024 * 8];
        byte[] bytesEnc = new byte[1024 * 8];
        while ((index = inputStream.read(bytes)) != -1) {
            //将字节数组的数据全部写入到输出流中
            for (int i = 0; i < index; i++) {
                //通过异或运算加密
                bytesEnc[i] = (byte) (bytes[i] ^ SystemConstant.SECRET_KEY);
            }
            outputStream.write(bytesEnc, 0, index);
        }
        return outputStream;
    }

    /**
     * 流写入
     *
     * @param inputStream
     * @param outputStream
     * @return
     * @throws IOException
     */
    public static OutputStream writeStreamFomal(InputStream inputStream, OutputStream outputStream) throws IOException {
        int index = 0;
        byte[] bytes = new byte[1024 * 8];
        while ((index = inputStream.read(bytes)) != -1) {
            //将字节数组的数据全部写入到输出流中
            outputStream.write(bytes, 0, index);
        }
        return outputStream;
    }
}
