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

Writing Container directly to OutputStream #23

Closed virtual-machinist closed 7 years ago

virtual-machinist commented 8 years ago

Is there any way to write a Container directly to an OutputStream without storing everything in memory/files? Container.save(OutputStream) is a deprecated wrapper for Container.saveAsStream(), which creates and returns a ByteArrayInputStream. That is something we might want to avoid, especially for large containers.

We can of course use Container.saveAsFile(String) (again, why String and no option for File/Path?) to save the contents in a temporary file, then copy it to the OutputStream, but that's a bit tedious IMHO.

Is there a reason Container.save(OutputStream) is deprecated?

rvillido commented 8 years ago

Hi, saving directly to outputstream makes sense, good point.

I have created a ticket for this, but it won't be developed before the next year. https://www.pivotaltracker.com/story/show/133095765

It would be much appreciated if you could make a pull request with that feature.

Thanks for the feedback!

virtual-machinist commented 7 years ago

As of now I've rewritten AsicContainerCreator to use streams where possible. Unfortunately the class itself was not very convenient to extend, so I've created a StreamingAsicContainerCreator, which retains all ZIP entry writing logic. However since they do not share any hierarchy, I had to change BDocContainer.writeAsicContainer(). Pull request created, looking forward to receiving some feedback.

nostneji commented 7 years ago

In release 1.0.7 the writing of Container directly to an OutputStream is added.