指示 XmlPullParser 的缓冲区大小

发布于 2024-10-08 21:05:43 字数 171 浏览 0 评论 0原文

我正在使用 XmlPullParser 通过 http 在移动设备上逐渐加载一些数据。

由于此类连接的速度通常可以低至 1KB/s 或更低,因此我想降低 PullParser 的默认缓冲区大小 8096 字节。

有人知道这怎么可能吗? (另外,为什么 PullParser 甚至有自己的缓冲区?)

I'm using XmlPullParser to load some data gradually over http on mobile devices.

Since the speed of such connections can often be as low as 1KB/s or less, I would like to lower the default Buffer size of 8096 bytes for the PullParser.

Do anybody have an idea, how that might be possible?
(Also, why does the PullParser even have its own buffer?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

饮惑 2024-10-15 21:05:43

据我所知,您需要设置传递给 XmlPullParser.setInput() 的 Reader 对象或 InputStream 对象的缓冲区大小。

setInput() 方法可以接受任何类型的源,但由于两者都是抽象的,您使用的 Reader 或 InputStream 的实际类型可能会有所不同 - 有些可能有缓冲区,在这种情况下,您需要查看文档以根据您的情况进行检查使用。

编辑:

对于实现具有缓冲区的 XmlPullParser 的类 - 在我看来,这是不可避免的,因为需要有某种“工作空间”,但缓冲区的大小buffer 以及它如何反映每次从 Reader 或 InputStream 请求的数据量,将归结为类定义。

总之,我想说,能够控制每次请求的数据量的唯一方法是定义自己的实现 XmlPullParser 的类。最简单的方法是扩展一个开源类(例如 apache 类)并简单地重写从 Reader 或 InputStream 源读取的方法(使用较小的缓冲区)。

As far as I can tell, you would need to set the buffer size of the Reader object or InputStream object passed to XmlPullParser.setInput().

The setInput() method can accept either type of source but as both are abstract, the actual type of Reader or InputStream you use can vary - some may have buffers in which case you need to look at the docs to check depending on what you are using.

EDIT:

As for a class which implements XmlPullParser having a buffer - it seems to me that this is going to be inevitable as there will need to be a 'workspace' of some sort, but the size of the buffer and how that reflects on the amount of data requested from the Reader or InputStream each time, will come down to the class definition.

In conclusion, I would say the only way you will be able to control the amount of data requested each time is to define your own class which implements XmlPullParser. The easiest way would be to extend an open source class (such as the apache one) and simply override the methods that read from the Reader or InputStream sources (using a smaller buffer).

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