Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 8534 invoked from network); 3 Apr 2002 04:43:32 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 3 Apr 2002 04:43:32 -0000 Received: (qmail 2956 invoked by uid 97); 3 Apr 2002 04:43:10 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 2873 invoked by uid 97); 3 Apr 2002 04:43:09 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 2862 invoked by uid 97); 3 Apr 2002 04:43:08 -0000 Date: 3 Apr 2002 04:42:50 -0000 Message-ID: <20020403044250.51913.qmail@icarus.apache.org> From: brekke@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/net/src/java/org/apache/commons/net CharGenTCPClient.java CharGenUDPClient.java DatagramSocketClient.java DatagramSocketFactory.java DaytimeTCPClient.java DaytimeUDPClient.java DefaultDatagramSocketFactory.java DefaultSocketFactory.java DiscardTCPClient.java DiscardUDPClient.java EchoTCPClient.java EchoUDPClient.java FingerClient.java MalformedServerReplyException.java ProtocolCommandEvent.java ProtocolCommandListener.java ProtocolCommandSupport.java SocketClient.java SocketFactory.java TimeTCPClient.java TimeUDPClient.java WhoisClient.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N brekke 02/04/02 20:42:50 Added: net/src/java/org/apache/commons/net CharGenTCPClient.java CharGenUDPClient.java DatagramSocketClient.java DatagramSocketFactory.java DaytimeTCPClient.java DaytimeUDPClient.java DefaultDatagramSocketFactory.java DefaultSocketFactory.java DiscardTCPClient.java DiscardUDPClient.java EchoTCPClient.java EchoUDPClient.java FingerClient.java MalformedServerReplyException.java ProtocolCommandEvent.java ProtocolCommandListener.java ProtocolCommandSupport.java SocketClient.java SocketFactory.java TimeTCPClient.java TimeUDPClient.java WhoisClient.java Log: Moving com.oroinc.net to org.apache.commons.net Revision Changes Path 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/CharGenTCPClient.java Index: CharGenTCPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The CharGenTCPClient class is a TCP implementation of a client for the * character generator protocol described in RFC 864. It can also be * used for Systat (RFC 866), Quote of the Day (RFC 865), and netstat * (port 15). All of these protocols involve connecting to the appropriate * port, and reading data from an input stream. The chargen protocol * actually sends data until the receiving end closes the connection. All * of the others send only a fixed amount of data and then close the * connection. *

* To use the CharGenTCPClient class, just establish a * connection with * connect * and call getInputStream() to access * the data. Don't close the input stream when you're done with it. Rather, * call disconnect * to clean up properly. *

*

* @author Daniel F. Savarese * @see CharGenUDPClient ***/ public final class CharGenTCPClient extends SocketClient { /*** The systat port value of 11 according to RFC 866. ***/ public static final int SYSTAT_PORT = 11; /*** The netstat port value of 19. ***/ public static final int NETSTAT_PORT = 15; /*** The quote of the day port value of 17 according to RFC 865. ***/ public static final int QUOTE_OF_DAY_PORT = 17; /*** The character generator port value of 19 according to RFC 864. ***/ public static final int CHARGEN_PORT = 19; /*** The default chargen port. It is set to 19 according to RFC 864. ***/ public static final int DEFAULT_PORT = 19; /*** * The default constructor for CharGenTCPClient. It merely sets the * default port to DEFAULT_PORT . ***/ public CharGenTCPClient () { setDefaultPort(DEFAULT_PORT); } /*** * Returns an InputStream from which the server generated data can be * read. You should NOT close the InputStream when you're finished * reading from it. Rather, you should call * disconnect * to clean up properly. *

* @return An InputStream from which the server generated data can be read. ***/ public InputStream getInputStream() { return _input_; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/CharGenUDPClient.java Index: CharGenUDPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The CharGenUDPClient class is a UDP implementation of a client for the * character generator protocol described in RFC 864. It can also be * used for Systat (RFC 866), Quote of the Day (RFC 865), and netstat * (port 15). All of these protocols involve sending a datagram to the * appropriate port, and reading data contained in one or more reply * datagrams. The chargen and quote of the day protocols only send * one reply datagram containing 512 bytes or less of data. The other * protocols may reply with more than one datagram, in which case you * must wait for a timeout to determine that all reply datagrams have * been sent. *

* To use the CharGenUDPClient class, just open a local UDP port * with open * and call send to send the datagram that will * initiate the data reply. For chargen or quote of the day, just * call receive , and you're done. For netstat and * systat, call receive in a while loop, and catch a SocketException and * InterruptedIOException to detect a timeout (don't forget to set the * timeout duration beforehand). Don't forget to call * close() * to clean up properly. *

*

* @author Daniel F. Savarese * @see CharGenTCPClient ***/ public final class CharGenUDPClient extends DatagramSocketClient { /*** The systat port value of 11 according to RFC 866. ***/ public static final int SYSTAT_PORT = 11; /*** The netstat port value of 19. ***/ public static final int NETSTAT_PORT = 15; /*** The quote of the day port value of 17 according to RFC 865. ***/ public static final int QUOTE_OF_DAY_PORT = 17; /*** The character generator port value of 19 according to RFC 864. ***/ public static final int CHARGEN_PORT = 19; /*** The default chargen port. It is set to 19 according to RFC 864. ***/ public static final int DEFAULT_PORT = 19; private byte[] __receiveData; private DatagramPacket __receivePacket; private DatagramPacket __sendPacket; /*** * The default CharGenUDPClient constructor. It initializes some internal * data structures for sending and receiving the necessary datagrams for * the chargen and related protocols. ***/ public CharGenUDPClient() { // CharGen return packets have a maximum length of 512 __receiveData = new byte[512]; __receivePacket = new DatagramPacket(__receiveData, 512); __sendPacket = new DatagramPacket(new byte[0], 0); } /*** * Sends the data initiation datagram. This data in the packet is ignored * by the server, and merely serves to signal that the server should send * its reply. *

* @param host The address of the server. * @param port The port of the service. * @exception IOException If an error occurs while sending the datagram. ***/ public void send(InetAddress host, int port) throws IOException { __sendPacket.setAddress(host); __sendPacket.setPort(port); _socket_.send(__sendPacket); } /*** Same as send(host, CharGenUDPClient.DEFAULT_PORT); ***/ public void send(InetAddress host) throws IOException { send(host, DEFAULT_PORT); } /*** * Receive the reply data from the server. This will always be 512 bytes * or less. Chargen and quote of the day only return one packet. Netstat * and systat require multiple calls to receive() with timeout detection. *

* @return The reply data from the server. * @exception IOException If an error occurs while receiving the datagram. ***/ public byte[] receive() throws IOException { int length; byte[] result; _socket_.receive(__receivePacket); result = new byte[length = __receivePacket.getLength()]; System.arraycopy(__receiveData, 0, result, 0, length); return result; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DatagramSocketClient.java Index: DatagramSocketClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.net.*; /*** * The DatagramSocketClient provides the basic operations that are required * of client objects accessing datagram sockets. It is meant to be * subclassed to avoid having to rewrite the same code over and over again * to open a socket, close a socket, set timeouts, etc. Of special note * is the setDatagramSocketFactory * method, which allows you to control the type of DatagramSocket the * DatagramSocketClient creates for network communications. This is * especially useful for adding things like proxy support as well as better * support for applets. For * example, you could create a * * DatagramSocketFactory that * requests browser security capabilities before creating a socket. * All classes derived from DatagramSocketClient should use the * _socketFactory_ member variable to * create DatagramSocket instances rather than instantiating * them by directly invoking a constructor. By honoring this contract * you guarantee that a user will always be able to provide his own * Socket implementations by substituting his own SocketFactory. *

*

* @author Daniel F. Savarese * @see DatagramSocketFactory ***/ public abstract class DatagramSocketClient { /*** * The default DatagramSocketFactory shared by all DatagramSocketClient * instances. ***/ private static final DatagramSocketFactory __DEFAULT_SOCKET_FACTORY = new DefaultDatagramSocketFactory(); /*** The timeout to use after opening a socket. ***/ protected int _timeout_; /*** The datagram socket used for the connection. ***/ protected DatagramSocket _socket_; /*** * A status variable indicating if the client's socket is currently open. ***/ protected boolean _isOpen_; /*** The datagram socket's DatagramSocketFactory. ***/ protected DatagramSocketFactory _socketFactory_; /*** * Default constructor for DatagramSocketClient. Initializes * _socket_ to null, _timeout_ to 0, and _isOpen_ to false. ***/ public DatagramSocketClient() { _socket_ = null; _timeout_ = 0; _isOpen_ = false; _socketFactory_ = __DEFAULT_SOCKET_FACTORY; } /*** * Opens a DatagramSocket on the local host at the first available port. * Also sets the timeout on the socket to the default timeout set * by setDefaultTimeout() . *

* _isOpen_ is set to true after calling this method and _socket_ * is set to the newly opened socket. *

* @exception SocketException If the socket could not be opened or the * timeout could not be set. ***/ public void open() throws SocketException { _socket_ = _socketFactory_.createDatagramSocket(); _socket_.setSoTimeout(_timeout_); _isOpen_ = true; } /*** * Opens a DatagramSocket on the local host at a specified port. * Also sets the timeout on the socket to the default timeout set * by setDefaultTimeout() . *

* _isOpen_ is set to true after calling this method and _socket_ * is set to the newly opened socket. *

* @param port The port to use for the socket. * @exception SocketException If the socket could not be opened or the * timeout could not be set. ***/ public void open(int port) throws SocketException { _socket_ = _socketFactory_.createDatagramSocket(port); _socket_.setSoTimeout(_timeout_); _isOpen_ = true; } /*** * Opens a DatagramSocket at the specified address on the local host * at a specified port. * Also sets the timeout on the socket to the default timeout set * by setDefaultTimeout() . *

* _isOpen_ is set to true after calling this method and _socket_ * is set to the newly opened socket. *

* @param port The port to use for the socket. * @param laddr The local address to use. * @exception SocketException If the socket could not be opened or the * timeout could not be set. ***/ public void open(int port, InetAddress laddr) throws SocketException { _socket_ = _socketFactory_.createDatagramSocket(port, laddr); _socket_.setSoTimeout(_timeout_); _isOpen_ = true; } /*** * Closes the DatagramSocket used for the connection. * You should call this method after you've finished using the class * instance and also before you call open() * again. _isOpen_ is set to false and _socket_ is set to null. * If you call this method when the client socket is not open, * a NullPointerException is thrown. ***/ public void close() { _socket_.close(); _socket_ = null; _isOpen_ = false; } /*** * Returns true if the client has a currently open socket. *

* @return True if the client has a curerntly open socket, false otherwise. ***/ public boolean isOpen() { return _isOpen_; } /*** * Set the default timeout in milliseconds to use when opening a socket. * After a call to open, the timeout for the socket is set using this value. * This method should be used prior to a call to open() * and should not be confused with setSoTimeout() * which operates on the currently open socket. _timeout_ contains * the new timeout value. *

* @param timeout The timeout in milliseconds to use for the datagram socket * connection. ***/ public void setDefaultTimeout(int timeout) { _timeout_ = timeout; } /*** * Returns the default timeout in milliseconds that is used when * opening a socket. *

* @return The default timeout in milliseconds that is used when * opening a socket. ***/ public int getDefaultTimeout() { return _timeout_; } /*** * Set the timeout in milliseconds of a currently open connection. * Only call this method after a connection has been opened * by open(). *

* @param timeout The timeout in milliseconds to use for the currently * open datagram socket connection. ***/ public void setSoTimeout(int timeout) throws SocketException { _socket_.setSoTimeout(timeout); } /*** * Returns the timeout in milliseconds of the currently opened socket. * If you call this method when the client socket is not open, * a NullPointerException is thrown. *

* @return The timeout in milliseconds of the currently opened socket. ***/ public int getSoTimeout() throws SocketException { return _socket_.getSoTimeout(); } /*** * Returns the port number of the open socket on the local host used * for the connection. If you call this method when the client socket * is not open, a NullPointerException is thrown. *

* @return The port number of the open socket on the local host used * for the connection. ***/ public int getLocalPort() { return _socket_.getLocalPort(); } /*** * Returns the local address to which the client's socket is bound. * If you call this method when the client socket is not open, a * NullPointerException is thrown. *

* @return The local address to which the client's socket is bound. ***/ public InetAddress getLocalAddress() { return _socket_.getLocalAddress(); } /*** * Sets the DatagramSocketFactory used by the DatagramSocketClient * to open DatagramSockets. If the factory value is null, then a default * factory is used (only do this to reset the factory after having * previously altered it). *

* @param factory The new DatagramSocketFactory the DatagramSocketClient * should use. ***/ public void setDatagramSocketFactory(DatagramSocketFactory factory) { if(factory == null) _socketFactory_ = __DEFAULT_SOCKET_FACTORY; else _socketFactory_ = factory; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DatagramSocketFactory.java Index: DatagramSocketFactory.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.net.*; /*** * The DatagramSocketFactory interface provides a means for the * programmer to control the creation of datagram sockets and * provide his own DatagramSocket implementations for use by all * classes derived from * * DatagramSocketClient . * This allows you to provide your own DatagramSocket implementations and * to perform security checks or browser capability requests before * creating a DatagramSocket. *

*

* @author Daniel F. Savarese ***/ public interface DatagramSocketFactory { /*** * Creates a DatagramSocket on the local host at the first available port. *

* @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket() throws SocketException; /*** * Creates a DatagramSocket on the local host at a specified port. *

* @param port The port to use for the socket. * @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket(int port) throws SocketException; /*** * Creates a DatagramSocket at the specified address on the local host * at a specified port. *

* @param port The port to use for the socket. * @param laddr The local address to use. * @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket(int port, InetAddress laddr) throws SocketException; } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DaytimeTCPClient.java Index: DaytimeTCPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The DaytimeTCPClient class is a TCP implementation of a client for the * Daytime protocol described in RFC 867. To use the class, merely * establish a connection with * connect * and call getTime() to retrieve the daytime * string, then * call disconnect * to close the connection properly. *

*

* @author Daniel F. Savarese * @see DaytimeUDPClient ***/ public final class DaytimeTCPClient extends SocketClient { /*** The default daytime port. It is set to 13 according to RFC 867. ***/ public static final int DEFAULT_PORT = 13; // Received dates will likely be less than 64 characters. // This is a temporary buffer used while receiving data. private char[] __buffer = new char[64]; /*** * The default DaytimeTCPClient constructor. It merely sets the default * port to DEFAULT_PORT . ***/ public DaytimeTCPClient () { setDefaultPort(DEFAULT_PORT); } /*** * Retrieves the time string from the server and returns it. The * server will have closed the connection at this point, so you should * call * disconnect * after calling this method. To retrieve another time, you must * initiate another connection with * connect * before calling getTime() again. *

* @return The time string retrieved from the server. * @exception IOException If an error occurs while fetching the time string. ***/ public String getTime() throws IOException { int read; StringBuffer result = new StringBuffer(__buffer.length); BufferedReader reader; reader = new BufferedReader(new InputStreamReader(_input_)); while(true) { read = reader.read(__buffer, 0, __buffer.length); if(read <= 0) break; result.append(__buffer, 0, read); } return result.toString(); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DaytimeUDPClient.java Index: DaytimeUDPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The DaytimeUDPClient class is a UDP implementation of a client for the * Daytime protocol described in RFC 867. To use the class, merely * open a local datagram socket with * open * and call getTime to retrieve the daytime * string, then * call close * to close the connection properly. Unlike * DaytimeTCPClient , * successive calls to getTime are permitted * without re-establishing a connection. That is because UDP is a * connectionless protocol and the Daytime protocol is stateless. *

*

* @author Daniel F. Savarese * @see DaytimeTCPClient ***/ public final class DaytimeUDPClient extends DatagramSocketClient { /*** The default daytime port. It is set to 13 according to RFC 867. ***/ public static final int DEFAULT_PORT = 13; private byte[] __dummyData = new byte[1]; // Received dates should be less than 256 bytes private byte[] __timeData = new byte[256]; /*** * Retrieves the time string from the specified server and port and * returns it. *

* @param host The address of the server. * @param port The port of the service. * @return The time string. * @exception IOException If an error occurs while retrieving the time. ***/ public String getTime(InetAddress host, int port) throws IOException { DatagramPacket sendPacket, receivePacket; sendPacket = new DatagramPacket(__dummyData, __dummyData.length, host, port); receivePacket = new DatagramPacket(__timeData, __timeData.length); _socket_.send(sendPacket); _socket_.receive(receivePacket); return new String(receivePacket.getData(), 0, receivePacket.getLength()); } /*** Same as getTime(host, DaytimeUDPClient.DEFAULT_PORT); ***/ public String getTime(InetAddress host) throws IOException { return getTime(host, DEFAULT_PORT); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DefaultDatagramSocketFactory.java Index: DefaultDatagramSocketFactory.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.net.*; /*** * DefaultDatagramSocketFactory implements the DatagramSocketFactory * interface by simply wrapping the java.net.DatagramSocket * constructors. It is the default DatagramSocketFactory used by * * DatagramSocketClient implementations. *

*

* @author Daniel F. Savarese * @see DatagramSocketFactory * @see DatagramSocketClient * @see DatagramSocketClient#setDatagramSocketFactory ***/ public class DefaultDatagramSocketFactory implements DatagramSocketFactory { /*** * Creates a DatagramSocket on the local host at the first available port. *

* @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket() throws SocketException { return new DatagramSocket(); } /*** * Creates a DatagramSocket on the local host at a specified port. *

* @param port The port to use for the socket. * @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket(int port) throws SocketException { return new DatagramSocket(port); } /*** * Creates a DatagramSocket at the specified address on the local host * at a specified port. *

* @param port The port to use for the socket. * @param laddr The local address to use. * @exception SocketException If the socket could not be created. ***/ public DatagramSocket createDatagramSocket(int port, InetAddress laddr) throws SocketException { return new DatagramSocket(port, laddr); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DefaultSocketFactory.java Index: DefaultSocketFactory.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * DefaultSocketFactory implements the SocketFactory interface by * simply wrapping the java.net.Socket and java.net.ServerSocket * constructors. It is the default SocketFactory used by * SocketClient * implementations. *

*

* @author Daniel F. Savarese * @see SocketFactory * @see SocketClient * @see SocketClient#setSocketFactory ***/ public class DefaultSocketFactory implements SocketFactory { /*** * Creates a Socket connected to the given host and port. *

* @param host The hostname to connect to. * @param port The port to connect to. * @return A Socket connected to the given host and port. * @exception UnknownHostException If the hostname cannot be resolved. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(String host, int port) throws UnknownHostException, IOException { return new Socket(host, port); } /*** * Creates a Socket connected to the given host and port. *

* @param address The address of the host to connect to. * @param port The port to connect to. * @return A Socket connected to the given host and port. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(InetAddress address, int port) throws IOException { return new Socket(address, port); } /*** * Creates a Socket connected to the given host and port and * originating from the specified local address and port. *

* @param host The hostname to connect to. * @param port The port to connect to. * @param localAddr The local address to use. * @param localPort The local port to use. * @return A Socket connected to the given host and port. * @exception UnknownHostException If the hostname cannot be resolved. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(String host, int port, InetAddress localAddr, int localPort) throws UnknownHostException, IOException { return new Socket(host, port, localAddr, localPort); } /*** * Creates a Socket connected to the given host and port and * originating from the specified local address and port. *

* @param address The address of the host to connect to. * @param port The port to connect to. * @param localAddr The local address to use. * @param localPort The local port to use. * @return A Socket connected to the given host and port. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException { return new Socket(address, port, localAddr, localPort); } /*** * Creates a ServerSocket bound to a specified port. A port * of 0 will create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port) throws IOException { return new ServerSocket(port); } /*** * Creates a ServerSocket bound to a specified port with a given * maximum queue length for incoming connections. A port of 0 will * create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @param backlog The maximum length of the queue for incoming connections. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port, int backlog) throws IOException { return new ServerSocket(port, backlog); } /*** * Creates a ServerSocket bound to a specified port on a given local * address with a given maximum queue length for incoming connections. * A port of 0 will * create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @param backlog The maximum length of the queue for incoming connections. * @param bindAddr The local address to which the ServerSocket should bind. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException { return new ServerSocket(port, backlog, bindAddr); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DiscardTCPClient.java Index: DiscardTCPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The DiscardTCPClient class is a TCP implementation of a client for the * Discard protocol described in RFC 863. To use the class, merely * establish a connection with * connect * and call getOutputStream() to * retrieve the discard output stream. Don't close the output stream * when you're done writing to it. Rather, call * disconnect * to clean up properly. *

*

* @author Daniel F. Savarese * @see DiscardUDPClient ***/ public class DiscardTCPClient extends SocketClient { /*** The default discard port. It is set to 9 according to RFC 863. ***/ public static final int DEFAULT_PORT = 9; /*** * The default DiscardTCPClient constructor. It merely sets the default * port to DEFAULT_PORT . ***/ public DiscardTCPClient () { setDefaultPort(DEFAULT_PORT); } /*** * Returns an OutputStream through which you may write data to the server. * You should NOT close the OutputStream when you're finished * reading from it. Rather, you should call * disconnect * to clean up properly. *

* @return An OutputStream through which you can write data to the server. ***/ public OutputStream getOutputStream() { return _output_; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/DiscardUDPClient.java Index: DiscardUDPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The DiscardUDPClient class is a UDP implementation of a client for the * Discard protocol described in RFC 863. To use the class, * just open a local UDP port * with open * and call send to send datagrams to the server * After you're done sending discard data, call * close() * to clean up properly. *

*

* @author Daniel F. Savarese * @see DiscardTCPClient ***/ public class DiscardUDPClient extends DatagramSocketClient { /*** The default discard port. It is set to 9 according to RFC 863. ***/ public static final int DEFAULT_PORT = 9; DatagramPacket _sendPacket; public DiscardUDPClient() { _sendPacket = new DatagramPacket(new byte[0], 0); } /*** * Sends the specified data to the specified server at the specified port. *

* @param data The discard data to send. * @param length The length of the data to send. Should be less than * or equal to the length of the data byte array. * @param host The address of the server. * @param port The service port. * @exception IOException If an error occurs during the datagram send * operation. ***/ public void send(byte[] data, int length, InetAddress host, int port) throws IOException { _sendPacket.setData(data); _sendPacket.setLength(length); _sendPacket.setAddress(host); _sendPacket.setPort(port); _socket_.send(_sendPacket); } /*** * Same as * send(data, length, host. DiscardUDPClient.DEFAULT_PORT). ***/ public void send(byte[] data, int length, InetAddress host) throws IOException { send(data, length, host, DEFAULT_PORT); } /*** * Same as * send(data, data.length, host. DiscardUDPClient.DEFAULT_PORT). ***/ public void send(byte[] data, InetAddress host) throws IOException { send(data, data.length, host, DEFAULT_PORT); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/EchoTCPClient.java Index: EchoTCPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The EchoTCPClient class is a TCP implementation of a client for the * Echo protocol described in RFC 862. To use the class, merely * establish a connection with * connect * and call getOutputStream() to * retrieve the echo output stream and * * getInputStream() to get the echo input stream. * Don't close either stream when you're done using them. Rather, call * disconnect * to clean up properly. *

*

* @author Daniel F. Savarese * @see EchoUDPClient * @see DiscardTCPClient ***/ public final class EchoTCPClient extends DiscardTCPClient { /*** The default echo port. It is set to 7 according to RFC 862. ***/ public static final int DEFAULT_PORT = 7; /*** * The default EchoTCPClient constructor. It merely sets the default * port to DEFAULT_PORT . ***/ public EchoTCPClient () { setDefaultPort(DEFAULT_PORT); } /*** * Returns an InputStream from which you may read echoed data from * the server. You should NOT close the InputStream when you're finished * reading from it. Rather, you should call * disconnect * to clean up properly. *

* @return An InputStream from which you can read echoed data from the * server. ***/ public InputStream getInputStream() { return _input_; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/EchoUDPClient.java Index: EchoUDPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The EchoUDPClient class is a UDP implementation of a client for the * Echo protocol described in RFC 862. To use the class, * just open a local UDP port * with open * and call send to send datagrams to the server, * then call receive to receive echoes. * After you're done echoing data, call * close() * to clean up properly. *

*

* @author Daniel F. Savarese * @see EchoTCPClient * @see DiscardUDPClient ***/ public final class EchoUDPClient extends DiscardUDPClient { /*** The default echo port. It is set to 7 according to RFC 862. ***/ public static final int DEFAULT_PORT = 7; private DatagramPacket __receivePacket = new DatagramPacket(new byte[0], 0); /*** * Sends the specified data to the specified server at the default echo * port. *

* @param data The echo data to send. * @param length The length of the data to send. Should be less than * or equal to the length of the data byte array. * @param host The address of the server. * @exception IOException If an error occurs during the datagram send * operation. ***/ public void send(byte[] data, int length, InetAddress host) throws IOException { send(data, length, host, DEFAULT_PORT); } /*** Same as send(data, data.length, host) ***/ public void send(byte[] data, InetAddress host) throws IOException { send(data, data.length, host, DEFAULT_PORT); } /*** * Receives echoed data and returns its length. The data may be divided * up among multiple datagrams, requiring multiple calls to receive. * Also, the UDP packets will not necessarily arrive in the same order * they were sent. *

* @return Length of actual data received. * @exception IOException If an error occurs while receiving the data. ***/ public int receive(byte[] data, int length) throws IOException { __receivePacket.setData(data); __receivePacket.setLength(length); _socket_.receive(__receivePacket); return __receivePacket.getLength(); } /*** Same as receive(data, data.length) ***/ public int receive(byte[] data) throws IOException { return receive(data, data.length); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/FingerClient.java Index: FingerClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The FingerClient class implements the client side of the Internet Finger * Protocol defined in RFC 1288. To finger a host you create a * FingerClient instance, connect to the host, query the host, and finally * disconnect from the host. If the finger service you want to query is on * a non-standard port, connect to the host at that port. * Here's a sample use: *

   *    FingerClient finger;
   * 
   *    finger = new FingerClient();
   *
   *    try {
   *      finger.connect("foo.bar.com");
   *      System.out.println(finger.query("foobar", false));
   *      finger.disconnect();
   *    } catch(IOException e) {
   *      System.err.println("Error I/O exception: " + e.getMessage());
   *      return;
   *    }
   * 
*

*

* @author Daniel F. Savarese ***/ public class FingerClient extends SocketClient { /*** * The default FINGER port. Set to 79 according to RFC 1288. ***/ public static final int DEFAULT_PORT = 79; private static final String __LONG_FLAG = "/W "; private transient StringBuffer __query = new StringBuffer(64); private transient char[] __buffer = new char[1024]; /*** * The default FingerClient constructor. Initializes the * default port to DEFAULT_PORT . ***/ public FingerClient() { setDefaultPort(DEFAULT_PORT); } /*** * Fingers a user at the connected host and returns the output * as a String. You must first connect to a finger server before * calling this method, and you should disconnect afterward. *

* @param longOutput Set to true if long output is requested, false if not. * @param username The name of the user to finger. * @return The result of the finger query. * @exception IOException If an I/O error occurs while reading the socket. ***/ public String query(boolean longOutput, String username) throws IOException { int read; StringBuffer result = new StringBuffer(__buffer.length); BufferedReader input; input = new BufferedReader(new InputStreamReader(getInputStream(longOutput, username))); while(true) { read = input.read(__buffer, 0, __buffer.length); if(read <= 0) break; result.append(__buffer, 0, read); } input.close(); return result.toString(); } /*** * Fingers the connected host and returns the output * as a String. You must first connect to a finger server before * calling this method, and you should disconnect afterward. * This is equivalent to calling query(longOutput, "") . *

* @param longOutput Set to true if long output is requested, false if not. * @return The result of the finger query. * @exception IOException If an I/O error occurs while reading the socket. ***/ public String query(boolean longOutput) throws IOException { return query(longOutput, ""); } /*** * Fingers a user and returns the input stream from the network connection * of the finger query. You must first connect to a finger server before * calling this method, and you should disconnect after finishing reading * the stream. *

* @param longOutput Set to true if long output is requested, false if not. * @param username The name of the user to finger. * @return The InputStream of the network connection of the finger query. * Can be read to obtain finger results. * @exception IOException If an I/O error during the operation. ***/ public InputStream getInputStream(boolean longOutput, String username) throws IOException { Socket socket; DataOutputStream output; __query.setLength(0); if(longOutput) __query.append(__LONG_FLAG); __query.append(username); __query.append(SocketClient.NETASCII_EOL); output = new DataOutputStream(_output_); output.writeBytes(__query.toString()); output.flush(); return _input_; } /*** * Fingers the connected host and returns the input stream from * the network connection of the finger query. This is equivalent to * calling getInputStream(longOutput, ""). You must first connect to a * finger server before calling this method, and you should disconnect * after finishing reading the stream. *

* @param longOutput Set to true if long output is requested, false if not. * @return The InputStream of the network connection of the finger query. * Can be read to obtain finger results. * @exception IOException If an I/O error during the operation. ***/ public InputStream getInputStream(boolean longOutput) throws IOException { return getInputStream(longOutput, ""); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/MalformedServerReplyException.java Index: MalformedServerReplyException.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; /*** * This exception is used to indicate that the reply from a server * could not be interpreted. Most of the NetComponents classes attempt * to be as lenient as possible when receiving server replies. Many * server implementations deviate from IETF protocol specifications, making * it necessary to be as flexible as possible. However, there will be * certain situations where it is not possible to continue an operation * because the server reply could not be interpreted in a meaningful manner. * In these cases, a MalformedServerReplyException should be thrown. *

*

* @author Daniel F. Savarese ***/ public class MalformedServerReplyException extends IOException { /*** Constructs a MalformedServerReplyException with no message ***/ public MalformedServerReplyException() { super(); } /*** * Constructs a MalformedServerReplyException with a specified message. *

* @param message The message explaining the reason for the exception. ***/ public MalformedServerReplyException(String message) { super(message); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ProtocolCommandEvent.java Index: ProtocolCommandEvent.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.util.*; /*** * There exists a large class of IETF protocols that work by sending an * ASCII text command and arguments to a server, and then receiving an * ASCII text reply. For debugging and other purposes, it is extremely * useful to log or keep track of the contents of the protocol messages. * The ProtocolCommandEvent class coupled with the * * ProtocolCommandListener interface facilitate this process. *

*

* @see ProtocolCommandListener * @see ProtocolCommandSupport * @author Daniel F. Savarese ***/ public class ProtocolCommandEvent extends EventObject { private int __replyCode; private boolean __isCommand; private String __message, __command; /*** * Creates a ProtocolCommandEvent signalling a command was sent to * the server. ProtocolCommandEvents created with this constructor * should only be sent after a command has been sent, but before the * reply has been received. *

* @param source The source of the event. * @param command The string representation of the command type sent, not * including the arguments (e.g., "STAT" or "GET"). * @param message The entire command string verbatim as sent to the server, * including all arguments. ***/ public ProtocolCommandEvent(Object source, String command, String message){ super(source); __replyCode = 0; __message = message; __isCommand = true; __command = command; } /*** * Creates a ProtocolCommandEvent signalling a reply to a command was * received. ProtocolCommandEvents created with this constructor * should only be sent after a complete command reply has been received * fromt a server. *

* @param source The source of the event. * @param replyCode The integer code indicating the natureof the reply. * This will be the protocol integer value for protocols * that use integer reply codes, or the reply class constant * corresponding to the reply for protocols like POP3 that use * strings like OK rather than integer codes (i.e., POP3Repy.OK). * @param message The entire reply as received from the server. ***/ public ProtocolCommandEvent(Object source, int replyCode, String message){ super(source); __replyCode = replyCode; __message = message; __isCommand = false; __command = null; } /*** * Returns the string representation of the command type sent (e.g., "STAT" * or "GET"). If the ProtocolCommandEvent is a reply event, then null * is returned. *

* @return The string representation of the command type sent, or null * if this is a reply event. ***/ public String getCommand() { return __command; } /*** * Returns the reply code of the received server reply. Undefined if * this is not a reply event. *

* @return The reply code of the received server reply. Undefined if * not a reply event. ***/ public int getReplyCode() { return __replyCode; } /*** * Returns true if the ProtocolCommandEvent was generated as a result * of sending a command. *

* @return true If the ProtocolCommandEvent was generated as a result * of sending a command. False otherwise. ***/ public boolean isCommand() { return __isCommand; } /*** * Returns true if the ProtocolCommandEvent was generated as a result * of receiving a reply. *

* @return true If the ProtocolCommandEvent was generated as a result * of receiving a reply. False otherwise. ***/ public boolean isReply() { return !isCommand(); } /*** * Returns the entire message sent to or received from the server. *

* @return The entire message sent to or received from the server. ***/ public String getMessage() { return __message; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ProtocolCommandListener.java Index: ProtocolCommandListener.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.util.*; /*** * There exists a large class of IETF protocols that work by sending an * ASCII text command and arguments to a server, and then receiving an * ASCII text reply. For debugging and other purposes, it is extremely * useful to log or keep track of the contents of the protocol messages. * The ProtocolCommandListener interface coupled with the * ProtocolCommandEvent * class facilitate this process. *

* To receive ProtocolCommandEvents, you merely implement the * ProtocolCommandListener interface and register the class as a listener * with a ProtocolCommandEvent source such as * FTPClient . *

*

* @see ProtocolCommandEvent * @see ProtocolCommandSupport * @author Daniel F. Savarese ***/ public interface ProtocolCommandListener extends EventListener { /*** * This method is invoked by a ProtocolCommandEvent source after * sending a protocol command to a server. *

* @param event The ProtocolCommandEvent fired. ***/ public void protocolCommandSent(ProtocolCommandEvent event); /*** * This method is invoked by a ProtocolCommandEvent source after * receiving a reply from a server. *

* @param event The ProtocolCommandEvent fired. ***/ public void protocolReplyReceived(ProtocolCommandEvent event); } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ProtocolCommandSupport.java Index: ProtocolCommandSupport.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.util.*; import org.apache.commons.util.ListenerList; /*** * ProtocolCommandSupport is a convenience class for managing a list of * ProtocolCommandListeners and firing ProtocolCommandEvents. You can * simply delegate ProtocolCommandEvent firing and listener * registering/unregistering tasks to this class. *

*

* @see ProtocolCommandEvent * @see ProtocolCommandListener * @author Daniel F. Savarese ***/ public class ProtocolCommandSupport implements java.io.Serializable { private Object __source; private ListenerList __listeners; /*** * Creates a ProtocolCommandSupport instant using the indicated source * as the source of fired ProtocolCommandEvents. *

* @param source The source to use for all generated ProtocolCommandEvents. ***/ public ProtocolCommandSupport(Object source) { __listeners = new ListenerList(); __source = source; } /*** * Fires a ProtocolCommandEvent signalling the sending of a command to all * registered listeners, invoking their * * protocolCommandSent() methods. *

* @param command The string representation of the command type sent, not * including the arguments (e.g., "STAT" or "GET"). * @param message The entire command string verbatim as sent to the server, * including all arguments. ***/ public void fireCommandSent(String command, String message){ Enumeration enum; ProtocolCommandEvent event; ProtocolCommandListener listener; enum = __listeners.getListeners(); event = new ProtocolCommandEvent(__source, command, message); while(enum.hasMoreElements()) { listener = (ProtocolCommandListener)enum.nextElement(); listener.protocolCommandSent(event); } } /*** * Fires a ProtocolCommandEvent signalling the reception of a command reply * to all registered listeners, invoking their * * protocolReplyReceived() methods. *

* @param replyCode The integer code indicating the natureof the reply. * This will be the protocol integer value for protocols * that use integer reply codes, or the reply class constant * corresponding to the reply for protocols like POP3 that use * strings like OK rather than integer codes (i.e., POP3Repy.OK). * @param message The entire reply as received from the server. ***/ public void fireReplyReceived(int replyCode, String message){ Enumeration enum; ProtocolCommandEvent event; ProtocolCommandListener listener; enum = __listeners.getListeners(); event = new ProtocolCommandEvent(__source, replyCode, message); while(enum.hasMoreElements()) { listener = (ProtocolCommandListener)enum.nextElement(); listener.protocolReplyReceived(event); } } /*** * Adds a ProtocolCommandListener. *

* @param listener The ProtocolCommandListener to add. ***/ public void addProtocolCommandListener(ProtocolCommandListener listener){ __listeners.addListener(listener); } /*** * Removes a ProtocolCommandListener. *

* @param listener The ProtocolCommandListener to remove. ***/ public void removeProtocolCommandListener(ProtocolCommandListener listener){ __listeners.removeListener(listener); } /*** * Returns the number of ProtocolCommandListeners currently registered. *

* @return The number of ProtocolCommandListeners currently registered. ***/ public int getListenerCount() { return __listeners.getListenerCount(); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/SocketClient.java Index: SocketClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The SocketClient provides the basic operations that are required * of client objects accessing sockets. It is meant to be * subclassed to avoid having to rewrite the same code over and over again * to open a socket, close a socket, set timeouts, etc. Of special note * is the setSocketFactory * method, which * allows you to control the type of Socket the SocketClient creates for * initiating network connections. This is especially useful for adding * SSL or proxy support as well as better support for applets. For * example, you could create a * SocketFactory that * requests browser security capabilities before creating a socket. * All classes derived from SocketClient should use the * _socketFactory_ member variable to * create Socket and ServerSocket instances rather than instanting * them by directly invoking a constructor. By honoring this contract * you guarantee that a user will always be able to provide his own * Socket implementations by substituting his own SocketFactory. *

*

* @author Daniel F. Savarese * @see SocketFactory ***/ public abstract class SocketClient { /*** * The end of line character sequence used by most IETF protocols. That * is a carriage return followed by a newline: "\r\n" ***/ public static final String NETASCII_EOL = "\r\n"; /*** The default SocketFactory shared by all SocketClient instances. ***/ private static final SocketFactory __DEFAULT_SOCKET_FACTORY = new DefaultSocketFactory(); /*** The timeout to use after opening a socket. ***/ protected int _timeout_; /*** The socket used for the connection. ***/ protected Socket _socket_; /*** * A status variable indicating if the client's socket is currently open. ***/ protected boolean _isConnected_; /*** The default port the client should connect to. ***/ protected int _defaultPort_; /*** The socket's InputStream. ***/ protected InputStream _input_; /*** The socket's OutputStream. ***/ protected OutputStream _output_; /*** The socket's SocketFactory. ***/ protected SocketFactory _socketFactory_; /*** * Default constructor for SocketClient. Initializes * _socket_ to null, _timeout_ to 0, _defaultPort to 0, * _isConnected_ to false, and _socketFactory_ to a shared instance of * * DefaultSocketFactory . ***/ public SocketClient() { _socket_ = null; _input_ = null; _output_ = null; _timeout_ = 0; _defaultPort_ = 0; _isConnected_ = false; _socketFactory_ = __DEFAULT_SOCKET_FACTORY; } /*** * Because there are so many connect() methods, the _connectAction_() * method is provided as a means of performing some action immediately * after establishing a connection, rather than reimplementing all * of the connect() methods. The last action performed by every * connect() method after opening a socket is to call this method. *

* This method sets the timeout on the just opened socket to the default * timeout set by setDefaultTimeout() , * sets _input_ and _output_ to the socket's InputStream and OutputStream * respectively, and sets _isConnected_ to true. *

* Subclasses overriding this method should start by calling * super._connectAction_() first to ensure the * initialization of the aforementioned protected variables. ***/ protected void _connectAction_() throws IOException { _socket_.setSoTimeout(_timeout_); _input_ = _socket_.getInputStream(); _output_ = _socket_.getOutputStream(); _isConnected_ = true; } /*** * Opens a Socket connected to a remote host at the specified port and * originating from the current host at a system assigned port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param host The remote host. * @param port The port to connect to on the remote host. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. ***/ public void connect(InetAddress host, int port) throws SocketException, IOException { _socket_ = _socketFactory_.createSocket(host, port); _connectAction_(); } /*** * Opens a Socket connected to a remote host at the specified port and * originating from the current host at a system assigned port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param hostname The name of the remote host. * @param port The port to connect to on the remote host. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void connect(String hostname, int port) throws SocketException, IOException { _socket_ = _socketFactory_.createSocket(hostname, port); _connectAction_(); } /*** * Opens a Socket connected to a remote host at the specified port and * originating from the specified local address and port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param host The remote host. * @param port The port to connect to on the remote host. * @param localAddr The local address to use. * @param localPort The local port to use. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. ***/ public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SocketException, IOException { _socket_ = _socketFactory_.createSocket(host, port, localAddr, localPort); _connectAction_(); } /*** * Opens a Socket connected to a remote host at the specified port and * originating from the specified local address and port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param hostname The name of the remote host. * @param port The port to connect to on the remote host. * @param localAddr The local address to use. * @param localPort The local port to use. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void connect(String hostname, int port, InetAddress localAddr, int localPort) throws SocketException, IOException { _socket_ = _socketFactory_.createSocket(hostname, port, localAddr, localPort); _connectAction_(); } /*** * Opens a Socket connected to a remote host at the current default port * and originating from the current host at a system assigned port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param host The remote host. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. ***/ public void connect(InetAddress host) throws SocketException, IOException { connect(host, _defaultPort_); } /*** * Opens a Socket connected to a remote host at the current default * port and originating from the current host at a system assigned port. * Before returning, _connectAction_() * is called to perform connection initialization actions. *

* @param hostname The name of the remote host. * @exception SocketException If the socket timeout could not be set. * @exception IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void connect(String hostname) throws SocketException, IOException { connect(hostname, _defaultPort_); } /*** * Disconnects the socket connection. * You should call this method after you've finished using the class * instance and also before you call * connect() * again. _isConnected_ is set to false, _socket_ is set to null, * _input_ is set to null, and _output_ is set to null. *

* @exception IOException If there is an error closing the socket. ***/ public void disconnect() throws IOException { _socket_.close(); _input_.close(); _output_.close(); _socket_ = null; _input_ = null; _output_ = null; _isConnected_ = false; } /*** * Returns true if the client is currently connected to a server. *

* @return True if the client is currently connected to a server, * false otherwise. ***/ public boolean isConnected() { return _isConnected_; } /*** * Sets the default port the SocketClient should connect to when a port * is not specified. The _defaultPort_ * variable stores this value. If never set, the default port is equal * to zero. *

* @param port The default port to set. ***/ public void setDefaultPort(int port) { _defaultPort_ = port; } /*** * Returns the current value of the default port (stored in * _defaultPort_ ). *

* @return The current value of the default port. ***/ public int getDefaultPort() { return _defaultPort_; } /*** * Set the default timeout in milliseconds to use when opening a socket. * This value is only used previous to a call to * connect() * and should not be confused with setSoTimeout() * which operates on an the currently opened socket. _timeout_ contains * the new timeout value. *

* @param timeout The timeout in milliseconds to use for the socket * connection. ***/ public void setDefaultTimeout(int timeout) { _timeout_ = timeout; } /*** * Returns the default timeout in milliseconds that is used when * opening a socket. *

* @return The default timeout in milliseconds that is used when * opening a socket. ***/ public int getDefaultTimeout() { return _timeout_; } /*** * Set the timeout in milliseconds of a currently open connection. * Only call this method after a connection has been opened * by connect(). *

* @param timeout The timeout in milliseconds to use for the currently * open socket connection. * @exception SocketException If the operation fails. ***/ public void setSoTimeout(int timeout) throws SocketException { _socket_.setSoTimeout(timeout); } /*** * Returns the timeout in milliseconds of the currently opened socket. *

* @return The timeout in milliseconds of the currently opened socket. * @exception SocketException If the operation fails. ***/ public int getSoTimeout() throws SocketException { return _socket_.getSoTimeout(); } /*** * Enables or disables the Nagle's algorithm (TCP_NODELAY) on the * currently opened socket. *

* @param on True if Nagle's algorithm is to be enabled, false if not. * @exception SocketException If the operation fails. ***/ public void setTcpNoDelay(boolean on) throws SocketException { _socket_.setTcpNoDelay(on); } /*** * Returns true if Nagle's algorithm is enabled on the currently opened * socket. *

* @return True if Nagle's algorithm is enabled on the currently opened * socket, false otherwise. * @exception SocketException If the operation fails. ***/ public boolean getTcpNoDelay() throws SocketException { return _socket_.getTcpNoDelay(); } /*** * Sets the SO_LINGER timeout on the currently opened socket. *

* @param on True if linger is to be enabled, false if not. * @param val The linger timeout (in hundredths of a second?) * @exception SocketException If the operation fails. ***/ public void setSoLinger(boolean on, int val) throws SocketException { _socket_.setSoLinger(on, val); } /*** * Returns the current SO_LINGER timeout of the currently opened socket. *

* @return The current SO_LINGER timeout. If SO_LINGER is disabled returns * -1. * @exception SocketException If the operation fails. ***/ public int getSoLinger() throws SocketException { return _socket_.getSoLinger(); } /*** * Returns the port number of the open socket on the local host used * for the connection. *

* @return The port number of the open socket on the local host used * for the connection. ***/ public int getLocalPort() { return _socket_.getLocalPort(); } /*** * Returns the local address to which the client's socket is bound. *

* @return The local address to which the client's socket is bound. ***/ public InetAddress getLocalAddress() { return _socket_.getLocalAddress(); } /*** * Returns the port number of the remote host to which the client is * connected. *

* @return The port number of the remote host to which the client is * connected. ***/ public int getRemotePort() { return _socket_.getPort(); } /*** * @return The remote address to which the client is connected. ***/ public InetAddress getRemoteAddress() { return _socket_.getInetAddress(); } /*** * Verifies that the remote end of the given socket is connected to the * the same host that the SocketClient is currently connected to. This * is useful for doing a quick security check when a client needs to * accept a connection from a server, such as an FTP data connection or * a BSD R command standard error stream. *

* @return True if the remote hosts are the same, false if not. ***/ public boolean verifyRemote(Socket socket) { InetAddress host1, host2; host1 = socket.getInetAddress(); host2 = getRemoteAddress(); return host1.equals(host2); } /*** * Sets the SocketFactory used by the SocketClient to open socket * connections. If the factory value is null, then a default * factory is used (only do this to reset the factory after having * previously altered it). *

* @param factory The new SocketFactory the SocketClient should use. ***/ public void setSocketFactory(SocketFactory factory) { if(factory == null) _socketFactory_ = __DEFAULT_SOCKET_FACTORY; else _socketFactory_ = factory; } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/SocketFactory.java Index: SocketFactory.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The SocketFactory interface provides a means for the programmer to * control the creation of sockets and provide his own Socket * implementations for use by all classes derived from * SocketClient . * This allows you to provide your own Socket implementations and * to perform security checks or browser capability requests before * creating a Socket. *

*

* @author Daniel F. Savarese * @see DefaultSocketFactory ***/ public interface SocketFactory { /*** * Creates a Socket connected to the given host and port. *

* @param host The hostname to connect to. * @param port The port to connect to. * @return A Socket connected to the given host and port. * @exception UnknownHostException If the hostname cannot be resolved. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(String host, int port) throws UnknownHostException, IOException; /*** * Creates a Socket connected to the given host and port. *

* @param address The address of the host to connect to. * @param port The port to connect to. * @return A Socket connected to the given host and port. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(InetAddress address, int port) throws IOException; /*** * Creates a Socket connected to the given host and port and * originating from the specified local address and port. *

* @param host The hostname to connect to. * @param port The port to connect to. * @param localAddr The local address to use. * @param localPort The local port to use. * @return A Socket connected to the given host and port. * @exception UnknownHostException If the hostname cannot be resolved. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(String host, int port, InetAddress localAddr, int localPort) throws UnknownHostException, IOException; /*** * Creates a Socket connected to the given host and port and * originating from the specified local address and port. *

* @param address The address of the host to connect to. * @param port The port to connect to. * @param localAddr The local address to use. * @param localPort The local port to use. * @return A Socket connected to the given host and port. * @exception IOException If an I/O error occurs while creating the Socket. ***/ public Socket createSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException; /*** * Creates a ServerSocket bound to a specified port. A port * of 0 will create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port) throws IOException; /*** * Creates a ServerSocket bound to a specified port with a given * maximum queue length for incoming connections. A port of 0 will * create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @param backlog The maximum length of the queue for incoming connections. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port, int backlog) throws IOException; /*** * Creates a ServerSocket bound to a specified port on a given local * address with a given maximum queue length for incoming connections. * A port of 0 will * create the ServerSocket on a system-determined free port. *

* @param port The port on which to listen, or 0 to use any free port. * @param backlog The maximum length of the queue for incoming connections. * @param bindAddr The local address to which the ServerSocket should bind. * @return A ServerSocket that will listen on a specified port. * @exception IOException If an I/O error occurs while creating * the ServerSocket. ***/ public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException; } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/TimeTCPClient.java Index: TimeTCPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; import java.util.*; /*** * The TimeTCPClient class is a TCP implementation of a client for the * Time protocol described in RFC 868. To use the class, merely * establish a connection with * connect * and call either getTime() or * getDate() to retrieve the time, then * call disconnect * to close the connection properly. *

*

* @author Daniel F. Savarese * @see TimeUDPClient ***/ public final class TimeTCPClient extends SocketClient { /*** The default time port. It is set to 37 according to RFC 868. ***/ public static final int DEFAULT_PORT = 37; /*** * The number of seconds between 00:00 1 January 1900 and * 00:00 1 January 1970. This value can be useful for converting * time values to other formats. ***/ public static final long SECONDS_1900_TO_1970 = 2208988800L; /*** * The default TimeTCPClient constructor. It merely sets the default * port to DEFAULT_PORT . ***/ public TimeTCPClient () { setDefaultPort(DEFAULT_PORT); } /*** * Retrieves the time from the server and returns it. The time * is the number of seconds since 00:00 (midnight) 1 January 1900 GMT, * as specified by RFC 868. This method reads the raw 32-bit big-endian * unsigned integer from the server, converts it to a Java long, and * returns the value. *

* The server will have closed the connection at this point, so you should * call * disconnect * after calling this method. To retrieve another time, you must * initiate another connection with * connect * before calling getTime() again. *

* @return The time value retrieved from the server. * @exception IOException If an error occurs while fetching the time. ***/ public long getTime() throws IOException { DataInputStream input; input = new DataInputStream(_input_); return (long)(input.readInt() & 0xffffffffL); } /*** * Retrieves the time from the server and returns a Java Date * containing the time converted to the local timezone. *

* The server will have closed the connection at this point, so you should * call * disconnect * after calling this method. To retrieve another time, you must * initiate another connection with * connect * before calling getDate() again. *

* @return A Date value containing the time retrieved from the server * converted to the local timezone. * @exception IOException If an error occurs while fetching the time. ***/ public Date getDate() throws IOException { return new Date((getTime() - SECONDS_1900_TO_1970)*1000L); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/TimeUDPClient.java Index: TimeUDPClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; import java.util.*; /*** * The TimeUDPClient class is a UDP implementation of a client for the * Time protocol described in RFC 868. To use the class, merely * open a local datagram socket with * open * and call getTime or * getDate to retrieve the time. Then call * close * to close the connection properly. Unlike * TimeTCPClient , * successive calls to getTime or * getDate are permitted * without re-establishing a connection. That is because UDP is a * connectionless protocol and the Time protocol is stateless. *

*

* @author Daniel F. Savarese * @see TimeTCPClient ***/ public final class TimeUDPClient extends DatagramSocketClient { /*** The default time port. It is set to 37 according to RFC 868. ***/ public static final int DEFAULT_PORT = 37; /*** * The number of seconds between 00:00 1 January 1900 and * 00:00 1 January 1970. This value can be useful for converting * time values to other formats. ***/ public static final long SECONDS_1900_TO_1970 = 2208988800L; private byte[] __dummyData = new byte[1]; private byte[] __timeData = new byte[4]; /*** * Retrieves the time from the specified server and port and * returns it. The time is the number of seconds since * 00:00 (midnight) 1 January 1900 GMT, as specified by RFC 868. * This method reads the raw 32-bit big-endian * unsigned integer from the server, converts it to a Java long, and * returns the value. *

* @param host The address of the server. * @param port The port of the service. * @return The time value retrieved from the server. * @exception IOException If an error occurs while retrieving the time. ***/ public long getTime(InetAddress host, int port) throws IOException { long time; DatagramPacket sendPacket, receivePacket; sendPacket = new DatagramPacket(__dummyData, __dummyData.length, host, port); receivePacket = new DatagramPacket(__timeData, __timeData.length); _socket_.send(sendPacket); _socket_.receive(receivePacket); time = 0L; time |= (((__timeData[0] & 0xff) << 24) & 0xffffffffL); time |= (((__timeData[1] & 0xff) << 16) & 0xffffffffL); time |= (((__timeData[2] & 0xff) << 8) & 0xffffffffL); time |= ((__timeData[3] & 0xff) & 0xffffffffL); return time; } /*** Same as getTime(host, DEFAULT_PORT); ***/ public long getTime(InetAddress host) throws IOException { return getTime(host, DEFAULT_PORT); } /*** * Retrieves the time from the server and returns a Java Date * containing the time converted to the local timezone. *

* @param host The address of the server. * @param port The port of the service. * @return A Date value containing the time retrieved from the server * converted to the local timezone. * @exception IOException If an error occurs while fetching the time. ***/ public Date getDate(InetAddress host, int port) throws IOException { return new Date((getTime(host, port) - SECONDS_1900_TO_1970)*1000L); } /*** Same as getTime(host, DEFAULT_PORT); ***/ public Date getDate(InetAddress host) throws IOException { return new Date((getTime(host, DEFAULT_PORT) - SECONDS_1900_TO_1970)*1000L); } } 1.1 jakarta-commons-sandbox/net/src/java/org/apache/commons/net/WhoisClient.java Index: WhoisClient.java =================================================================== package org.apache.commons.net; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Commons" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ import java.io.*; import java.net.*; /*** * The WhoisClient class implements the client side of the Internet Whois * Protocol defined in RFC 954. To query a host you create a * WhoisClient instance, connect to the host, query the host, and finally * disconnect from the host. If the whois service you want to query is on * a non-standard port, connect to the host at that port. * Here's a sample use: *

   *    WhoisClient whois;
   *
   *    whois = new WhoisClient();
   *
   *    try {
   *      whois.connect(WhoisClient.DEFAULT_HOST);
   *      System.out.println(whois.query("foobar"));
   *      whois.disconnect();
   *    } catch(IOException e) {
   *      System.err.println("Error I/O exception: " + e.getMessage());
   *      return;
   *    }
   * 
* *

*

* @author Daniel F. Savarese ***/ public final class WhoisClient extends FingerClient { /*** * The default whois host to query. It is set to whois.internic.net. ***/ public static final String DEFAULT_HOST = "whois.internic.net"; /*** * The default whois port. It is set to 43 according to RFC 954. ***/ public static final int DEFAULT_PORT = 43; /*** * The default whois constructor. Initializes the * default port to DEFAULT_PORT . ***/ public WhoisClient() { setDefaultPort(DEFAULT_PORT); } /*** * Queries the connected whois server for information regarding * the given handle. It is up to the programmer to be familiar with the * handle syntax of the whois server. You must first connect to a whois * server before calling this method, and you should disconnect afterward. *

* @param handle The handle to lookup. * @return The result of the whois query. * @exception IOException If an I/O error occurs during the operation. ***/ public String query(String handle) throws IOException { return query(false, handle); } /*** * Queries the connected whois server for information regarding * the given handle and returns the InputStream of the network connection. * It is up to the programmer to be familiar with the handle syntax * of the whois server. You must first connect to a finger server before * calling this method, and you should disconnect after finishing reading * the stream. *

* @param handle The handle to lookup. * @return The InputStream of the network connection of the whois query. * Can be read to obtain whois results. * @exception IOException If an I/O error occurs during the operation. ***/ public InputStream getInputStream(String handle) throws IOException { return getInputStream(false, handle); } } -- To unsubscribe, e-mail: For additional commands, e-mail: