|
@@ -1,7 +1,7 @@
|
1
|
1
|
package com.xxl.job.core.rpc.serialize;
|
2
|
2
|
|
3
|
|
-import com.caucho.hessian.io.HessianInput;
|
4
|
|
-import com.caucho.hessian.io.HessianOutput;
|
|
3
|
+import com.caucho.hessian.io.Hessian2Input;
|
|
4
|
+import com.caucho.hessian.io.Hessian2Output;
|
5
|
5
|
|
6
|
6
|
import java.io.ByteArrayInputStream;
|
7
|
7
|
import java.io.ByteArrayOutputStream;
|
|
@@ -15,22 +15,47 @@ public class HessianSerializer {
|
15
|
15
|
|
16
|
16
|
public static <T> byte[] serialize(T obj){
|
17
|
17
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
18
|
|
- HessianOutput ho = new HessianOutput(os);
|
|
18
|
+ Hessian2Output ho = new Hessian2Output(os);
|
19
|
19
|
try {
|
20
|
20
|
ho.writeObject(obj);
|
|
21
|
+ ho.flush();
|
|
22
|
+ byte[] result = os.toByteArray();
|
|
23
|
+ return result;
|
21
|
24
|
} catch (IOException e) {
|
22
|
25
|
throw new IllegalStateException(e.getMessage(), e);
|
|
26
|
+ } finally {
|
|
27
|
+ try {
|
|
28
|
+ ho.close();
|
|
29
|
+ } catch (IOException e) {
|
|
30
|
+ throw new IllegalStateException(e.getMessage(), e);
|
|
31
|
+ }
|
|
32
|
+ try {
|
|
33
|
+ os.close();
|
|
34
|
+ } catch (IOException e) {
|
|
35
|
+ throw new IllegalStateException(e.getMessage(), e);
|
|
36
|
+ }
|
23
|
37
|
}
|
24
|
|
- return os.toByteArray();
|
25
|
38
|
}
|
26
|
39
|
|
27
|
40
|
public static <T> Object deserialize(byte[] bytes, Class<T> clazz) {
|
28
|
41
|
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
29
|
|
- HessianInput hi = new HessianInput(is);
|
|
42
|
+ Hessian2Input hi = new Hessian2Input(is);
|
30
|
43
|
try {
|
31
|
|
- return hi.readObject();
|
|
44
|
+ Object result = hi.readObject();
|
|
45
|
+ return result;
|
32
|
46
|
} catch (IOException e) {
|
33
|
47
|
throw new IllegalStateException(e.getMessage(), e);
|
|
48
|
+ } finally {
|
|
49
|
+ try {
|
|
50
|
+ hi.close();
|
|
51
|
+ } catch (Exception e) {
|
|
52
|
+ throw new IllegalStateException(e.getMessage(), e);
|
|
53
|
+ }
|
|
54
|
+ try {
|
|
55
|
+ is.close();
|
|
56
|
+ } catch (IOException e) {
|
|
57
|
+ throw new IllegalStateException(e.getMessage(), e);
|
|
58
|
+ }
|
34
|
59
|
}
|
35
|
60
|
}
|
36
|
61
|
|