How can I save a org.docx4j.openpackaging.packages.WordprocessingMLPackage instance into ByteArrayInputStream, then It can be downloaded from server.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot save to a
ByteArrayInputStream… ever. AByteArrayInputStreamis anInputStreamand you don’t / can’t write to anInputStream.However you can write something to a
ByteArrayOutputStream, get the byte array, and create aByteArrayInputStreamwrapper for the array.(I’m assuming that there is a way to save one of those instances to an OutputStream or Writer …)
Well, my assumption was wrong, and
WordprocessingMLPackage‘s onlysavemethod saves to aFile. (I guess someone didn’t get the memo on how to design flexible I/O apis …)But the source code ( here ) offers some clues on how you could implement it yourself. The method is as follows:
It looks like you should be able to copy this code in a helper class, and tweak it to save to a
OutputStreamrather than (specifically) aFileOutputStream. Note that theSaveToZipFileclass has alternativesavemethods that write to anOutputStream.