I'm programming in order to create a tool to translate a coded .txt file in a readable .xlsx file. (I need to work with xlsx because I'm working with more than 256 colums, so i'm using XSSFWorkbook when writing rows and colums).
The coding part is ok.. I know it beacuse I verified it several times but when I tried to add new coding maps in the code it all ends in :
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.io.ByteArrayOutputStream.write(Unknown Source)
at org.apache.poi.openxml4j.opc.internal.MemoryPackagePartOutputStream.write(MemoryPackagePart OutputStream.java:88)
at org.apache.xmlbeans.impl.store.Cursor._save(Cursor.java:590)
at org.apache.xmlbeans.impl.store.Cursor.save(Cursor.java:2544)
at org.apache.xmlbeans.impl.values.XmlObjectBase.save(XmlObjectBase.java:212)
at org.apache.poi.xssf.usermodel.XSSFSheet.write(XSSFSheet.java:2480)
at org.apache.poi.xssf.usermodel.XSSFSheet.commit(XSSFSheet.java:2439)
at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:196)
at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:200)
at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:204)
at model.Conversione.traduzioneFile(Conversione.java:241)
at model.Main.scriviFile(Main.java:76)
at model.Main.main(Main.java:52)
The error occurs after 3000/4000 lines , the memory is acting like this start value:
14443720 **:13572128 **:12078128 **:10575592 **:14126224 ->new increase always lower than start value then decreasing **:12559920 **:11811440 **:10229128 **:13751400 -> ... **:13011080
The "coding maps" are maps generally of the type HashMap<Integer,Hashmap<Integer,String>>
.
(I did it like this because I can not use databases..)
So the procedure is mainly:
-instantiate and create the whole map at first, -read line from .txt file, -split the line, take a token, translate it using the map and put it into rows and columns -wb.write(fileOutputStream fos) -fos.close.
I cannot understand why that error occurs even if the maps I added are not taken into account in the translating operation...
And why the memory quantity is so variable? (but never back to start value?)
If i wasn't clear in some points please ask.. i don't know what to do..
At the beginning I thought it was a buffering problem for the increasing size of .xlsx file (even if..as i said..nothing should have changed because the new maps are not used)..
Any hints appreciated..
Lucia