Skip to content

Unable to read large excel files #266

Description

@fivetran-satvikpatil

Hi guys,
I am unable to read large Excel files.

I am using the below code to fetch the workbook:

StreamingReader.builder()
                    .rowCacheSize(100) 
                    .bufferSize(4096) 
                    .open(inputStreamSupplier.get());

It is failing with below error :

java.lang.OutOfMemoryError: Requested array size exceeds VM limit
	at java.base/java.util.Arrays.copyOf(Arrays.java:3537)
	at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:100)
	at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:130)
	at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:185)
	at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:149)
	at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:136)
	at org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.<init>(ZipArchiveFakeEntry.java:47)
	at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:53)
	at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:210)
	at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:194)
	at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:168)
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:149)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:277)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:186)
	at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:113)
	at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:91)
	at com.monitorjbl.xlsx.StreamingReader$Builder.open(StreamingReader.java:251)

The memory assigned is 8GB, but it is still failing with this error. By observing the stack trace and also the heap dump, I noticed that we are creating a byte array with the total size of around 2.1GB.
How can we fix this issue?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions