001 /*
002 * Copyright 2001-2005 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package examples;
017
018 import java.io.PrintWriter;
019 import org.apache.commons.net.ProtocolCommandEvent;
020 import org.apache.commons.net.ProtocolCommandListener;
021
022 /***
023 * This is a support class for some of the example programs. It is
024 * a sample implementation of the ProtocolCommandListener interface
025 * which just prints out to a specified stream all command/reply traffic.
026 * <p>
027 ***/
028
029 public class PrintCommandListener implements ProtocolCommandListener
030 {
031 private PrintWriter __writer;
032
033 public PrintCommandListener(PrintWriter writer)
034 {
035 __writer = writer;
036 }
037
038 public void protocolCommandSent(ProtocolCommandEvent event)
039 {
040 __writer.print(event.getMessage());
041 __writer.flush();
042 }
043
044 public void protocolReplyReceived(ProtocolCommandEvent event)
045 {
046 __writer.print(event.getMessage());
047 __writer.flush();
048 }
049 }