2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.util;
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;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
24 * Utility class for handling test resources.
26 * @author Björn Lange - Initial contribution
29 public final class ResourceUtil {
30 private ResourceUtil() {
34 * Gets the contents of a resource file as {@link String}.
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.
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"));