package kr.jm.utils.helper;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;

public class JMResources {

	public static URL getResourceURL(String pathInClassPath) {
		return ClassLoader.getSystemResource(pathInClassPath);
	}

	public static URI getResourceURI(String pathInClassPath) {
		try {
			return getResourceURL(pathInClassPath).toURI();
		} catch (URISyntaxException e) {
			e.printStackTrace();
			return null;
		}
	}

	// can't instantiate java.io.File object from file in jar
	@Deprecated
	public static File getResourceFile(String pathInClassPath) {
		return new File(getResourceURI(pathInClassPath));
	}

	public static InputStream getResourceInputStream(String pathInClassPath) {
		try {
			return getResourceURL(pathInClassPath).openStream();
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static Properties getProperties(String pathInClassPath) {
		Properties properties = new Properties();
		try {
			InputStream is = ClassLoader
					.getSystemResourceAsStream(pathInClassPath);
			properties.load(is);
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
			return properties;
		}
		return properties;
	}

	public static Properties getProperties(File propertiesFile) {
		Properties properties = new Properties();
		try {
			BufferedReader reader = new BufferedReader(new FileReader(
					propertiesFile));
			properties.load(reader);
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
			return properties;
		}
		return properties;
	}

	public static boolean saveProperties(Properties inProperties,
			File saveFile, String comment) {
		try {
			if (!saveFile.exists()) {
				saveFile.getParentFile().mkdirs();
				saveFile.createNewFile();
			}
			BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile));
			inProperties.store(writer, comment);
			writer.close();
			return true;
		} catch (IOException ex) {
			ex.printStackTrace();
			return false;
		}

	}

}

@@ -323,16 +323,107 @@
 rties;%0A%0A
+import kr.jm.utils.exception.JMExceptionManager;%0Aimport lombok.extern.slf4j.Slf4j;%0A%0A@Slf4j%0A
 public c
@@ -720,34 +720,89 @@
 e) %7B%0A%09%09%09
-e.printStackTrace(
+JMExceptionManager.logException(log, e, %22getResourceURI%22, pathInClassPath
 );%0A%09%09%09re
@@ -1181,34 +1181,97 @@
 e) %7B%0A%09%09%09
-e.printStackTrace(
+JMExceptionManager.logException(log, e, %22getResourceInputStream%22, pathInClassPath
 );%0A%09%09%09re
@@ -1559,34 +1559,88 @@
 e) %7B%0A%09%09%09
-e.printStackTrace(
+JMExceptionManager.logException(log, e, %22getProperties%22, pathInClassPath
 );%0A%09%09%09re
@@ -1967,26 +1967,79 @@
 %0A%09%09%09
-e.printStackTrace(
+JMExceptionManager.logException(log, e, %22getProperties%22, propertiesFile
 );%0A%09
@@ -2474,35 +2474,104 @@
 on e
-x
 ) %7B%0A%09%09%09
-ex.printStackTrace(
+JMExceptionManager.logException(log, e, %22saveProperties%22, inProperties, saveFile, comment
 );%0A%09

apply JMExceptionManager