Results 21 to 40 of 395
Thread: [SOLVED] Read From LOGFILE
- 05-26-2008, 08:25 AM #21
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 05-26-2008, 08:39 AM #22
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, easy way to solve this is, change the log file with a space between number and string. Like this,
Or you have to edit the code, to handle all spaces. But it's not easy.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
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.
- 05-26-2008, 08:48 AM #23
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
it is working for spaces,but my log file i have use Tab ,so how can i do for tab.
Plz help me
- 05-26-2008, 08:51 AM #24
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Change the split regex to tab space.
Java Code:private void doProcessing(String strr) { String newStr = strr.split("\t")[0]; removeDuplicates(newStr); }
- 05-26-2008, 08:56 AM #25
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
thxs it is working for tab..
- 05-26-2008, 08:57 AM #26
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
can i count how many time 192.158.5.9 is present in log file..
- 05-26-2008, 09:02 AM #27
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You want to find only the 192.158.5.9 number of occurrence. Don't you have any other IPs.
- 05-26-2008, 09:05 AM #28
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
All occurrence IPs
- 05-26-2008, 09:07 AM #29
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You have to maintain counters for each. Update in each time you find a such IPs.
- 05-26-2008, 09:17 AM #30
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Thxs for solution..
- 05-26-2008, 09:39 AM #31
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-26-2008, 09:42 AM #32
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
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..
- 05-26-2008, 09:46 AM #33
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Oki, I'll help you. Why, is that much complicated?
- 05-26-2008, 09:52 AM #34
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
ok
My Code formate is..In this .java file no Main class..
Plz help meJava 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(); }
- 05-26-2008, 10:04 AM #35
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
From where you start to read line-by-line of the log file.
- 05-26-2008, 10:07 AM #36
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
From here...
Java Code:FileReader fr = new FileReader("./" +str3); BufferedReader br = new BufferedReader(fr);
- 05-26-2008, 10:19 AM #37
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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); } }
- 05-26-2008, 10:20 AM #38
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
just i check it
- 05-26-2008, 10:22 AM #39
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Define the array list in class level, just after the class declaration. As follows,
Java Code:private ArrayList<String> str;
- 05-26-2008, 10:26 AM #40
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Here some error :--
After add
private ArrayList<String> str;
In these error showing...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);
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)
Similar Threads
-
Must Read.....
By sanjeevtarar in forum Forum LobbyReplies: 10Last Post: 03-03-2010, 07:16 PM -
how to read a form with JFS
By crispy in forum JavaServer Faces (JSF)Replies: 2Last Post: 05-01-2008, 03:07 PM -
Read file
By tajinvillage in forum Threads and SynchronizationReplies: 0Last Post: 01-29-2008, 09:10 AM -
How to read the following
By rrp in forum New To JavaReplies: 0Last Post: 12-03-2007, 06:16 PM -
read txt file
By sureshsri1981 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-05-2007, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks