English 中文(简体)
如何让SAX Parser等到一个档案完成下载,然后才放完。
原标题:How to make the SAX Parser wait for a file to finish downloading before it is parsed?

我遇到一个问题,即我的XML文件负荷缓慢,在它们开始被搁置之前没有完成下载,这从我的主言中留下了一个xml而不是格式好的例外情况,表明文件下载不完整。

日志中的全部错误是“ERROR/Error(323):错误org.apache.harmony.xml.ExpatParser$ParseException: 第10行,第46栏:不知情(无效)”

我知道Xml案是正确的,因为有时它会发挥作用,而且我也可以把它拖到我的浏览器上。

在继续使用Xml数据之前,由谁来等待投入使用?

下面的法典是我用来查阅档案和整理的法典。

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
GradeHandler gradeHandler = new GradeHandler();
xr.setContentHandler(gradeHandler);
URL url = new URL("https://url/to/xml/file");
HttpsURLConnection ucon = (HttpsURLConnection)url.openConnection();
ucon.setHostnameVerifier(new AllowAllHostnameVerifier());
xr.parse(new InputSource(new BufferedInputStream(ucon.getInputStream())));
问题回答

What would be the best way to make the parser wait for the InputSource before continuing on and parsing the xml data?

也许先下载答复,然后再使用?

ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(ucon.getInputStream(), output);
xr.parse(new InputSource(new ByteArrayInputStream(output.toByteArray());




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签