Skip to content

Commit 8d45764

Browse files
committed
PDFBOX-5660: close input, as suggested by Valery Bokov; closes #396
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1931229 13f79535-47bb-0310-9956-ffa450edef68
1 parent c4d1433 commit 8d45764

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,28 @@ private PDDocument createDocument(String title, PDFont font, String text) throws
5555
void testEscapeTitle() throws IOException
5656
{
5757
PDFTextStripper stripper = new PDFText2HTML();
58-
PDDocument doc = createDocument("<script>\u3042", new PDType1Font(FontName.HELVETICA),
59-
"<foo>");
60-
String text = stripper.getText(doc);
61-
62-
Matcher m = Pattern.compile("<title>(.*?)</title>").matcher(text);
63-
assertTrue(m.find());
64-
assertEquals("&lt;script&gt;&#12354;", m.group(1));
65-
assertTrue(text.contains("&lt;foo&gt;"));
58+
try (PDDocument doc = createDocument("<script>\u3042", new PDType1Font(FontName.HELVETICA), "<foo>"))
59+
{
60+
String text = stripper.getText(doc);
61+
62+
Matcher m = Pattern.compile("<title>(.*?)</title>").matcher(text);
63+
assertTrue(m.find());
64+
assertEquals("&lt;script&gt;&#12354;", m.group(1));
65+
assertTrue(text.contains("&lt;foo&gt;"));
66+
}
6667
}
6768

6869
@Test
6970
void testStyle() throws IOException
7071
{
7172
PDFTextStripper stripper = new PDFText2HTML();
72-
PDDocument doc = createDocument("t", new PDType1Font(FontName.HELVETICA_BOLD), "<bold>");
73-
String text = stripper.getText(doc);
74-
75-
Matcher bodyMatcher = Pattern.compile("<p>(.*?)</p>").matcher(text);
76-
assertTrue(bodyMatcher.find(), "body p exists");
77-
assertEquals("<b>&lt;bold&gt;</b>", bodyMatcher.group(1), "body p");
73+
try (PDDocument doc = createDocument("t", new PDType1Font(FontName.HELVETICA_BOLD), "<bold>"))
74+
{
75+
String text = stripper.getText(doc);
76+
77+
Matcher bodyMatcher = Pattern.compile("<p>(.*?)</p>").matcher(text);
78+
assertTrue(bodyMatcher.find(), "body p exists");
79+
assertEquals("<b>&lt;bold&gt;</b>", bodyMatcher.group(1), "body p");
80+
}
7881
}
7982
}

0 commit comments

Comments
 (0)