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

05-26-2008, 10:25 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
So what can i do for this....
|
|

05-26-2008, 10:39 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
Ok, easy way to solve this is, change the log file with a space between number and string. Like this,
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.
|
|

05-26-2008, 10:48 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
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, 10:51 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
Change the split regex to tab space.
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.
|
|

05-26-2008, 10:56 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
thxs it is working for tab..
|
|

05-26-2008, 10:57 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
can i count how many time 192.158.5.9 is present in log file..
|
|

05-26-2008, 11:02 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
|
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.
|
|

05-26-2008, 11:05 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
All occurrence IPs
|
|

05-26-2008, 11:07 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
|
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.
|
|

05-26-2008, 11:17 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
Thxs for solution..
|
|

05-26-2008, 11:39 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
|
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.
|
|

05-26-2008, 11:42 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
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, 11:46 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
|
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.
|
|

05-26-2008, 11:52 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
ok
My Code formate is..In this .java file no Main class..
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
|
|

05-26-2008, 12:04 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
|
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.
|
|

05-26-2008, 12:07 PM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
From here...
FileReader fr = new FileReader("./" +str3);
BufferedReader br = new BufferedReader(fr);
|
|

05-26-2008, 12:19 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
Originally Posted by Mir
From here...
FileReader fr = new FileReader("./" +str3);
BufferedReader br = new BufferedReader(fr);
Replace the above code with this.
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.
|
|

05-26-2008, 12:20 PM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
just i check it
|
|

05-26-2008, 12:22 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
Define the array list in class level, just after the class declaration. As follows,
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.
|
|

05-26-2008, 12:26 PM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
Here some error :--
After add
private ArrayList<String> str;
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...
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)
|
|
|