JavaAgent to search CSV File for appLog.nsf Docs


/**
 * Copyright 2012 Dököll Solutions, Inc.
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 *
 *
 * @AppName: Docu.nsf
 * Program: ComDataGrab.java
 * Created from Copy: 2012.28.6.00.AM
 * 
 */
import java.io.BufferedReader;  
import java.io.BufferedWriter;
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;
import java.io.FileReader;  
import java.io.IOException;  
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.StringTokenizer;  


/** 
 * @author Dököll Solutions, Inc.
 * @version 2012.28.6.00.AM
 * 
 * @param args 
 * @throws FileNotFoundException 
*/  
public class ComDataGrab {  
	
    public static void main(String[] args) throws FileNotFoundException { 
        // TODO Auto-generated method stub  
    	BufferedWriter writer = null; 
    	//Grab file created by LotusScript Agent (SearchHttpStringInLog:2012.09.08.2.02.AM)
       //fileName="C:/temp/TXT_DATA/LOGNSFMULTERRORSTYPE.csv";  
       String fileName="C:/temp/CSV_DATA/LOGNSFMULTERRORSTYPE.csv";  
  
        //Write the results of the file into this path as a new CSV
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:/temp/CSV_DATA/BULK_CSV_COM_DATA_SPLIT.csv")));
        //entering Try Catch
        
        try {    
        	
        BufferedReader br = new BufferedReader( new FileReader(fileName));  
        //Set up tokenPositions for file in question, based on spaces in fileLine
            StringTokenizer stringTokenizer = null;   
            //declare and initialize counters for both the number of tokens found
            //and the number of lines retrieved
            int lineNumber = 0, tokenNumber = 0;    

		//Create ColumNames for the CSV file
		System.out.println("ComDataGrab Creating columns, please wait...");

			
			writer.append("FileDate");
			writer.append(", ");
			writer.append("FileTime");
			writer.append(", ");
			writer.append("ErrorAmPm");			
			writer.append(", ");
			writer.append("ErrorFrag");
			writer.append(", ");
			writer.append("ErrorRequest");
			writer.append(", ");
			writer.append("ErrorOrigin");
			writer.append(", ");
			writer.append("ErrorDummy");	
			writer.append(", ");
			writer.append("ErrorAt");	
			writer.append(", ");
			writer.append("ErrorDescrip");	
			writer.append(", ");
			writer.append("ErrorLang");	
			writer.append(", ");
			writer.append("ErrorNum");	
		//go to next line,prepare to load records t oclumns...
			writer.append("\r\n");
		//Connect ColumNames to records
		System.out.println("ComDataGrab Columns created, adding records to columns...");		
           //run through file and read line by line
            while( (fileName = br.readLine()) != null)    
            {    
            //...
                if(lineNumber++ == 0)  
                   continue;                  
                stringTokenizer = new StringTokenizer(fileName);    

            //set up array of String values to add to columns
                String[] myString = null;

            //run though until no more spaces found in fileLine
                while(stringTokenizer.hasMoreTokens())    
                {                   	
           //load myString[x] in conjunction to each space (column)
                	
                	lineNumber++;               	
                	myString = fileName.split("[(\\s\\)]");

                	//write the array into myString variable
                	writer.write(myString[0].trim() + ", " + myString[1].trim()  + ", " + myString[2].trim() +", " + myString[3].trim() + ", " + myString[4].trim()  + ", " + myString[5].trim() +", " + myString[6].trim()+", " + myString[7].trim()+", " + myString[8].trim()+", " + myString[9].trim()+", " + lineNumber+"\n");
                	
                	//increment tokenNumber
                    tokenNumber++; 
                    //TO DO: Revive this console item for testing purposes
                    stringTokenizer.nextToken(); //

                }    
 

                //clear tokenNumber    
                tokenNumber = 0;    

            } 
            //flush/close writer
            writer.flush();
            writer.close();

            System.out.print("ComDataGrab Agent Inserted Data to CSV file..."); 
            
        } catch (FileNotFoundException e) {    
            // TODO Auto-generated catch block    
            e.printStackTrace();    
        } catch (IOException e) {    
            // TODO Auto-generated catch block    
            e.printStackTrace();    
        }
    }
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...