]> git.basschouten.com Git - openhab-addons.git/blob
1f313121add5c2da60279c40a24d213aa20f4a7a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ihc.internal.ws;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.BufferedReader;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.InputStreamReader;
21 import java.io.Reader;
22 import java.util.stream.Collectors;
23
24 /**
25  * Util class to load file content from resource files.
26  *
27  * @author Pauli Anttila - Initial contribution
28  */
29 public class ResourceFileUtils {
30     public static String getFileContent(String resourceFile) {
31         try (InputStream inputStream = ResourceFileUtils.class.getClassLoader().getResourceAsStream(resourceFile);
32                 Reader inputStreamReader = new InputStreamReader(inputStream);
33                 BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
34             return bufferedReader.lines().collect(Collectors.joining("\n"));
35         } catch (IOException e) {
36             fail("IOException reading xml file '" + resourceFile + "': " + e);
37         }
38         return "";
39     }
40 }