简体   繁体   English

Jaxb直接将XML生成到OutputStream

[英]Jaxb to generate the XML directly to the OutputStream

I have a 500Mb csv file. 我有一个500Mb的csv文件。 I need to convert it into XML file. 我需要将其转换为XML文件。
I am using the Jaxb to created the xml file. 我正在使用Jaxb创建xml文件。 It is working fine for small amout of data. 对于少量数据,它工作正常。
but for large amout of data like 300 mb it is throwing out of memory exception. 但是对于大量数据(例如300 mb),则会抛出内存不足异常。
Can anyone tell me that How can I create each element and write it into a file 谁能告诉我,我怎样才能创建每个元素,并将其写入文件
without creating the whole tree using the jaxb?" 不用使用jaxb创建整个树?”

Thanks Sonu 谢谢索努

Converting csv to XML you should expect the size of data to be about 10x larger. 将csv转换为XML时,您应该期望数据大小约为10倍。 I suggest you increase the heap size to 10 Gb if you want to use Jaxb for your whole file at once, possibly higher. 如果您想一次对整个文件使用Jaxb,建议您将堆大小增加到10 Gb,可能更高。

Another approach would be to convert one line of CSV at a time. 另一种方法是一次转换一行CSV。 You can still use Jaxb to do this, but you may find a one line println statement is much simpler. 您仍然可以使用Jaxb来执行此操作,但是您可能会发现一行println语句要简单得多。 In this case, you can expect your program will use up to 10x the longest line. 在这种情况下,您可以预期您的程序将使用最长的行的10倍。 (Which might be a few KB) (可能是几KB)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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