poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fannin...@apache.org
Subject svn commit: r1818786 - /poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
Date Wed, 20 Dec 2017 12:15:35 GMT
Author: fanningpj
Date: Wed Dec 20 12:15:35 2017
New Revision: 1818786

URL: http://svn.apache.org/viewvc?rev=1818786&view=rev
Log:
use try with resources

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1818786&r1=1818785&r2=1818786&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Wed Dec 20 12:15:35
2017
@@ -617,10 +617,11 @@ public class XSSFWorkbook extends POIXML
         }
         
         
-        try {
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
             srcSheet.write(out);
-            clonedSheet.read(new ByteArrayInputStream(out.toByteArray()));
+            try (ByteArrayInputStream bis = new ByteArrayInputStream(out.toByteArray()))
{
+                clonedSheet.read(bis);
+            }
         } catch (IOException e){
             throw new POIXMLException("Failed to clone sheet", e);
         }
@@ -2366,18 +2367,19 @@ public class XSSFWorkbook extends POIXML
         
         Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
 
-        ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500);
-        ole10.writeOut(bos);
-        
-        try (POIFSFileSystem poifs = new POIFSFileSystem()) {
-            DirectoryNode root = poifs.getRoot();
-            root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray()));
-            root.setStorageClsid(ClassID.OLE10_PACKAGE);
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) {
+            ole10.writeOut(bos);
 
-            // TODO: generate CombObj stream
+            try (POIFSFileSystem poifs = new POIFSFileSystem()) {
+                DirectoryNode root = poifs.getRoot();
+                root.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray()));
+                root.setStorageClsid(ClassID.OLE10_PACKAGE);
 
-            try (OutputStream os = pp.getOutputStream()) {
-                poifs.writeFilesystem(os);
+                // TODO: generate CombObj stream
+
+                try (OutputStream os = pp.getOutputStream()) {
+                    poifs.writeFilesystem(os);
+                }
             }
         }
 



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


Mime
View raw message