Page 2 of 20 FirstFirst 123412 ... LastLast
Results 21 to 40 of 395
  1. #21
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

  2. #22
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, easy way to solve this is, change the log file with a space between number and string. Like this,

    Java Code:
    192.158.5.9 kjnkjnkn
    192.158.5.9 kasasdas
    192.158.5.9 asdsad
    192.158.5.9 sadasdsad
    192.158.5.9 sadsad
    192.158.5.9 rtertre
    192.158.5.9 rtret
    192.158.5.9 cbvv
    192.158.5.9 cvbnghh
    192.158.5.9 fghfgn
    192.158.5.9 tyty
    Or you have to edit the code, to handle all spaces. But it's not easy.

    I'm worried how it happened if it's a log file. Log file should have quite same pattern. In your file I found tab spaces, character spaces an mix of them too.

    The above file format works perfectly on my code.

  3. #23
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    it is working for spaces,but my log file i have use Tab ,so how can i do for tab.
    Plz help me

  4. #24
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Change the split regex to tab space.

    Java Code:
        private void doProcessing(String strr) {
            String newStr = strr.split("\t")[0];
            removeDuplicates(newStr);
        }

  5. #25
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    thxs it is working for tab..

  6. #26
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    can i count how many time 192.158.5.9 is present in log file..

  7. #27
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  8. #28
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    All occurrence IPs

  9. #29
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  10. #30
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Thxs for solution..

  11. #31
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  12. #32
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    yes..But i have a problem to impliment your code in my main code..Can you help me for impliment.

    If yes then i post code formate..

  13. #33
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  14. #34
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    ok

    My Code formate is..In this .java file no Main class..
    Java Code:
    public  void run(){
      
    	   Socket  server  = null;
    
           String clientName ="";
           String serverName ="";
           String Method; 
           String  host;
           URL url;
             
           String s;
           String sp;
           String s1;
           String s2;
           String s3;
           String s4;
           String s5;
           String s6;
    
           HttpRequestHdr request = new HttpRequestHdr();
           HttpReplyHdr   reply   = new HttpReplyHdr();
       
    	   boolean documentInCache = false;
    	   boolean serverFilesMayBeCached = false;
    	   DocumentInfo documentInfo;
    	   
    	   File file = null;					
    	   FileOutputStream fileToCache = null;
       
    	   
    	//   HttpURLConnection con = null;
    
    	   try {
    
    		   /*
                * Read HTTP Server Request from client 
                */
               request.parse(client.getInputStream());
               clientName = client.getInetAddress().getHostAddress();
     	   
               url = new URL( request.url );
    
               Method= request.method;
               int   port = url.getPort();
               int port1=url.getPort();
            if(port==-1)
            {
               port = 80;
            }
    
            s=String.valueOf(port);
    
            sp=String.valueOf(port1);
    	         
            InetAddress p = InetAddress.getByName(url.getHost());
    
            
            mainFrame.updateLog( ""  + clientName + "--->" +p.getHostAddress()+ "-" + Method+ " " + request.url+":" +port +"");
    	    
    
            synchronized(serversAccessibleWOProxy) 
    	           {
    				   if(!serversAccessibleWOProxy.containsKey(url.getHost())) 
    					   serverFilesMayBeCached = true;
    			   }
    			   
    			   synchronized(cache)
    			   {
    				  if(serverFilesMayBeCached &&
    				     !request.pragmaNoCache &&
    				     request.ifModifiedSince.equals("") &&
    				  	 cache.containsKey(url))
    				  {
    					  documentInCache = true;
    					  documentInfo = (DocumentInfo)cache.get(url);
    				  }
    				  else documentInfo = null;
    			   }
    
    			   
    			   
    		  if(documentInCache)
    		   {
    			   synchronized (documentInfo) 
    			   {
    				   File cachedFile = new File(config.getCacheDirectory(),
    										      documentInfo.getFileName());
    
    				   if (cachedFile.exists()) 
    			  	   {
    					
    					   synchronized (hits) 
    					   {
    						   hits = new Integer(hits.intValue()+1);
    					
    					   }
    					   documentInfo.incrementReferences();
    					   	
    					   FileInputStream in = new FileInputStream(cachedFile);
    					   OutputStream out = client.getOutputStream();
    					   
    					   byte data[] = new byte[2000];
    					   int count;
    					   while (-1 < ( count  = in.read(data))) 
    					   {
    						   out.write(data,0,count);
    						   Thread.yield(); // Remember this is multi-threaded
    					   }
    					   
    					   try {out.flush();} catch (Exception ef1){}
    					   try {in.close();} catch (Exception e){} 
    					   try {client.close();} catch (Exception e){}
    					   return;
    				   }
    			   }
    		   }
    	   
    			   
    		   try 
               {
            	   String spac="	";
            	   String spacpo=":";
            	   String spacp="-";
           	   
                   Date now = new Date();
                   DateFormat df =  DateFormat.getDateInstance();
                   DateFormat df1 = DateFormat.getDateInstance(DateFormat.MEDIUM);
                   String s11= df1.format(now);
                   String str3=s11;
                
                    str3 += "_proxy.log";
        			
                    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong"));
    
                    int hour12 = cal.get(Calendar.HOUR);            // 0..11
                    int hour24 = cal.get(Calendar.HOUR_OF_DAY);     // 0..23
                    int min = cal.get(Calendar.MINUTE);             // 0..59
                    int sec = cal.get(Calendar.SECOND);             // 0..59
                    int ms = cal.get(Calendar.MILLISECOND);         // 0..999
                    int ampm = cal.get(Calendar.AM_PM);             // 0=AM, 1=PM
    
            		s4=Integer.toString(hour24);
            	    s5=Integer.toString(min);
            	    s6=Integer.toString(sec);
    
            	FileWriter fstream = new FileWriter("./" +str3, true);//handling for file
    
            	BufferedWriter out = new BufferedWriter(fstream);
    
            	FileReader fr = new FileReader("./" +str3);
                BufferedReader br = new BufferedReader(fr);
                  
                String str;
               
            	
                
                
                while((str = br.readLine()) != null)
               	
          		//System.out.println(str);
               
            	out.write(clientName);
                out.write(spac);
                out.write(p.getHostAddress());
                out.write(spac);
                out.write(Method);
                out.write(spac);
                out.write(request.url);
                out.write(spacpo);
                out.write(s);
                out.write(spac);
                  
                out.write(s4);
                out.write(spacpo);
                out.write(s5);
                out.write(spacpo);
                out.write(s6);
                  
                out.newLine();
                out.flush();
    
               }
    Plz help me

  15. #35
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  16. #36
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    From here...

    Java Code:
    FileReader fr = new FileReader("./" +str3);
    BufferedReader br = new BufferedReader(fr);

  17. #37
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Mir View Post
    From here...

    Java Code:
    [COLOR="DarkGreen"]FileReader fr = new FileReader("./" +str3);
    BufferedReader br = new BufferedReader(fr);
    [/COLOR]


    Replace the above code with this.

    Java Code:
            FileReader fr = null;
            str = new ArrayList<String>();
            try {
                fr = new FileReader("./" +str3);
                BufferedReader br = new BufferedReader(fr);
                
                String temp;
                
                while((temp = br.readLine()) != null) {
                    doProcessing(temp);
                }
                printResult();
            } 
            catch (IOException ex) {
                Logger.getLogger(Completed.class.getName()).log(Level.SEVERE, null, ex);
            }        
            finally {
                try {
                    fr.close();
                } catch (IOException ex) {
                    Logger.getLogger(Completed.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

  18. #38
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    just i check it

  19. #39
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Define the array list in class level, just after the class declaration. As follows,

    Java Code:
    private ArrayList<String> str;

  20. #40
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Here some error :--
    After add
    private ArrayList<String> str;

    Java Code:
       doProcessing(temp);
    printResult();
    Logger.getLogger(Completed.class.getName()).log(Level.SEVERE, null, ex);
    Logger.getLogger(Completed.class.getName()).log(Level.SEVERE, null, ex);
    In these error showing...

    Java Code:
    Exception in thread "Thread-3" java.lang.Error: Unresolved compilation problems: 
    	The method doProcessing(String) is undefined for the type Proxy
    	The method printResult() is undefined for the type Proxy
    	Logger cannot be resolved
    	Completed cannot be resolved to a type
    	Level cannot be resolved
    	Logger cannot be resolved
    	Completed cannot be resolved to a type
    	Level cannot be resolved
    
    	at proxy.Proxy.run(Proxy.java:230)

Page 2 of 20 FirstFirst 123412 ... LastLast

Similar Threads

  1. Must Read.....
    By sanjeevtarar in forum Forum Lobby
    Replies: 10
    Last Post: 03-03-2010, 07:16 PM
  2. how to read a form with JFS
    By crispy in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 05-01-2008, 03:07 PM
  3. Read file
    By tajinvillage in forum Threads and Synchronization
    Replies: 0
    Last Post: 01-29-2008, 09:10 AM
  4. How to read the following
    By rrp in forum New To Java
    Replies: 0
    Last Post: 12-03-2007, 06:16 PM
  5. read txt file
    By sureshsri1981 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-05-2007, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •