]> source.dussan.org Git - poi.git/commitdiff
use try with resources
authorPJ Fanning <fanningpj@apache.org>
Wed, 20 Dec 2017 12:15:35 +0000 (12:15 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 20 Dec 2017 12:15:35 +0000 (12:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1818786 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

index aa1ffd20d2168cf811a2698681a717238fa4fb14..bb8e2be2b3e792891d78d8bb1598d28d47133a16 100644 (file)
@@ -617,10 +617,11 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
         }
         
         
-        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 POIXMLDocument implements Workbook {
         
         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);
+                }
             }
         }