要搞这个原因是:
RedDwarf平台在服务端手法数据都是基于字节数组类型的,这样就需要做一个byte数组到基本数据类型的转换。
用到的技术主要有MINA和AMF,先来介绍一下AMF:
Action Message Format (AMF) is a binary format used to serialize ActionScript objects. It is used primarily to exchange data between an Adobe Flash application and a remote service, usually over the internet.
Typical usage from Adobe Flash Player, consists of an ActionScript program which:[citation needed]
- Connects to a specific "gateway" URL on a web server
- Accesses the service which handles AMF communication
- Calls a method on the service, mentioning a "callback" method
- Arguments passed are serialized to AMF and deserialized at the receiving end
- The service processes the input, and optionally returns data via AMF
- The callback method is invoked by the platform, and returned data is passed
the pragraph below is used to describe the new characteristic which is about some new type in the
ActionScript 3.0. and this content is come from the amf3_spec_121207.pdf
ActionScript 3.0 introduced a new type to support the manipulation of raw data in the form of an
Array of bytes, namely flash.utils.ByteArray. To assist with ActionScript Object serialization and
copying, ByteArray implements flash.utils.IDataInput and flash.utils.IDataOutput. These interfaces
specify utility methods that help write common types to byte streams. Two methods of interest are
IDataOutput.writeObject and IDataInput.readObject. These methods encode objects using AMF.
The version of AMF used to encode object data is controlled by the ByteArray.objectEncoding method, which can be set to either AMF 3 or AMF 0. An enumeration type, flash.net.ObjectEncoding, holds the constants for the versions of AMF - ObjectEncoding.AMF0 and ObjectEncoding.AMF3 respectively.
Note that ByteArray.writeObject uses one version of AMF to encode the entire object. Unlike
NetConnection, ByteArray does not start out in AMF 0 and switch to AMF 3 (with the objectEncoding
property set to AMF 3). Also note that ByteArray uses a new set of implicit reference tables for objects,
object traits and strings for each readObject and writeObject call.
根据pdf所介绍,flash.utils.ByteArray 用来协助实现Action Script 对象的序列化和拷贝。该类实现了flash.utils.IDataInput 和flash.utils.IDataOutput接口。实现了它们的writeObject和readObject方法。这两个方法使用的对象就是使用AMF0或者是AMF3进行编码的。
And now the case is that i should convert byte array to the xml type data. I can use the MINA 's
IoBuffer. org.apache.mina.core.buffer.IoBuffer, it has a function:
public static IoBuffer wrap(byte[] byteArray). And use it you can make the byte array which received
from client . After that, use the IoBuffer.asInputStream() convert the it to inputstream . And now you can
use openAMF's XMLUtils.convertToDOM(inputStream). and this function return a DOM which is one type
of org.w3c.dom. It is like that :org.w3c.dom.Document dom = XMLUtils.convertToDOM(inputstream);
也就是说,用MINA的IoBuffer.wrap(Byte []: org0)可以将从客户端过来的byte数组类型的数值压缩到IoBuffer的ByteBuffer 中,然后利用IoBuffer的实例方法: as InputStream()将byteBuffer 转换为输入流。最后利用openAMF的XMLUtils.convertToDOM(inputStream)方法将输入流转换为DOM树。这样就完成了转换。
利用AMF的好处在于RedDwarf的数据传递时利用Byte数组传递的。但是按照我这样的搞法,最后还是在用xml呀,所以这一点比较纠结,现在先这样吧,至少这样是可以实现的,就行而且基本上这些数据转换也摸了一遍了,下次就会好很多了,只是把xml换为可能json等这些吧。
分享到:
相关推荐
2017年8月更新VisualSVN-Server-3.6.4-x64位服务端
基于SpringBoot 和 Nuxt 的服务端渲染博客系统.zip正版个人毕设-基于SpringBoot 和 Nuxt 的服务端渲染博客系统.zip正版个人毕设-基于SpringBoot 和 Nuxt 的服务端渲染博客系统.zip正版个人毕设-基于SpringBoot 和 ...
mysql-server for linux,mysql最新服务端服务端,要下载统一版本的客户端,开发包,share包的话,我在csdn上上传了统一版本的欢迎下载!
最近因为想做一个APK,主要涉及到网络方面的应用,所以也开始学习之前没怎么涉及到的模块。今天实现要实现的其实很简单,通过网络获取服务端一个文件(可以是txt、png、mp3等等),因为之前是做c#开发的,所以操起...
cas-overlay-template-6.1 服务端代码,文章:记录CAS6.1X Server 部署加Mysql数据源整合详细所用到的代码
Jmeter-Plugins-ServerAgent常用来监控服务端资源情况,jmeter 4.0版本之后就无法在plugins manager管理更新下载该包了。jmeter-plugins-manager-1.3.jar、JMeterPlugins-ExtrasLibs.jar放置到jmeter_home/lib/ext/...
ArcGIS简介 桌面 GIS --ArcGIS Desktop:ArcView、ArcEditor、ArcInfo; 服务端 GIS --ArcGIS 9所包含的三种服务端产品:ArcSDE、ArcIMS、ArcGIS Server。
VisualSVN-Server-3.9.2 64位服务端
Linux运维-运维课程MP4频-06容器编排(k8s)-day01-11-9-06-docker客户端与服务端分
SignalR-实现web浏览器客户端与服务端的推送功能 SignalR-实现web浏览器客户端与服务端的推送功能
Laravel开发-laravel-push-notification Push Notification 服务端支持 app的推送通知发送工具,支持结果的apns和安装的gcm
直接可以对cas-server项目进行打不,部署到tomcat,即可使用,记得修改cas-server的数据库连接地址哦 单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目cas-server 单点登录服务端项目...
从文本控件中获得Cstring类型的数据,与想发送的目标客户端昵称根据之前的约定进行组合,然后转换为TCHAR的数据,再发送到所有的客户端。 四、 客户端单击“断开服务器”按钮后的操作 关闭套接字,此时,服务端将会...
泛微协同办公平台(e-cology)E-cology9-Mobile7服务端设置手册.doc
最新版SVN服务端,Setup-Subversion-1.7.4(SVN服务端).msi
restlet_jax-rs列子 可直接运行 在我的博客里有一些描述。希望能给大家提供点帮助
metaq-server-1.4.6.2服务端+客户端+javadoc文档,打包于一个压缩包
内网穿透proxy-server-0.1_ZW87MY服务端开箱即用
oracle10g-win和linux-32位、64位服务端和客户端