]> git.basschouten.com Git - openhab-addons.git/blob
6b7260d41265327ff243a94bd6d167033709a74f
[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.mielecloud.internal.util;
14
15 import java.io.BufferedReader;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.io.InputStreamReader;
19 import java.util.stream.Collectors;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22
23 /**
24  * Utility class for handling test resources.
25  *
26  * @author Björn Lange - Initial contribution
27  */
28 @NonNullByDefault
29 public final class ResourceUtil {
30     private ResourceUtil() {
31     }
32
33     /**
34      * Gets the contents of a resource file as {@link String}.
35      *
36      * @param resourceName The resource name (path inside the resources source folder).
37      * @return The file contents.
38      * @throws IOException if reading the resource fails or it cannot be found.
39      */
40     public static String getResourceAsString(String resourceName) throws IOException {
41         InputStream inputStream = ResourceUtil.class.getResourceAsStream(resourceName);
42         try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
43             return reader.lines().collect(Collectors.joining("\n"));
44         }
45     }
46 }