1 package com.proalpha.pds.projconf.properties;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.util.Properties;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 final class PropertiesUtils {
14 private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
16 private PropertiesUtils() {
28 public static void storeProperties(Properties properties, File outputFile)
throws IOException {
30 if (!outputFile.exists()) {
31 File parentDir = outputFile.getParentFile();
32 if ((parentDir !=
null) && (!parentDir.exists())) {
35 boolean created = outputFile.createNewFile();
39 logger.warn(
"The file {} already existed.", outputFile);
42 try (FileOutputStream out =
new FileOutputStream(outputFile);) {
43 properties.store(out,
"");
56 public static Properties loadProperties(File file)
throws IOException {
58 Properties properties =
new Properties();
61 throw new IllegalArgumentException(
"Properties file is null.");
65 throw new IllegalArgumentException(
66 String.format(
"%s file does not exits or is null.", file.getAbsolutePath()));
69 try (FileInputStream reader =
new FileInputStream(file)) {
70 properties.load(reader);