Android:是否可以解析来自网络的二进制数据?
不久前,我为一些二进制数据开发了一个解析器,当数据通过网络传输时,它会解析这些数据。重要的是,在开始解析之前,我们不必等待整个字节集下载完毕。这极大地提高了速度,因为它允许更多线程,我们可以在系统等待字节时做一些事情。
在 Android 上,这可以通过 Android HTTP 类实现吗?当有一定数量的字节可用时,我也想要大致类似的东西,调用回调,允许我在系统继续加载更多字节的同时解析这些字节。我已经使用过 DefaultHttpClient 一些,但不确定它是否支持我正在寻找的内容。
A while ago I worked on a parser for some binary data that parsed the data as the data was coming down the network. The important thing being that we didn't have to wait for the entire set of bytes to download before we started parsing. This GREATLY improved the speed because it allowed for more threading, we were able to do something while the system waited for bytes.
On Android, is this possible with the Android HTTP classes? I would like something roughly similar too when some number of bytes are available, a callback is called, allowing me to parse those bytes while the system continues loading more bytes. I've worked with DefaultHttpClient a bit but am not sure if it supports what I'm looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然。下载数据的标准模式通常如下所示:
HttpResponse
有一个名为getContent
返回一个InputStream
。您可以读取几个字节,对该数据进行一些处理或排队,然后获取更多数据。根据需要重复。Sure. The standard pattern for downloading data usually looks something like this:
HttpResponse
has a method calledgetContent
which returns anInputStream
. You can just read a few bytes, do or queue off some processing on that data, then get some more data. Repeat as necessary.