//生成数据 ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(amf); FileOutputStream fileOutputStream = new FileOutputStream( new File("out.amf")); out.writeTo(fileOutputStream) ; out.flush(); System.out.println("在当前目录生成out.amf成功!");
} publicstatic Object generateUnicastRef(String host, int port)throws Exception { java.rmi.server.ObjID objId = new java.rmi.server.ObjID(); sun.rmi.transport.tcp.TCPEndpoint endpoint = new sun.rmi.transport.tcp.TCPEndpoint(host, port); sun.rmi.transport.LiveRef liveRef = new sun.rmi.transport.LiveRef(objId, endpoint, false); returnnew sun.rmi.server.UnicastRef(liveRef); } publicstaticbyte[] serialize(Object data) throws IOException { MessageBody body = new MessageBody(); body.setData(data); ActionMessage message = new ActionMessage(); message.addBody(body); ByteArrayOutputStream out = new ByteArrayOutputStream(); AmfMessageSerializer serializer = new AmfMessageSerializer(); serializer.initialize(SerializationContext.getSerializationContext(), out, null); serializer.writeMessage(message); return out.toByteArray(); }
//用来验证 publicstatic ActionMessage deserialize(byte[] amf)throws ClassNotFoundException, IOException { ByteArrayInputStream in = new ByteArrayInputStream(amf); AmfMessageDeserializer deserializer = new AmfMessageDeserializer(); deserializer.initialize(SerializationContext.getSerializationContext(), in, null); ActionMessage actionMessage = new ActionMessage(); deserializer.readMessage(actionMessage, new ActionContext()); return actionMessage; } }
Disclaimer: This article is for study and communication. It is strictly forbidden to use it for illegal operations. All consequences shall be borne by yourself. Reading this article means that you have agreed to this statement.