简体   繁体   English

使用Java重写二进制流

[英]Rewriting Binary Streams using Java

I have been studying Netty and Mina but am confused as to the best way to rewrite binary streams. 我一直在研究Netty和Mina,但是对于重写二进制流的最佳方法感到困惑。 For example, I would like to create a proxy that will allow for replacement of XML and forward along. 例如,我想创建一个代理,该代理将允许替换XML并向前转发。

Examples appreciated. 实例赞赏。

I think you're thinking at too low of a level. 我认为您的思考水平过低。 XML is not so much "binary" as it is an abstraction on top of binary. XML与其说是“二进制”,还不如说是二进制的抽象。 If you want to replace snippets of XML as they come across your line, you'll have to poke into the payload portion of the packets and look for patterns of XML.. a simple way is to use a regular expression after rebuilding the bytes into content temporarily. 如果要替换行中出现的XML代码段,则必须戳入数据包的有效负载部分并查找XML模式。一种简单的方法是在将字节重建为字节后使用正则表达式暂时满足。

Once you have this search and you have matched what you want, you can replace what you want to replace and re-send. 进行搜索并匹配所需的内容后,您可以替换要替换的内容并重新发送。

The hard part of this is that you will likely need to cache some input before it leaves your machine so that you are able to find the beginning and end of what it is you are searching for. 困难的部分是,您可能需要先缓存一些输入,然后再离开计算机,这样才能找到要搜索的内容的开头和结尾。 What makes this difficult is that often times, you don't know what constitutes the "beginning" and the "end" of a data payload. 造成这种困难的原因是,通常您不知道什么构成数据有效负载的“开始”和“结束”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM