diff options
author | Dominik Stadler <centic@apache.org> | 2019-12-15 14:53:11 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2019-12-15 14:53:11 +0000 |
commit | 1a5cec89d8d36f2a7cd5643b221befd57fa515b7 (patch) | |
tree | 6a6719f33761c08a719599393ca310eafcb7834e /src/scratchpad/testcases/org/apache | |
parent | 2748844549b50dc11e8ef19dcd506c820c1a1e19 (diff) | |
download | poi-1a5cec89d8d36f2a7cd5643b221befd57fa515b7.tar.gz poi-1a5cec89d8d36f2a7cd5643b221befd57fa515b7.zip |
Replace manual close with try-with-resources
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache')
6 files changed, 23 insertions, 44 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java index 69f61e29fb..a1db11c170 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java @@ -134,11 +134,8 @@ public final class TestVisioExtractor { } private VisioTextExtractor openExtractor(String fileName) throws IOException { - InputStream is = _dgTests.openResourceAsStream(fileName); - try { + try (InputStream is = _dgTests.openResourceAsStream(fileName)) { return new VisioTextExtractor(is); - } finally { - is.close(); } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java index 959079a758..8c4edf564c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java +++ b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java @@ -166,9 +166,9 @@ public final class TestCompressedRTF { msg = new HMEFMessage(is); } - MAPIAttribute attr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED); - assertNotNull(attr); - MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute) attr; + MAPIAttribute attr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED); + assertNotNull(attr); + MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute)attr; final byte[] expected; try (InputStream stream = _samples.openResourceAsStream("quick-contents/message.rtf")) { @@ -196,7 +196,7 @@ public final class TestCompressedRTF { } // By String - String expString = new String(expected, StandardCharsets.US_ASCII); + String expString = new String(expected, StandardCharsets.US_ASCII); String decompStr = rtfAttr.getDataString(); assertEquals(expString.length(), decompStr.length()); assertEquals(expString, decompStr); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java b/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java index 90fb3ad814..0ec92bb6a2 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java @@ -44,12 +44,9 @@ public class HSLFTestDataSamples { } public static HSLFSlideShow getSlideShow(String fileName) throws IOException { - InputStream is = openSampleFileStream(fileName); - try { - return new HSLFSlideShow(is); - } finally { - is.close(); - } + try (InputStream is = openSampleFileStream(fileName)) { + return new HSLFSlideShow(is); + } } /** diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java index a8060e7d3a..ffecf2a58a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java @@ -45,31 +45,22 @@ public final class TestEncryptedFile { @Test(expected=EncryptedPowerPointFileException.class) public void testLoadEncrypted1() throws IOException { - InputStream is = slTests.openResourceAsStream("Password_Protected-hello.ppt"); - try { + try (InputStream is = slTests.openResourceAsStream("Password_Protected-hello.ppt")) { new HSLFSlideShowImpl(is).close(); - } finally { - is.close(); - } + } } @Test(expected=EncryptedPowerPointFileException.class) public void testLoadEncrypted2() throws IOException { - InputStream is = slTests.openResourceAsStream("Password_Protected-np-hello.ppt"); - try { + try (InputStream is = slTests.openResourceAsStream("Password_Protected-np-hello.ppt")) { new HSLFSlideShowImpl(is).close(); - } finally { - is.close(); - } + } } @Test(expected=EncryptedPowerPointFileException.class) public void testLoadEncrypted3() throws IOException { - InputStream is = slTests.openResourceAsStream("Password_Protected-56-hello.ppt"); - try { + try (InputStream is = slTests.openResourceAsStream("Password_Protected-56-hello.ppt")) { new HSLFSlideShowImpl(is).close(); - } finally { - is.close(); - } + } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java index 7ce0f6cbd1..e9eff122ab 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java @@ -67,16 +67,13 @@ public final class TestCurrentUserAtom { @Test(expected = EncryptedPowerPointFileException.class) public void readEnc() throws Exception { - POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(encFile)); - - try { - new CurrentUserAtom(fs.getRoot()); - assertTrue(true); // not yet failed - - new HSLFSlideShowImpl(fs).close(); - } finally { - fs.close(); - } + + try (POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(encFile))) { + new CurrentUserAtom(fs.getRoot()); + assertTrue(true); // not yet failed + + new HSLFSlideShowImpl(fs).close(); + } } @Test diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java index f60b010ef7..fc6ac11bc1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -366,12 +366,9 @@ public final class TestPictures { expectImages(docA, 1); HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA); - - OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc"); - try { + + try (OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) { docB.write(out); - } finally { - out.close(); } expectImages(docB, 1); |