通用框架平台,每个分支对应子通用框架平台,禁止Merge不同分支!! 分支版本区别见项目内readme.md
whycxzp
2021-01-23 f7f8e9cc7de686fe3e8ef424f1d50fa821255449
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.whyc.util;
 
import com.alibaba.druid.util.StringUtils;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
 
import java.io.*;
 
/**
 * @Description:自定义序列化工具
 */
@Slf4j
public class ShiroRedissionSerialize {
 
    //序列化方法
    public static String serialize(Object object){
        //判断对象是否为空
        if (EmptyUtil.isNullOrEmpty(object)){
            return null;
        }
        //流的操作
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos =null;
        String encodeBase64 = null;
        bos = new ByteArrayOutputStream();
        try {
            oos = new ObjectOutputStream(bos);
            oos.writeObject(object);
            //转换字符串
            encodeBase64 = EncodesUtil.encodeBase64(bos.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
            log.error("流写入异常:{}",e);
        }finally {
            //关闭流
            try {
                bos.close();
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
                log.error("流写入异常:{}",e);
            }
        }
        return encodeBase64;
    }
 
    //反序列化方法
    public static Object deserialize(String str){
        //判断是否为空
        if (EmptyUtil.isNullOrEmpty(str)){
            return null;
        }
        //流从操作
        ByteArrayInputStream bis =null;
        ObjectInputStream ois = null;
        Object object = null;
        //转换对象
        bis = new ByteArrayInputStream(EncodesUtil.decodeBase64(str));
        try {
            ois = new ObjectInputStream(bis);
            object = ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("流读取异常:{}",e);
        }finally {
            //关闭流
            try {
                bis.close();
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
                log.error("流读取异常:{}",e);
            }
 
        }
        return object;
    }
}