]> source.dussan.org Git - poi.git/commitdiff
catch IOException and rethrow as RuntimeException
authorJaven O'Neal <onealj@apache.org>
Mon, 23 Nov 2015 15:36:57 +0000 (15:36 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 23 Nov 2015 15:36:57 +0000 (15:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715850 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java

index e106c4c8f80eabfbab9c0a7bab6bc33f45445ee7..550c4d8b956c1a58889f7c20ebbf093e702d2da1 100644 (file)
@@ -24,21 +24,24 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
-import java.io.OutputStream;\r
 \r
 /**\r
  * @author Yegor Kozlov\r
  */\r
 public class XSLFTestDataSamples {\r
 \r
-    public static XMLSlideShow openSampleDocument(String sampleName) throws IOException {\r
+    public static XMLSlideShow openSampleDocument(String sampleName) {\r
         InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream(sampleName);\r
         try {\r
             return new XMLSlideShow(OPCPackage.open(is));\r
         } catch (Exception e) {\r
             throw new RuntimeException(e);\r
         } finally {\r
-            is.close();\r
+            try {\r
+                is.close();\r
+            } catch (IOException e) {\r
+                throw new RuntimeException(e);\r
+            }\r
         }\r
     }\r
 \r
@@ -46,7 +49,7 @@ public class XSLFTestDataSamples {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);\r
         try {\r
             doc.write(baos);\r
-        } catch (Exception e) {\r
+        } catch (IOException e) {\r
             throw new RuntimeException(e);\r
         }\r
         \r
@@ -57,8 +60,12 @@ public class XSLFTestDataSamples {
         } catch (Exception e) {\r
             throw new RuntimeException(e);\r
         } finally {\r
-            baos.close();\r
-            bais.close();\r
+            try {\r
+                baos.close();\r
+                bais.close();\r
+            } catch (IOException e) {\r
+                throw new RuntimeException(e);\r
+            }\r
         }\r
         \r
     }\r
index 92c30b62d5b92a74bf5bf89cec1bff85ada51eee..a307eaab7f75f580f20d7b85929beb9f31124d9d 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.poi.xslf.usermodel;
 \r
 import static org.junit.Assert.*;\r
 \r
+import java.io.IOException;\r
 import java.util.List;\r
 \r
 import org.apache.poi.xslf.XSLFTestDataSamples;\r
@@ -31,7 +32,7 @@ import org.junit.Test;
 public class TestXSLFSheet {\r
     \r
     @Test\r
-    public void testCreateShapes(){\r
+    public void testCreateShapes() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
         assertTrue(slide.getShapes().isEmpty());\r
@@ -58,8 +59,8 @@ public class TestXSLFSheet {
         assertSame(shape3, slide.getShapes().get(2));\r
         assertSame(shape4, slide.getShapes().get(3));\r
 \r
-        ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);\r
-        slide = ppt.getSlides().get(0);\r
+        XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);\r
+        slide = ppt2.getSlides().get(0);\r
         List<XSLFShape> shapes = slide.getShapes();\r
         assertEquals(4, shapes.size());\r
 \r
@@ -67,5 +68,8 @@ public class TestXSLFSheet {
         assertTrue(shapes.get(1) instanceof XSLFTextBox);\r
         assertTrue(shapes.get(2) instanceof XSLFConnectorShape);\r
         assertTrue(shapes.get(3) instanceof XSLFGroupShape);\r
+        \r
+        ppt.close();\r
+        ppt2.close();\r
     }\r
 }
\ No newline at end of file