open-eid / digidoc4j

DigiDoc for Java. Javadoc:
http://open-eid.github.io/digidoc4j
GNU Lesser General Public License v2.1
73 stars 39 forks source link

Support for writing Container directly to OutputStream #25

Closed virtual-machinist closed 7 years ago

virtual-machinist commented 7 years ago

I see no rationale for Container.save(OutputStream) being deprecated. The user should be able to freely choose where to write the contents of the container, be it FileOutputStream, ServletOutputStream or any other. Another issue I've faced while using the library was the enormous memory usage. I see no point in using byte[] intermediates for ZIP entries in AsicContainerCreator, especially when most of the underlying classes implement some sort of write(OutputStream) / getInputStream() method. My solution was to replace writeZipEntry() / writeZipEntryWithoutComment() with callbacks to the ZipOutputStream. Probably not the most elegant way of doing things, but still less memory overhead and no signature changes. My implementation uses less than 20 MB of heap for creating a container with a 1.2 GB Modern IE image (checked using VisualVM). The original implementation fails with OutOfMemoryError, if heap is not increased from default 2 GB.

rvillido commented 7 years ago

Hi Igor,

Thank you for your contribution. It is very much appreciated!

There is a small pause in the development right now until the next development contract starts next year. These changes will be included in the main release as soon as the development starts again and all the code and tests are validated.