Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 05-26-2008, 10:25 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
So what can i do for this....
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 05-26-2008, 10:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ok, easy way to solve this is, change the log file with a space between number and string. Like this,

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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #23 (permalink)  
Old 05-26-2008, 10:48 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
it is working for spaces,but my log file i have use Tab ,so how can i do for tab.
Plz help me
Bookmark Post in Technorati
Reply With Quote
  #24 (permalink)  
Old 05-26-2008, 10:51 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Change the split regex to tab space.

Code:
private void doProcessing(String strr) { String newStr = strr.split("\t")[0]; removeDuplicates(newStr); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #25 (permalink)  
Old 05-26-2008, 10:56 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
thxs it is working for tab..
Bookmark Post in Technorati
Reply With Quote
  #26 (permalink)  
Old 05-26-2008, 10:57 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
can i count how many time 192.158.5.9 is present in log file..
Bookmark Post in Technorati
Reply With Quote
  #27 (permalink)  
Old 05-26-2008, 11:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You want to find only the 192.158.5.9 number of occurrence. Don't you have any other IPs.

__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #28 (permalink)  
Old 05-26-2008, 11:05 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
All occurrence IPs
Bookmark Post in Technorati
Reply With Quote
  #29 (permalink)  
Old 05-26-2008, 11:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to maintain counters for each. Update in each time you find a such IPs.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #30 (permalink)  
Old 05-26-2008, 11:17 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
Thxs for solution..
Bookmark Post in Technorati
Reply With Quote
  #31 (permalink)  
Old 05-26-2008, 11:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Did you get to work now?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #32 (permalink)  
Old 05-26-2008, 11:42 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
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..
Bookmark Post in Technorati
Reply With Quote
  #33 (permalink)  
Old 05-26-2008, 11:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Oki, I'll help you. Why, is that much complicated?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #34 (permalink)  
Old 05-26-2008, 11:52 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
ok

My Code formate is..In this .java file no Main class..
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
Bookmark Post in Technorati
Reply With Quote
  #35 (permalink)  
Old 05-26-2008, 12:04 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
From where you start to read line-by-line of the log file.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #36 (permalink)  
Old 05-26-2008, 12:07 PM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
From here...

Code:
FileReader fr = new FileReader("./" +str3); BufferedReader br = new BufferedReader(fr);
Bookmark Post in Technorati
Reply With Quote
  #37 (permalink)  
Old 05-26-2008, 12:19 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Mir View Post
From here...

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


Replace the above code with this.

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); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #38 (permalink)  
Old 05-26-2008, 12:20 PM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
just i check it
Bookmark Post in Technorati
Reply With Quote
  #39 (permalink)  
Old 05-26-2008, 12:22 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Define the array list in class level, just after the class declaration. As follows,

Code:
private ArrayList<String> str;
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #40 (permalink)  
Old 05-26-2008, 12:26 PM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
Here some error :--
After add
private ArrayList<String> str;

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...

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)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply