]> git.basschouten.com Git - openhab-addons.git/blob
61b509254c5d7e587a0fb8038920b2855945d890
[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.mybmw.internal.util;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.BufferedReader;
18 import java.io.FileInputStream;
19 import java.io.IOException;
20 import java.io.InputStreamReader;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.mybmw.internal.utils.Constants;
24
25 /**
26  * The {@link FileReader} Helper Util to read test resource files
27  *
28  * @author Bernd Weymann - Initial contribution
29  */
30 @NonNullByDefault
31 public class FileReader {
32
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();
36             String sCurrentLine;
37
38             while ((sCurrentLine = br.readLine()) != null) {
39                 buf.append(sCurrentLine);
40             }
41             return buf.toString();
42         } catch (IOException e) {
43             // fail if file cannot be read
44             assertEquals(filename, Constants.EMPTY, "Read failute " + filename);
45         }
46         return Constants.UNDEF;
47     }
48 }