- 最终版本,利用hessian实现rpc调用
- HessianUtil
package com.bill.rpc10;
import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* @Auther: wangchunwen
* @Date: 2023/1/10 - 01 - 10 - 23:31
* @Description: com.bill.rpc10
* @version: 1.0
*/
public class HessianUtil {
public static byte[] serialize(Object o) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Hessian2Output output = new Hessian2Output(baos);
output.writeObject(o);
byte[] bytes = baos.toByteArray();
baos.close();
output.close();
return bytes;
}
public static Object deseriabliz(byte[] bytes) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Hessian2Input input = new Hessian2Input(bais);
Object o = input.readObject();
bais.close();
input.close();
return o;
}
}
标签:230110,bytes,50,new,RPC,io,import,close,baos
From: https://www.cnblogs.com/wcwblog/p/17041702.html