]> git.basschouten.com Git - openhab-addons.git/blob
656dfcb0c3b8c8efe0d0fff8858a883cf6bec2b4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.luftdateninfo.internal.util;
14
15 import static org.junit.jupiter.api.Assertions.*;
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.eclipse.jdt.annotation.Nullable;
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 @Nullable String readFileInString(String filename) {
34         try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "CP1252"));) {
35             StringBuffer buf = new StringBuffer();
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             assertTrue(false);
45         }
46         return null;
47     }
48 }