Use try-with-resources in TestUtils 55/99355/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Jan 2022 10:35:08 +0000 (11:35 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Jan 2022 10:35:40 +0000 (11:35 +0100)
Eclipse is pointing out we should be managing resources properly, fix
that.

Change-Id: I34e8040bca7c5003e4830134ccc37d0cd44d2387
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
codec/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java

index dc1e980952d671860621abc5afeee4138a4cd3a3..13251a2f94316abb3c209df66bd352c01ab3997c 100644 (file)
@@ -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();
     }