You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2019/04/13 12:57:20 UTC

svn commit: r1857473 - /poi/site/src/documentation/content/xdocs/encryption.xml

Author: fanningpj
Date: Sat Apr 13 12:57:20 2019
New Revision: 1857473

URL: http://svn.apache.org/viewvc?rev=1857473&view=rev
Log:
close POIFSFileSystem

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=1857473&r1=1857472&r2=1857473&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/encryption.xml (original)
+++ poi/site/src/documentation/content/xdocs/encryption.xml Sat Apr 13 12:57:20 2019
@@ -199,24 +199,25 @@ try {
      Apart of the CipherMode, the EncryptionInfo class provides further parameters to specify the cipher and
      hashing algorithm to be used.</p>
      <source>
-POIFSFileSystem fs = new POIFSFileSystem();
-EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
-// EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null);
+try (POIFSFileSystem fs = new POIFSFileSystem()) {
+  EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
+  // EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null);
 
-Encryptor enc = info.getEncryptor();
-enc.confirmPassword("foobaa");
+  Encryptor enc = info.getEncryptor();
+  enc.confirmPassword("foobaa");
 
-// 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);
+  // 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("...");
-fs.writeFilesystem(fos);
-fos.close();
+  // Write out the encrypted version
+  try (FileOutputStream fos = new FileOutputStream("...")) {
+    fs.writeFilesystem(fos);
+  }
+}
      </source>
      </section>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org