poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 52204] InputStream not closed
Date Fri, 18 Nov 2011 12:50:09 GMT

Yegor Kozlov <yegor@dinom.ru> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #3 from Yegor Kozlov <yegor@dinom.ru> 2011-11-18 12:50:09 UTC ---
It is not a bug, rather a feature of the XSSF API. 

In short, .xlsx file is a zip archive and there are two ways to open it:

1) from file which leads to invoking java.util.zip.ZipFile(File file) deep in
POI internals. 

2) from input stream in which case we first read everything into memory and
then pass the data to ZipInputStream  

It should be noted, that (2) uses quite a bit more memory than (1), which
doesn't need to hold the whole zip file in memory, and can take advantage
of native methods. 

As you may guessed, (1) opens the underlying zip but does not close it which
results in a leak.

You have two choices:

 choice 1: open from FileInputStream
 choice 2: re-write your code as follows:

OPCPackage pkg = OPCPackage.open(file);
XSSFWorkbook wb = new XSSFWorkbook(pkg);

// work with workbook

pkg.close(); // gracefully closes the underlying zip file

I'm going to update the documentation to reflect this feature.


Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

View raw message