poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1843348 - /poi/site/src/documentation/content/xdocs/encryption.xml
Date Tue, 09 Oct 2018 21:41:00 GMT
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: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message