1 /*
2 * #%L
3 * wcm.io
4 * %%
5 * Copyright (C) 2018 wcm.io
6 * %%
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package io.wcm.qa.glnm.configuration;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.nio.charset.StandardCharsets;
25 import java.util.Collection;
26
27 import org.apache.commons.io.FileUtils;
28
29 import io.wcm.qa.glnm.exceptions.GaleniumException;
30
31 /**
32 * Utility methods for extracting string values from text files with one value per line.
33 *
34 * @since 1.0.0
35 */
36 public final class TextFileUtil {
37
38 private TextFileUtil() {
39 // do not instantiate
40 }
41
42 /**
43 * Read lines from file to String collection.
44 *
45 * @param file to read from
46 * @return list of strings with one string per line
47 * @since 3.0.0
48 */
49 public static Collection<String> parse(File file) {
50 try {
51 return FileUtils.readLines(file, StandardCharsets.UTF_8);
52 }
53 catch (IOException ex) {
54 throw new GaleniumException("when trying to parse text file: ", ex);
55 }
56 }
57
58 /**
59 * Read lines from file to String collection.
60 *
61 * @param filePath to read from
62 * @return list of strings with one string per line
63 * @since 3.0.0
64 */
65 public static Collection<String> parse(final String filePath) {
66 return parse(new File(filePath));
67 }
68
69 }