0

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.

DarthRitis
  • 352
  • 2
  • 10
  • Buffered writing should have been used, console output/logging can slow down with different behavior. Memory options of java `-Xmx=...m` maybe. – Joop Eggen Jun 01 '17 at 20:24
  • I create the XMLStreamWriter using a BufferOutputStream. Also I've tried changing the VM arguments to adjust the memory options but it didn't help – DarthRitis Jun 01 '17 at 20:37
  • Maybe a xalan versus xerces XML parser/writer thing. The actual XML parser is selected using an interface and the java SPI (service provider interface). And those two are most prominent. You can use a debugger or java SPI calls to check whether different XML libraries where used. – Joop Eggen Jun 01 '17 at 20:54
  • When reading XML it could be the use of an _XML catalog_ that would speed up things tremendously; external references not needing to be loaded over the web. Try running it without internet. – Joop Eggen Jun 01 '17 at 20:57
  • Ok I actually had both those jars included (I think I added them while trying to fix this issue) and I tried removing them one by one and then I removed both but it didn't fix the issue. I also have a jar called xml-apis which gets included regardless of whether or not I list it as a dependency in the build.gradle file. I'm about to wrap up for the day but I'll try using the debugger to check which library is being used tomorrow. Thank you – DarthRitis Jun 01 '17 at 21:17

1 Answers1

0

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.

DarthRitis
  • 352
  • 2
  • 10