From e201931864746dc2312aad39571bebc612686e68 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 18 Jan 2022 11:35:08 +0100 Subject: [PATCH] Use try-with-resources in TestUtils Eclipse is pointing out we should be managing resources properly, fix that. Change-Id: I34e8040bca7c5003e4830134ccc37d0cd44d2387 Signed-off-by: Robert Varga --- .../yangtools/yang/data/codec/gson/TestUtils.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/codec/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java b/codec/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java index dc1e980952..13251a2f94 100644 --- a/codec/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java +++ b/codec/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java @@ -36,19 +36,17 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public final class TestUtils { private TestUtils() { - throw new UnsupportedOperationException(); + // Hidden on purpose } static String loadTextFile(final File file) throws IOException { - final FileReader fileReader = new FileReader(file, StandardCharsets.UTF_8); - final BufferedReader bufReader = new BufferedReader(fileReader); - - String line = null; final StringBuilder result = new StringBuilder(); - while ((line = bufReader.readLine()) != null) { - result.append(line); + try (BufferedReader bufReader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) { + String line = null; + while ((line = bufReader.readLine()) != null) { + result.append(line); + } } - bufReader.close(); return result.toString(); } -- 2.36.6