domenica 23 agosto 2015

ODI 11g-12c - Groovy come verificare che un file contenga una determinata stringa

Supponiamo di dover trovare una stringa all'interno di un file ed a seguito del risultato occorre bloccare o meno il processo in esecuzione.
Per bloccare l'esecuzione usciamo con un errore fittizio.

//Created by ODI Studio

package odi.sdk;
import java.sql.*;

import java.io.FileWriter;
import java.util.List;
import java.util.ArrayList;

 /************** export *************/

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.io.BufferedReader;
import java.io.FileReader;
import java.lang.Object;
import java.lang.Runtime;

import java.io.FileNotFoundException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class From_File{

    private static int   count=0;
     
       /** Please change these Parameters *************/    
 static String Find_Frase = "#V_1"
 static String File_input = "#V_FILE_INPUT" 
 static String Path_ril ="#V_PATH_EXPORT"; 
 static def file_output =  new File(Path_ril+"/EXP_LOG/AOG_FindInFile.log");
 static PrintWriter out2 = new PrintWriter(new FileWriter(file_output));
 
public static void main(String [] args) {


 /************** Please change these Parameters *************/
// def File_Input = File_input.replace("/","\\");
 def file_input =  new File(File_input);
 def s = 0

      out2.println("§*********************   Repository Info ******************")
      out2.println("§***  File Input: "+File_input)   
      out2.println("§***  File Output: "+file_output.getAbsolutePath())   
      out2.println("§**********************************************************")
      out2.println(" ");

   out2.println("******************************************************")
           out2.println("--------------Current Line --------------------------");
               
       BufferedReader br = null;

try 
{

String sCurrentLine;
br = new BufferedReader(new FileReader(file_input));
                        out2.println("--count "+ count);  

while ((sCurrentLine = br.readLine()) != null) {  
                        Pattern pat = Pattern.compile(Find_Frase);
       // Pattern pat = Pattern.compile(Find_Frase,Pattern.CASE_INSENSITIVE);
                        Matcher mat = pat.matcher(sCurrentLine);
                          if(mat.find()){

                              mat.start();
                              count++;         
out2.println("lookingAt(): "+mat.lookingAt()+" "+sCurrentLine+" --- "+Find_Frase);
out2.println("matches(): "+mat.matches()+" "+sCurrentLine+" --- "+Find_Frase);

                           if (count>0) { out2.println("--count "+ count);
                 out2.println("--CurrentLine OK"); 
  }else{
              out2.println("--count "+ count);  
       out2.println("--CurrentLine KO");  
out2.close();
exit();
}  
  } //if
}//while

             if (count==0){
   out2.println("--count "+ count);  
       out2.println("--CurrentLine KO");  
out2.close();
exit();
}  

} catch (IOException e_1) {
out2.println("Exception thrown  :" + e_1.getMessage());  
e_1.printStackTrace(out2);
out2.close();
exit();  
}catch(Exception  e_6){
out2.println("Exception thrown  :" + e_6.getMessage());  
e_6.printStackTrace(out2);
out2.close();
exit();      
                }   out2.println("*****************************************************************")
out2.println(" ");
out2.close(); 
}


// End Main

Nessun commento:

Posta un commento