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.mybmw.internal.util;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.BufferedReader;
18 import java.io.FileInputStream;
19 import java.io.IOException;
20 import java.io.InputStreamReader;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.mybmw.internal.utils.Constants;
26 * The {@link FileReader} Helper Util to read test resource files
28 * @author Bernd Weymann - Initial contribution
31 public class FileReader {
33 public static String readFileInString(String filename) {
34 try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8"));) {
35 StringBuilder buf = new StringBuilder();
38 while ((sCurrentLine = br.readLine()) != null) {
39 buf.append(sCurrentLine);
41 return buf.toString();
42 } catch (IOException e) {
43 // fail if file cannot be read
44 assertEquals(filename, Constants.EMPTY, "Read failute " + filename);
46 return Constants.UNDEF;