|
33 | 33 | import java.io.FileNotFoundException;
|
34 | 34 | import java.io.FileOutputStream;
|
35 | 35 | import java.io.IOException;
|
| 36 | +import java.io.InputStream; |
36 | 37 | import java.io.OutputStream;
|
37 | 38 | import java.io.Serializable;
|
38 | 39 | import java.util.Arrays;
|
@@ -155,13 +156,37 @@ else if (arg.startsWith("-")) {
|
155 | 156 | */
|
156 | 157 | public static ParameterTool fromPropertiesFile(String path) throws IOException {
|
157 | 158 | File propertiesFile = new File(path);
|
158 |
| - if (!propertiesFile.exists()) { |
159 |
| - throw new FileNotFoundException("Properties file " + propertiesFile.getAbsolutePath() + " does not exist"); |
| 159 | + return fromPropertiesFile(propertiesFile); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * Returns {@link ParameterTool} for the given {@link Properties} file. |
| 164 | + * |
| 165 | + * @param file File object to the properties file |
| 166 | + * @return A {@link ParameterTool} |
| 167 | + * @throws IOException If the file does not exist |
| 168 | + * @see Properties |
| 169 | + */ |
| 170 | + public static ParameterTool fromPropertiesFile(File file) throws IOException { |
| 171 | + if (!file.exists()) { |
| 172 | + throw new FileNotFoundException("Properties file " + file.getAbsolutePath() + " does not exist"); |
160 | 173 | }
|
161 |
| - Properties props = new Properties(); |
162 |
| - try (FileInputStream fis = new FileInputStream(propertiesFile)) { |
163 |
| - props.load(fis); |
| 174 | + try (FileInputStream fis = new FileInputStream(file)) { |
| 175 | + return fromPropertiesFile(fis); |
164 | 176 | }
|
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * Returns {@link ParameterTool} for the given InputStream from {@link Properties} file. |
| 181 | + * |
| 182 | + * @param inputStream InputStream from the properties file |
| 183 | + * @return A {@link ParameterTool} |
| 184 | + * @throws IOException If the file does not exist |
| 185 | + * @see Properties |
| 186 | + */ |
| 187 | + public static ParameterTool fromPropertiesFile(InputStream inputStream) throws IOException { |
| 188 | + Properties props = new Properties(); |
| 189 | + props.load(inputStream); |
165 | 190 | return fromMap((Map) props);
|
166 | 191 | }
|
167 | 192 |
|
|
0 commit comments