Author: sebb
Date: Thu Mar 17 12:44:08 2011
New Revision: 1082466
URL: http://svn.apache.org/viewvc?rev=1082466&view=rev
Log:
Add support for suppressing login information.
TODO should default be changed to suppress?
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/PrintCommandListener.java
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/PrintCommandListener.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/PrintCommandListener.java?rev=1082466&r1=1082465&r2=1082466&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/PrintCommandListener.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/PrintCommandListener.java
Thu Mar 17 12:44:08 2011
@@ -33,15 +33,45 @@ import org.apache.commons.net.ProtocolCo
public class PrintCommandListener implements ProtocolCommandListener
{
private final PrintWriter __writer;
+ private final boolean __nologin;
+ /**
+ * Create the default instance which prints everything.
+ *
+ * @param writer where to write the commands and responses
+ */
public PrintCommandListener(PrintWriter writer)
{
+ this(writer, false);
+ }
+
+ /**
+ * Create an instance which optionally suppresses login command text.
+ *
+ * @param writer where to write the commands and responses
+ * @param suppressLogin if {@code true}, only print command name for login
+ *
+ * @since 3.0
+ */
+ public PrintCommandListener(PrintWriter writer, boolean suppressLogin)
+ {
__writer = writer;
+ __nologin = suppressLogin;
}
public void protocolCommandSent(ProtocolCommandEvent event)
{
- __writer.print(event.getMessage());
+ if (__nologin) {
+ String cmd = event.getCommand();
+ if ("PASS".equalsIgnoreCase(cmd) || "USER".equalsIgnoreCase(cmd)) {
+ __writer.print(cmd);
+ __writer.println(" *******");
+ } else {
+ __writer.print(event.getMessage());
+ }
+ } else {
+ __writer.print(event.getMessage());
+ }
__writer.flush();
}