安卓:SAX解析器进度监控 [英] Android: SAX parser progress monitoring

查看:200
本文介绍了安卓:SAX解析器进度监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SAX DefaultHandler的它解析一个InputStream。我不知道有多少元素在XML,所以我不能指望他们对的endElement 或simmilar。 我做知道的字节长度的InputStream (从HTTP头中读出),但我无法找到一个方法来获得当前的按字节的进展的解析过程。

有没有办法让目前的进展(如位处理)的解析过程呢?

这是怎么了的DefaultHandler 被调用:

 的SAXParserFactory厂= SAXParserFactory.newInstance();
的SAXParser解析器= factory.newSAXParser();
parser.parse(InputStream的,myDefaultHandler);
 

解决方案

您可以通过编写的 FilterInputStream中的来包装现有的InputStream。在过滤器的阅读()方法,增加一个计数器,并提供一个getter,这样别的东西可以跟踪当前计数。

由于分析器可以预读,这将是近似的,但它可能是最好的,你可以做的。

I have a SAX DefaultHandler which parses an InputStream. I don't know how many elements are in the XML so I can't count them on endElement or simmilar. I do know the byte length of the InputStream (read from the http header) but I can't find a method to get the current bytewise progress of the parsing process.

Is there a way to get the current progress (i.e. bits processed) of the parsing process?

This is how the DefaultHandler gets called:

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(inputStream, myDefaultHandler);

解决方案

You can do this by writing a FilterInputStream to wrap the existing inputStream. In the read() method of your filter, increment a counter, and provide a getter so that something else can track the current count.

Since the parser may read ahead, this will be approximate, but it's probably the best you can do.

这篇关于安卓:SAX解析器进度监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆