Bug 56906

Summary: While reading .docx(of more than 10mb) file with Apache POI its throwing OutOfMemory error
Product: POI Reporter: Ajeet Singh <ajeet.singh>
Component: XWPFAssignee: POI Developers List <dev>
Status: RESOLVED INVALID    
Severity: major    
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Ajeet Singh 2014-09-01 11:14:11 UTC
I am using apche POI-3.10, I have to read an sample.docx file and write its content to new sampleOutput.docx file.
However I have succeed to do the same but while reading file’s more than or equal to 10mb in size, XWPFDocument is not able to read the file, its throwing error “java.lang.OutOfMemoryError: Java heap space”

Following is the sample code for the reference, Request you to help me with any solution

try {                                        
FileInputStream  fis = new FileInputStream(“sample.docx”);
                XWPFDocument  document = new XWPFDocument(OPCPackage.open(inputFilePath));  // its throws error here with files of size >= 10 mb            
                OutputStream  outStream = new FileOutputStream(outputFilePath);     

                document. write(outStream);

}catch(Exception e){
                e.printStackTrace();
}
Comment 1 Nick Burch 2014-09-01 11:27:04 UTC
The default JVM heap size is very very small by modern standards. You need to increase that at JVM startup (-Xmx) to something more sensible before handling larger files