/*
 * 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 consoleapp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Vytvorte konzolovú aplikáciu, ktorá bude pracovať nasledovne. Aplikácia má
 * tri vstupné parametre, zadané na príkazovom riadku. Prvým parametrom je
 * zoznam znakov, ktoré treba nahradiť vo vstupnom súboru. Druhým parametrom je
 * zoznam znakov, za ktoré sa znaky z prvého zoznamu nahradia. Tretím parametrom
 * je cesta k súboru, v ktorom sa znaky budú nahradzovať. Výstup vypisujte na
 * štandardný výstup. Prvý a druhý parameter musia mať rovnakú dĺžku. Ak táto
 * podmienka nie je splnená, ukončite aplikáciu chybovým hlásením. *
 */
/**
 *
 * @author Pepcox
 */
public class Replacer {

    private String path = "";
    private char[] parameter1;
    private char[] parameter2;
    private File file;
    private String token;

    public Replacer(String param1, String param2, String paPath) {
        System.out.println("parameter1 : " + param1);
        System.out.println("parameter2 : " + param2);
        System.out.println("cesta : " + paPath);
        parameter1 = getCharField(param1);
        parameter2 = getCharField(param2);
        path = paPath;
        file = new File(path);
        token = ReadFile(file);
        replace();
        System.out.print(token);
    }

    public char[] getCharField(String retazec) {
        char[] a = new char[retazec.length()];
        a = retazec.toCharArray();
        return a;
    }

    public String ReadFile(File subor) {
        String fileContent = "";
        try {
            BufferedReader in = new BufferedReader(new FileReader(subor));
            String str;
            while ((str = in.readLine()) != null) {
                fileContent += " " + str + "\n";
            }
            in.close();
        } catch (IOException e) {
        }
        return fileContent;
    }

    public void replace() {
        for (int i = 0; i < parameter1.length; i++) {
            token = token.replace(parameter1[i], parameter2[i]);
            
        }
    }
}
