/*
Soubory pro zaznamenani spatnych uzlu
 */
package octantKlient;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.sql.Time;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Filip Dvorak
 */
public class Soubory {
    
      public static void zapisDoSouboruSpatneUzly(String spatnyUzel, String vzdalenosti) {
        Writer souborLogu = null;
        try {
            //pro test na SERVERu
            //souborLogu = new BufferedWriter(new FileWriter("/var/www/html/bachsoft/public/methods/xdvora02/xdvora02logSpatneUzly.txt", true)); //true - pro dalsi zapis
            //pro TEST na lokalnim PC
            souborLogu = new BufferedWriter(new FileWriter("spatneUzly.txt",true)); 
        } catch (IOException ex) {
            Logger.getLogger(Log.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            souborLogu.write("OB " + spatnyUzel + " " + " Duvod : " + vzdalenosti + " " + "\n -------------------------------------------------------------- \n");
        } catch (IOException ex) {
            Log.zapisDoLogu(ex);
        } finally {
            try {
                souborLogu.close();
            } catch (IOException ex) {
                Log.zapisDoLogu(ex);
            }
        }

    }

    
    
        //metoda na smazani souboru pri zapnuti programu
    public static void smazSoubor() {
        try {
            //pro TEST na lokalnim PC
             Writer souborLogu = new BufferedWriter(new FileWriter("spatneUzly.txt"));
             Writer souborLoguNedostupne = new BufferedWriter(new FileWriter("xdvora02logNedostupneCile.txt"));
            //pro test na SERVERu
            // Writer souborLogu = new BufferedWriter(new FileWriter("/var/www/html/bachsoft/public/methods/xdvora02/xdvora02logSpatneUzly.txt"));
            souborLogu.write("");
            souborLoguNedostupne.write("");
        } catch (IOException ex) {
             Log.zapisDoLogu("Nepodarilo se smazat log soubor");
             Log.zapisDoLogu(ex);
        }
    }

    public static void nedostupnyCil(String spatnyUzel) {
        Writer souborLogu = null;
        Date cas = new Date();
        long cc = cas.getTime();
        
        try {
            //pro test na SERVERu
            //souborLogu = new BufferedWriter(new FileWriter("/var/www/html/bachsoft/public/methods/xdvora02/xdvora02logNedostupneCile.txt", true)); //true - pro dalsi zapis
            //pro TEST na lokalnim PC
            souborLogu = new BufferedWriter(new FileWriter("xdvora02logNedostupneCile.txt",true)); 
        } catch (IOException ex) {
            Logger.getLogger(Log.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {           
            souborLogu.write("Cas :" + cc +  "Cilovy uzel na adrese " + spatnyUzel + "neni dostupny " + " " + "\n -------------------------------------------------------------- \n");
        } catch (IOException ex) {
            Log.zapisDoLogu(ex);
        } finally {
            try {
                souborLogu.close();
            } catch (IOException ex) {
                Log.zapisDoLogu(ex);
            }
        }

        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}
