Android:是否可以解析来自网络的二进制数据?

发布于 2024-12-20 16:22:24 字数 261 浏览 0 评论 0原文

不久前,我为一些二进制数据开发了一个解析器,当数据通过网络传输时,它会解析这些数据。重要的是,在开始解析之前,我们不必等待整个字节集下载完毕。这极大地提高了速度,因为它允许更多线程,我们可以在系统等待字节时做一些事情。

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-12-27 16:22:24

当然。下载数据的标准模式通常如下所示:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(URL));

HttpResponse 有一个名为 getContent 返回一个 InputStream。您可以读取几个字节,对该数据进行一些处理或排队,然后获取更多数据。根据需要重复。

Sure. The standard pattern for downloading data usually looks something like this:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(URL));

HttpResponse has a method called getContent which returns an InputStream. You can just read a few bytes, do or queue off some processing on that data, then get some more data. Repeat as necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文