Question

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?)

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top