Skip to content

Commit ede268a

Browse files
committed
PDFBOX-5660: use try-with-resources
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1924366 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1e0fddc commit ede268a

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,35 @@ void testCreatePDFA() throws Exception
9292
}
9393

9494
File signedFile = new File(signedPdfaFilename);
95-
BufferedReader br = new BufferedReader(
96-
new InputStreamReader(new FileInputStream(signedFile)));
97-
String line;
98-
boolean isIncrementalArea = false;
99-
Set<String> set = new HashSet<>();
100-
int linePos = 0;
101-
while ((line = br.readLine()) != null)
95+
try (BufferedReader br = new BufferedReader(
96+
new InputStreamReader(new FileInputStream(signedFile))))
10297
{
103-
++linePos;
104-
if (line.equals("%%EOF"))
98+
String line;
99+
boolean isIncrementalArea = false;
100+
Set<String> set = new HashSet<>();
101+
int linePos = 0;
102+
while ((line = br.readLine()) != null)
105103
{
106-
isIncrementalArea = true;
107-
set.clear(); // for cases with several revisions
108-
}
109-
if (!isIncrementalArea)
110-
{
111-
continue;
112-
}
113-
if (line.matches("\\d+ 0 obj"))
114-
{
115-
int pos = line.indexOf(" 0 obj");
116-
line = line.substring(0, pos);
117-
assertFalse(set.contains(line), "object '" + line
118-
+ " 0 obj' twice in incremental part of PDF at line " + linePos);
119-
set.add(line);
104+
++linePos;
105+
if (line.equals("%%EOF"))
106+
{
107+
isIncrementalArea = true;
108+
set.clear(); // for cases with several revisions
109+
}
110+
if (!isIncrementalArea)
111+
{
112+
continue;
113+
}
114+
if (line.matches("\\d+ 0 obj"))
115+
{
116+
int pos = line.indexOf(" 0 obj");
117+
line = line.substring(0, pos);
118+
assertFalse(set.contains(line), "object '" + line
119+
+ " 0 obj' twice in incremental part of PDF at line " + linePos);
120+
set.add(line);
121+
}
120122
}
121123
}
122-
br.close();
123124

124125
// https://docs.verapdf.org/develop/
125126
VeraGreenfieldFoundryProvider.initialise();

0 commit comments

Comments
 (0)