catch IOException and rethrow as RuntimeException
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715850 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e10c4f0f6
commit
7af82a3de2
@ -24,21 +24,24 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class XSLFTestDataSamples {
|
public class XSLFTestDataSamples {
|
||||||
|
|
||||||
public static XMLSlideShow openSampleDocument(String sampleName) throws IOException {
|
public static XMLSlideShow openSampleDocument(String sampleName) {
|
||||||
InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream(sampleName);
|
InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream(sampleName);
|
||||||
try {
|
try {
|
||||||
return new XMLSlideShow(OPCPackage.open(is));
|
return new XMLSlideShow(OPCPackage.open(is));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ public class XSLFTestDataSamples {
|
|||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
||||||
try {
|
try {
|
||||||
doc.write(baos);
|
doc.write(baos);
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +60,12 @@ public class XSLFTestDataSamples {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
baos.close();
|
try {
|
||||||
bais.close();
|
baos.close();
|
||||||
|
bais.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
@ -31,7 +32,7 @@ import org.junit.Test;
|
|||||||
public class TestXSLFSheet {
|
public class TestXSLFSheet {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateShapes(){
|
public void testCreateShapes() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertTrue(slide.getShapes().isEmpty());
|
assertTrue(slide.getShapes().isEmpty());
|
||||||
@ -58,8 +59,8 @@ public class TestXSLFSheet {
|
|||||||
assertSame(shape3, slide.getShapes().get(2));
|
assertSame(shape3, slide.getShapes().get(2));
|
||||||
assertSame(shape4, slide.getShapes().get(3));
|
assertSame(shape4, slide.getShapes().get(3));
|
||||||
|
|
||||||
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
||||||
slide = ppt.getSlides().get(0);
|
slide = ppt2.getSlides().get(0);
|
||||||
List<XSLFShape> shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals(4, shapes.size());
|
assertEquals(4, shapes.size());
|
||||||
|
|
||||||
@ -67,5 +68,8 @@ public class TestXSLFSheet {
|
|||||||
assertTrue(shapes.get(1) instanceof XSLFTextBox);
|
assertTrue(shapes.get(1) instanceof XSLFTextBox);
|
||||||
assertTrue(shapes.get(2) instanceof XSLFConnectorShape);
|
assertTrue(shapes.get(2) instanceof XSLFConnectorShape);
|
||||||
assertTrue(shapes.get(3) instanceof XSLFGroupShape);
|
assertTrue(shapes.get(3) instanceof XSLFGroupShape);
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
|
ppt2.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user