a
554325746@qq.com
2020-01-10 ce0902f1721b9de6c0a2e8b16cdb6be2c6bca2b3
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
package com.basic.security.utils;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
 
public class ObjectUtil {
    public static boolean stringEquals(String str1, String str2) {
        if (str1 == null) {
            if (str2 == null) {
                return true;
            } else {
                return false;
            }
        } else {
            return str1.equals(str2);
        }
    }
 
    public static byte[] toByteArray(Object yourObject) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutput out = null;
            try {
                out = new ObjectOutputStream(bos);
                out.writeObject(yourObject);
                out.flush();
                byte[] yourBytes = bos.toByteArray();
                return yourBytes;
            } finally {
                try {
                    bos.close();
                } catch (IOException ex) {
                }
            }
        } catch (Exception e) {
            ExceptionUtil.printException(e);
        }
        return new byte[]{};
    }
 
    public static Object toObject(byte[] yourBytes) {
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(yourBytes);
            ObjectInput in = null;
            try {
                in = new ObjectInputStream(bis);
                Object o = in.readObject();
                return o;
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                } catch (IOException ex) {
                }
            }
        } catch (Exception e) {
            ExceptionUtil.printException(e);
        }
        return null;
    }
}