Author: kiwiwings
Date: Tue Oct 9 21:41:00 2018
New Revision: 1843348
URL: http://svn.apache.org/viewvc?rev=1843348&view=rev
Log:
Fix encrypted stream usage
Modified:
poi/site/src/documentation/content/xdocs/encryption.xml
Modified: poi/site/src/documentation/content/xdocs/encryption.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/encryption.xml?rev=1843348&r1=1843347&r2=1843348&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/encryption.xml (original)
+++ poi/site/src/documentation/content/xdocs/encryption.xml Tue Oct 9 21:41:00
2018
@@ -204,11 +204,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]