Author: kiwiwings
Date: Tue Oct 9 21:40:10 2018
New Revision: 1843347
URL: http://svn.apache.org/viewvc?rev=1843347&view=rev
Log:
Fix encrypted stream usage
Modified:
poi/site/publish/encryption.html
Modified: poi/site/publish/encryption.html
URL:
http://svn.apache.org/viewvc/poi/site/publish/encryption.html?rev=1843347&r1=1843346&r2=1843347&view=diff
==============================================================================
--- poi/site/publish/encryption.html (original)
+++ poi/site/publish/encryption.html Tue Oct 9 21:40:10 2018
@@ -384,11 +384,12 @@ EncryptionInfo info = new EncryptionInfo
Encryptor enc = info.getEncryptor();
enc.confirmPassword("foobaa");
-// Read in an existing OOXML file
-OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE);
-OutputStream os = enc.getDataStream(fs);
-opc.save(os);
-opc.close();
+// Read in an existing OOXML file and write to encrypted output stream
+// don't forget to close the output stream otherwise the padding bytes aren't
added
+try (OPCPackage opc = OPCPackage.open(new File("..."),
PackageAccess.READ_WRITE);
+ OutputStream os = enc.getDataStream(fs)) {
+ opc.save(os);
+}
// Write out the encrypted version
FileOutputStream fos = new FileOutputStream("...");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]