/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ctecinf;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 *
 * @author Cássio Conceição
 * @since 29/05/2019
 * @version 201905
 * @see http://ctecinf.com.br/
 */
public class Config {

    public static final String FILE_NAME = "config.properties";

    public static String get(String name) {

        Properties prop = new Properties();

        try (InputStream input = new FileInputStream(FILE_NAME)) {
            prop.load(input);
        } catch (IOException ex) {
            System.err.println(ex);
            return "";
        }

        if (prop.containsKey(name)) {
            return prop.getProperty(name);
        }

        return "";
    }

    public static void set(String name, String value) {

        Properties prop = new Properties();

        try (InputStream input = new FileInputStream(FILE_NAME)) {
            prop.load(input);
        } catch (IOException ex) {
            System.err.println(ex);
        }

        try (OutputStream output = new FileOutputStream(FILE_NAME)) {
            prop.setProperty(name, value);
            prop.store(output, null);
        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}
