简体   繁体   中英

XMLStreamWriter - Issue writing long string to xml writer

I am working on a gradle project that involves reading from and writing to xml files. I've come across an issue while trying to write a very long string of escaped xml to a file using XMLStreamWriter . This string ends up taking around half an hour to write to the file and causes my application to stop responding. The issue arises when I call the method:

writer.writeAttribute(key, escapedXML)

The strange thing is that I've imported the gradle project to both eclipse and intellij; the problem is present when I run the application in eclipse and when I run the executable jar created using gradle, but, when I run the program in intellij, it finishes quickly without any problems. I haven't included any additional jar files aside from the dependencies included in the build.gradle file. I've tried to find differences in dependencies or settings between the two IDE's but I haven't been able to find anything. I've also verified that both IDE's are using the same JRE. I've also tried running the jar with more memory allocated to the application, but this didn't help. I'm sure I'm missing something obvious and I'd really appreciate some help. Please let me know if you can tell what I'm missing.

Update: Spent several more days looking into this with no luck. I used intellij to create an executable jar but the problem was present in that as well. I also looked into the class path for the application when running in eclipse and intellij. The path included a few jar files from jdk1.8.0_121\\lib when running in intellij but not when running in eclipse. I then copied the intellij class path and ran the jar with that class path specified. Still no luck. I hope I've provided enough details to spark some ideas. Any suggestions would be greatly appreciated.

I figured out the cause of the issue. Apparently, intellij was setting the encoding for my XMLStreamWriter to UTF-8 automatically while eclipse was not. I changed this

 XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream);

to this

XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, "UTF-8");

and my issue was solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM