package io.github.mattshen.dbkit.cli.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


public class PropertiesHolder {

    private static Logger LOG = LoggerFactory.getLogger(PropertiesHolder.class);

    private static Properties props = null;

    private static File getFileClassPath(String path) {
        ClassLoader classLoader = PropertiesHolder.class.getClassLoader();
        return new File(classLoader.getResource(path).getFile());
    }

    public static void loadConfig() {
        try (FileInputStream input = new FileInputStream(getFileClassPath("jdbc.properties"))) {
            Properties tmp = new Properties();
            tmp.load(input);
            props = tmp;
        } catch (IOException e) {
           LOG.error("cannot read jdbc.properties", e);
        }
    }

    public static void printConfig() {
        if (props != null) {
            props.list(System.out);
        } else {
            LOG.warn("not initialized");
        }
    }

    public static Properties getProps() {
        return props;
    }

}

@@ -112,20 +112,27 @@
 java.io.
-File
+IOException
 ;%0Aimport
@@ -140,20 +140,16 @@
 java.io.
-File
 InputStr
@@ -157,36 +157,8 @@
 am;%0A
-import java.io.IOException;%0A
 impo
@@ -349,30 +349,29 @@
 ;%0A%0A    p
-rivate
+ublic
  static 
 File get
@@ -366,41 +366,24 @@
 tic 
-File getFileClassPath(String path
+void loadConfig(
 ) %7B%0A
@@ -469,184 +469,64 @@
     
-return new File(classLoader.getResource(path).getFile());%0A    %7D%0A%0A    public static void loadConfig() %7B%0A        try (FileInputStream input = new FileInputStream(getFileClassPath
+try (InputStream input = classLoader.getResourceAsStream
 (%22jd
@@ -541,17 +541,16 @@
 rties%22))
-)
  %7B%0A     

fix properties file load problem