package com.gordon_from_blumberg.utils;

/**
 * Copyright (c) 2016 Gordon from Blumberg
 * <p>
 * Project: Terrible snake
 *
 * @author: gordon
 * Created: 22:25 020 20.06.16
 */

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

public class ProperiesUtils {
    public static Properties getProperties(File file) {
        Properties properties = new Properties();

        try (FileInputStream inputStream = new FileInputStream(file)) {
            properties.load(inputStream);
            inputStream.close();
            return properties;

        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static String getProperty(Properties properties, String key) {
        String property = properties.getProperty(key);

        try {
            return new String(property.getBytes("ISO8859-1"));
        } catch(NullPointerException | UnsupportedEncodingException e) {
            System.out.print(e); //todo Use log
            return "";
        }
    }

    public static String getProperty(File file, String key) {
        return getProperty(getProperties(file), key);
    }
}

@@ -333,37 +333,365 @@
 s;%0A%0A
-public class ProperiesUtils %7B
+/**%0A * Util class for work with properties files%0A */%0Apublic class ProperiesUtils %7B%0A    private static final String PROPERTIES_ENCODING = %22ISO8859-1%22;%0A%0A    /**%0A     * Reads properties file%0A     *%0A     * @param file File with properties%0A     * @return Properties object%0A     * @throws RuntimeException if the IO exception is thrown during file reading%0A     */
 %0A   
@@ -716,19 +716,20 @@
 perties 
-get
+read
 Properti
@@ -1059,32 +1059,249 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Finds property in the passed properties object by the specified key%0A     * @param properties Properties object%0A     * @param key Property key%0A     * @return Found property value or empty string%0A     */%0A
     public stati
@@ -1426,237 +1426,295 @@
     
-try %7B%0A            return new String(property.getBytes(%22ISO8859-1%22))
+return property != null ?%0A                convert(property) :%0A                %22%22
 ;%0A    
+%7D%0A%0A
     
-%7D catch(NullPointerException %7C UnsupportedEncodingException e) %7B%0A            System.out.print(e); //todo Use log%0A            return %22%22;%0A        %7D
+/**%0A     * Finds property by the specified key in the specified file%0A     * @param file Properties file%0A     * @param key Property key%0A     * @return Found property value or empty string
 %0A    
-%7D%0A
+ */
 %0A   
@@ -1799,19 +1799,20 @@
 roperty(
-get
+read
 Properti
@@ -1832,11 +1832,255 @@
 );%0A    %7D
+%0A%0A    private static String convert(String string) %7B%0A        try %7B%0A            return new String(string.getBytes(PROPERTIES_ENCODING));%0A        %7D catch(UnsupportedEncodingException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D
 %0A%7D%0A

Refactor PropertiesUtils