KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > protocol > ftp > PrintCommandListener


1 package net.nutch.protocol.ftp;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.StringReader JavaDoc;
5 import java.io.IOException JavaDoc;
6
7 import java.util.logging.Logger JavaDoc;
8 import org.apache.commons.net.ProtocolCommandEvent;
9 import org.apache.commons.net.ProtocolCommandListener;
10
11 /***
12  * This is a support class for logging all ftp command/reply traffic.
13  *
14  * @author John Xing
15  ***/

16 public class PrintCommandListener implements ProtocolCommandListener
17 {
18     private Logger JavaDoc __logger;
19
20     public PrintCommandListener(Logger JavaDoc logger)
21     {
22         __logger = logger;
23     }
24
25     public void protocolCommandSent(ProtocolCommandEvent event) {
26       try {
27         __logIt(event);
28       } catch (IOException JavaDoc e) {
29         __logger.info("PrintCommandListener.protocolCommandSent(): "+e);
30       }
31     }
32
33     public void protocolReplyReceived(ProtocolCommandEvent event) {
34       try {
35         __logIt(event);
36       } catch (IOException JavaDoc e) {
37         __logger.info("PrintCommandListener.protocolReplyReceived(): "+e);
38       }
39     }
40
41     private void __logIt(ProtocolCommandEvent event) throws IOException JavaDoc {
42       BufferedReader JavaDoc br =
43         new BufferedReader JavaDoc(new StringReader JavaDoc(event.getMessage()));
44       String JavaDoc line;
45       while ((line = br.readLine()) != null) {
46         __logger.info("ftp> "+line);
47       }
48     }
49 }
50
Popular Tags