Advertisement
haazee

LogReaderT1.java

Aug 16th, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.regex.*;
  3. import java.util.Date;
  4. import java.util.ArrayList;
  5.  
  6. public class LogReaderT1 {
  7.  
  8.     void runTest(String fileName){
  9.         ArrayList<String> logRecords=new ArrayList<String>();
  10.         BufferedReader br;
  11.         String nextRec;
  12.         long start,end;
  13.        
  14.         start=System.currentTimeMillis();
  15.        
  16.         try {
  17.             br = new BufferedReader(new FileReader(fileName));
  18.             while( (nextRec=br.readLine()) != null){
  19.                 logRecords.add(nextRec);
  20.             }
  21.             br.close();
  22.         } catch(IOException ex) {
  23.            
  24.         } finally {
  25.         }
  26.        
  27.         end=System.currentTimeMillis();
  28.         System.out.println(logRecords.size());
  29.         System.out.println("Elapsed time: "+(end-start)+"ms");
  30.        
  31.         int n1=0;
  32.         int n2=0;
  33.        
  34.         start=System.currentTimeMillis();
  35.         Pattern pat=Pattern.compile("^(.{11})\\s(\\d\\d:\\d\\d:\\d\\d)\\s(\\S+)\\s(\\w+\\.\\w+)\\s(\\w+):\\s+(ACCEPT|REJECT|DROP)\\s+(.*$)" );
  36.         for(String s: logRecords){
  37.             Matcher mat=pat.matcher(s);
  38.             if(mat.matches()){
  39.                 n1++;
  40.             } else {
  41.                 n2++;
  42.             }
  43.         }
  44.         System.out.println("Known:"+n1+"  unknown:"+n2);
  45.         end=System.currentTimeMillis();
  46.         System.out.println("Elapsed time: "+(end-start)+"ms");
  47.        
  48.     }
  49.    
  50.     /**
  51.      * @param args
  52.      */
  53.     public static void main(String[] args) {
  54.         // TODO Auto-generated method stub
  55.         LogReaderT1 l=new LogReaderT1();
  56.         l.runTest("/home/haazee/kern.log");
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement