import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Regroupement_FI { static public int fichiersort =0; static public PrintWriter fichierOut; public static void main(String[] args) throws IOException { Methode_FI.FicheNme(); PrintWriter fichierOutintLog = null; int indexInternet = -1; String strteste = null, s, str10 = "", strNd = null, strNcli = null, strProduit = null, strCliInt = ""; String lignOut = "", lignein = ""; int cpt = 0, cpt2 = 0, nbrclientInternet = 0, nbrcltinttraité = 0; char c = 0; int NTR = 0; // RandomAccessFile fichierfixe=null; List listClientFixe = new ArrayList(10); List listClientInt = new ArrayList(10); List lstnme = new ArrayList(10); // PrintWriter fichierOut = null; // PrintWriter fichierOut2 = null; // PrintWriter fichierOutint = null; boolean entrer = true; ClientFixe cfixe = null; ClientInternet cInt = null; int count = 0; MyProperties pr = new MyProperties(); listClientFixe = Methode_FI.ParcourDossierfixe(); listClientInt = Methode_FI.ParcourDossierint(); lstnme = Methode_FI.listnme(); try { FileInputStream is = new FileInputStream("config_FI.properties"); pr.load(is); pr.load(is); // Lire les fichiers a partire d’un répertoire File di = new File(pr.getProperty("input")); File fl[] = di.listFiles(); if (fl.length == 0) { PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(pr.getProperty("file-log") + "\\log" + MonDate.date_err() + ".dat")), true); out.print("Veuillez déposer les fichiers à traiter"); // System.out.println("le dossier ne contien aucun fichier "); out.close(); System.exit(0); } else { fichierOutintLog = new PrintWriter(new BufferedWriter( new FileWriter(pr.getProperty("file-log") + "\\Stat " + MonDate.date_err() + ".DAT"))); String dateDebut = MonDate.date("le début"); fichierOutintLog.print(dateDebut + "\n"); fichierOutintLog.println("Le Nombre de Fichier Input est: " + fl.length) ; //+ Methode_FI.listFichierInput.size()); for (int j = 0; j < fl.length; j++) { //System.out.println(fl[j].getName()); BufferedReader in = new BufferedReader( new FileReader(fl[j])); String fileOut = pr.getProperty("output") + "/" + fl[j].getName(); fichierOut = new PrintWriter(new BufferedWriter(new FileWriter(fileOut, true))); count = 0; while ((s = in.readLine()) != null) { str10 = ""; strNd = ""; strNcli = ""; strProduit = ""; for (int k = 0; k < s.length(); k++) { c = s.charAt(k); if (k <= 1) { str10 += c; } if (str10.equals("10")) { if ((90 < k) && (k < 115)) { strNcli += c; } if ((70 < k) && (k < 86)) { strNd += c; } if ((85 < k) && (k < 89)) { strProduit += c; } } if ((k == 37 && str10.equals("10") && entrer == true)) { String tr = ""; tr += c; NTR = Integer.parseInt(tr); // System.out.println(NTR); entrer = false; System.out.println("LA TRANCHE EST "+ NTR); } } if (str10.equals("10")) count++; if (count == 0) { ecrire(fileOut, s); fichiersort++; } if (strProduit == "INT" || "INT".equals(strProduit)) { String b = ""; strNcli = strNcli.trim(); if (strNcli.length() != 0) { // nclifixe si y a le ncli internet b = Methode_FI.Ficheexist1(strNcli,lstnme); } /// b = ""; //System.out.println(b); if ("".equals(b)) { //System.out // .println("int n'existe pas ds fichier nme"); // String str1 = s; ecrire(fileOut, s); while ((s = in.readLine()) != null) { // ecrire dans le fichier output String strtmp = ""; for (int k2 = 0; k2 < s.length(); k2++) { c = s.charAt(k2); if ((k2 < 2)) strtmp += c; } if ((strtmp.equals("90"))) { ecrire(fileOut, s); break; // fichier.close(); } else { // if (nok) ecrire(fileOut, s); } } } else { nbrcltinttraité++; //System.out.println("int existe"); boolean d = islienExiste(b, listClientFixe); if (!d) { ecrire(fileOut, s); } while ((s = in.readLine()) != null) { // ecrire dans le fichier output String strtmp = ""; for (int k2 = 0; k2 < s.length(); k2++) { c = s.charAt(k2); if ((k2 < 2)) strtmp += c; } if ((strtmp.equals("90"))) { if (!d) { ecrire(fileOut, s); } // fichierOut.println(s);// // ecrire la // fichier.close(); break; } else { if (!d) { ecrire(fileOut, s); } // if (nok) // fichierOut.println(s); } } } // } else { // // File f = new File(pr.getProperty("output") + "/" // + fl[j].getName()); // // // crée le fichier sortie // // if (f.exists()) { // fichierOut = new PrintWriter( // new BufferedWriter(new FileWriter(pr // .getProperty("output") // + "/" + fl[j].getName(), true))); // // } else { // // /System.out.println("FILE // // FILEFILE"+f.getName()); // // fichierOut = new PrintWriter( // new BufferedWriter(new FileWriter(pr // .getProperty("output") // + "/" + fl[j].getName()))); // fichierOut.println(s); // fichierOut.close(); // } } else if (count != 0) { String strInt = ""; if (strNcli.length() != 0) { // ncliint de nclifixe strInt = Methode_FI.Ficheexist(strNcli, strNd); } if (!"".equals(strInt)) { ecrire(fileOut, s); while ((s = in.readLine()) != null) { // ecrire dans le fichier output String strtmp = ""; for (int k2 = 0; k2 < s.length(); k2++) { c = s.charAt(k2); if ((k2 < 2)) strtmp += c; } if ((strtmp.equals("90"))) { ecrire(fileOut, s); break; // fichier.close(); } else { // if (nok) ecrire(fileOut, s); } } Iterator it = listClientInt.iterator(); String sttmp2 = ""; while (it.hasNext()) { ClientInternet clint = (ClientInternet) it .next(); String ncliInt = clint.NcliInt; ncliInt = ncliInt.trim(); if (ncliInt.equals(strInt) || strInt.equals(ncliInt)) { BufferedReader fichierfixetmp = new BufferedReader( new FileReader(clint.Lien)); //System.out.println("clint.Position : " // + clint.Position); for (int i = 0; i < clint.Position - 1; i++) { sttmp2 = fichierfixetmp.readLine(); // fichierOut.println(sttmp); } while ((sttmp2 = fichierfixetmp .readLine()) != null) { // ecrire dans le fichier output String strtmp = ""; for (int k2 = 0; k2 < sttmp2 .length(); k2++) { c = sttmp2.charAt(k2); if ((k2 < 2)) strtmp += c; } if ((strtmp.equals("90"))) { ecrire(fileOut, sttmp2); break; // fichier.close(); } else { // if (nok) ecrire(fileOut, sttmp2); } } fichierfixetmp.close(); } } } else { ecrire(fileOut, s); while ((s = in.readLine()) != null) { // ecrire dans le fichier output String strtmp = ""; for (int k2 = 0; k2 < s.length(); k2++) { c = s.charAt(k2); if ((k2 < 2)) strtmp += c; } if ((strtmp.equals("90"))) { ecrire(fileOut, s); break; // fichier.close(); } else { // if (nok) ecrire(fileOut, s); } } // fichierOut.close(); } } } fichierOut.close(); in.close();//20/07/2009 } } } catch (Exception e) { System.out.println("l'exeption :" + e); } finally { String datefin = MonDate.date("la fin"); fichierOutintLog.print("Traitement en cours de la tranche :" + NTR + "\n"); fichierOutintLog .println("le nombre de fichier internet traité " + nbrcltinttraité); fichierOutintLog.println("Le Nombre de Fichier Sortie est: " + fichiersort); datefin = MonDate.date("la fin"); fichierOutintLog.print(datefin + " \n"); fichierOutintLog.close(); } } private static boolean islienExiste(String strNcli, List listClientFixe) { boolean result = false; // System.out.println("strNcli : " + strNcli); for (int i = 0; i < listClientFixe.size(); i++) { ClientFixe clientFixe = (ClientFixe) listClientFixe.get(i); String ncliFixe = clientFixe.NcliFixe; ncliFixe = ncliFixe.trim(); strNcli = strNcli.trim(); //System.out.println("ncliFixe : " + ncliFixe); if (ncliFixe.equals(strNcli) || strNcli.equals(ncliFixe)) { //System.out.println("ncliFixe : " + ncliFixe); // System.out // .println("strNcli ************************************************: " // + strNcli); result = true; break; } } //System.out.println("result : " + result); return result; } public static void ecrire(String fichier, String chaine) { //try { // PrintWriter fichierOut = new PrintWriter(new BufferedWriter( // new FileWriter(fichier, true))); fichierOut.println(chaine); // } catch (IOException e) { // System.out.println("exception ecriture"); // } } }