snowindy/scriptlet4docx

Streams

RushPVA opened this issue · 14 comments

Now exists only File api. Streams api will be very usefull.

ok. Please describe the way you use the library, so it's easier to create an appropriate api.
is it a web app?

yes it is web app,
Example: templates are in db. i need to process one of them and put it in response.
way to do it now:

  1. create tmp file with template
  2. process template and save it another tmp file
  3. copy processed file in response outputstream

I suppose easier way to get api somthing like:
DocxTemplater(InputStream is)
process(OutputStream os, ...)

Yeah, it makes sense. It will be a utility wrapper around file API at first.

Thing I am aware of is output stream closing..
The other thing is caching input streams data (for example, you do not want to do a heavy preprocess every time the templater is invoked, it's better to have it caching some intermediate template results)

I will think it through.

About cache, normal practice is to use cache key or id...

Streaming and caching features are implemented in version 0.7. Please check it out.

Note that the new version will appear at maven central as soon as sonatype sync happens. This may require a week or so.
If you need the new features ultimately, simply install project to local maven repo using mvn install.

Why is not available outputstream api for processed template?

Thanks for the note!
I completely lost that point, sorry.

Will add it ASAP.

Now it's done: see processAndReturnInputStream method.

Why does method return InputStream? Why just not copy data to outstream like in example above? Because it is no deffirance copy data from file or from inputstream, if i need for example put data in response.

Makes sence... Will add soon, in .0.7.2.

P.S. It is very usefull library. Realy i didnt meet any another library, that works stable with docx templates. I hope you will impove this. Thank You!

That's nice! If you see an option of library promotion I would be pleased to listen.

OutputStream feature added