Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 78558 invoked from network); 27 Aug 2006 15:39:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Aug 2006 15:39:06 -0000 Received: (qmail 93803 invoked by uid 500); 27 Aug 2006 15:38:59 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 93757 invoked by uid 500); 27 Aug 2006 15:38:59 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: 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 93670 invoked by uid 500); 27 Aug 2006 15:38:59 -0000 Received: (qmail 93519 invoked by uid 99); 27 Aug 2006 15:38:58 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 08:38:58 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 08:38:56 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 073E21A981A; Sun, 27 Aug 2006 08:38:35 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r437387 - in /jakarta/commons/proper/net/branches/JDK_1_5_BRANCH: ./ src/main/java/examples/ src/main/java/examples/ntp/ src/main/java/org/apache/commons/net/ src/main/java/org/apache/commons/net/chargen/ src/main/java/org/apache/commons/ne... Date: Sun, 27 Aug 2006 15:38:31 -0000 To: commons-cvs@jakarta.apache.org From: rwinston@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060827153836.073E21A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rwinston Date: Sun Aug 27 08:38:28 2006 New Revision: 437387 URL: http://svn.apache.org/viewvc?rev=437387&view=rev Log: (empty) Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/FingerClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/WhoisClient.java Removed: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/CharGenTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/CharGenUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/DaytimeTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/DaytimeUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/DiscardTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/DiscardUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/EchoTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/EchoUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/FingerClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/TimeTCPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/TimeUDPClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/WhoisClient.java Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/ (props changed) jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/chargen.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/daytime.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/echo.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/finger.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/fwhois.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/ntp/TimeClient.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/rdate.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/test/java/org/apache/commons/net/time/TimeTCPClientTest.java jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/xdocs/changes.xml Propchange: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Sun Aug 27 08:38:28 2006 @@ -8,3 +8,4 @@ *.log *.$$$ bin +.fbwarnings Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/chargen.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/chargen.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/chargen.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/chargen.java Sun Aug 27 08:38:28 2006 @@ -21,8 +21,9 @@ import java.io.InterruptedIOException; import java.net.InetAddress; import java.net.SocketException; -import org.apache.commons.net.CharGenTCPClient; -import org.apache.commons.net.CharGenUDPClient; + +import org.apache.commons.net.chargen.CharGenTCPClient; +import org.apache.commons.net.chargen.CharGenUDPClient; /*** * This is an example program demonstrating how to use the CharGenTCPClient Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/daytime.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/daytime.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/daytime.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/daytime.java Sun Aug 27 08:38:28 2006 @@ -17,8 +17,9 @@ import java.io.IOException; import java.net.InetAddress; -import org.apache.commons.net.DaytimeTCPClient; -import org.apache.commons.net.DaytimeUDPClient; + +import org.apache.commons.net.daytime.DaytimeTCPClient; +import org.apache.commons.net.daytime.DaytimeUDPClient; /*** * This is an example program demonstrating how to use the DaytimeTCP Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/echo.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/echo.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/echo.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/echo.java Sun Aug 27 08:38:28 2006 @@ -23,8 +23,9 @@ import java.io.PrintWriter; import java.net.InetAddress; import java.net.SocketException; -import org.apache.commons.net.EchoTCPClient; -import org.apache.commons.net.EchoUDPClient; + +import org.apache.commons.net.echo.EchoTCPClient; +import org.apache.commons.net.echo.EchoUDPClient; /*** * This is an example program demonstrating how to use the EchoTCPClient Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/finger.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/finger.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/finger.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/finger.java Sun Aug 27 08:38:28 2006 @@ -18,7 +18,8 @@ import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import org.apache.commons.net.FingerClient; + +import org.apache.commons.net.finger.FingerClient; /*** * This is an example of how you would implement the finger command Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/fwhois.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/fwhois.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/fwhois.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/fwhois.java Sun Aug 27 08:38:28 2006 @@ -18,7 +18,8 @@ import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import org.apache.commons.net.WhoisClient; + +import org.apache.commons.net.whois.WhoisClient; /*** * This is an example of how you would implement the Linux fwhois command Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/ntp/TimeClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/ntp/TimeClient.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/ntp/TimeClient.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/ntp/TimeClient.java Sun Aug 27 08:38:28 2006 @@ -18,8 +18,9 @@ import java.io.IOException; import java.net.InetAddress; -import org.apache.commons.net.TimeTCPClient; -import org.apache.commons.net.TimeUDPClient; + +import org.apache.commons.net.time.TimeTCPClient; +import org.apache.commons.net.time.TimeUDPClient; /*** * This is an example program demonstrating how to use the TimeTCPClient Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/rdate.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/rdate.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/rdate.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/examples/rdate.java Sun Aug 27 08:38:28 2006 @@ -17,8 +17,9 @@ import java.io.IOException; import java.net.InetAddress; -import org.apache.commons.net.TimeTCPClient; -import org.apache.commons.net.TimeUDPClient; + +import org.apache.commons.net.time.TimeTCPClient; +import org.apache.commons.net.time.TimeUDPClient; /*** * This is an example program demonstrating how to use the TimeTCPClient Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenTCPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenTCPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenTCPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenTCPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,84 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.chargen; + +import java.io.InputStream; + +import org.apache.commons.net.SocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.SocketClient#connect connect } + * and call {@link #getInputStream getInputStream() } to access + * the data. Don't close the input stream when you're done with it. Rather, + * call {@link org.apache.commons.net.SocketClient#disconnect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * to clean up properly. + *

+ * @return An InputStream from which the server generated data can be read. + ***/ + public InputStream getInputStream() + { + return _input_; + } +} + + + + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,127 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.chargen; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; + +import org.apache.commons.net.DatagramSocketClient; + +/*** + * 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 {@link org.apache.commons.net.DatagramSocketClient#open open } + * and call {@link #send send } to send the datagram that will + * initiate the data reply. For chargen or quote of the day, just + * call {@link #receive 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 + * {@link org.apache.commons.net.DatagramSocketClient#close 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; + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,90 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.daytime; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.commons.net.SocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.SocketClient#connect connect } + * and call {@link #getTime getTime() } to retrieve the daytime + * string, then + * call {@link org.apache.commons.net.SocketClient#disconnect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * after calling this method. To retrieve another time, you must + * initiate another connection with + * {@link org.apache.commons.net.SocketClient#connect 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(); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,82 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.daytime; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; + +import org.apache.commons.net.DatagramSocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.DatagramSocketClient#open open } + * and call {@link #getTime getTime } to retrieve the daytime + * string, then + * call {@link org.apache.commons.net.DatagramSocketClient#close close } + * to close the connection properly. Unlike + * {@link org.apache.commons.net.daytime.DaytimeTCPClient}, + * successive calls to {@link #getTime 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); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,65 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.discard; + +import java.io.OutputStream; + +import org.apache.commons.net.SocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.SocketClient#connect connect } + * and call {@link #getOutputStream getOutputStream() } to + * retrieve the discard output stream. Don't close the output stream + * when you're done writing to it. Rather, call + * {@link org.apache.commons.net.SocketClient#disconnect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * to clean up properly. + *

+ * @return An OutputStream through which you can write data to the server. + ***/ + public OutputStream getOutputStream() + { + return _output_; + } +} Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,95 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.discard; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; + +import org.apache.commons.net.DatagramSocketClient; + +/*** + * 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 {@link org.apache.commons.net.DatagramSocketClient#open open } + * and call {@link #send send } to send datagrams to the server + * After you're done sending discard data, call + * {@link org.apache.commons.net.DatagramSocketClient#close 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); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoTCPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoTCPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoTCPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoTCPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,71 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.echo; + +import java.io.InputStream; + +import org.apache.commons.net.SocketClient; +import org.apache.commons.net.discard.DiscardTCPClient; + +/*** + * 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 + * {@link org.apache.commons.net.SocketClient#connect connect } + * and call {@link DiscardTCPClient#getOutputStream getOutputStream() } to + * retrieve the echo output stream and + * {@link #getInputStream getInputStream() } + * to get the echo input stream. + * Don't close either stream when you're done using them. Rather, call + * {@link org.apache.commons.net.SocketClient#disconnect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * to clean up properly. + *

+ * @return An InputStream from which you can read echoed data from the + * server. + ***/ + public InputStream getInputStream() + { + return _input_; + } + +} Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,98 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.echo; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; + +import org.apache.commons.net.DatagramSocketClient; +import org.apache.commons.net.discard.DiscardUDPClient; + +/*** + * 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 {@link org.apache.commons.net.DatagramSocketClient#open open } + * and call {@link #send send } to send datagrams to the server, + * then call {@link #receive receive } to receive echoes. + * After you're done echoing data, call + * {@link org.apache.commons.net.DatagramSocketClient#close 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); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/FingerClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/FingerClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/FingerClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/finger/FingerClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,174 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.finger; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.commons.net.SocketClient; + +/*** + * 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 + { + DataOutputStream output; + + __query.setLength(0); + if (longOutput) + __query.append(__LONG_FLAG); + __query.append(username); + __query.append(SocketClient.NETASCII_EOL); + + output = + new DataOutputStream(new BufferedOutputStream(_output_, 1024)); + 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, ""); + } + +} Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeTCPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeTCPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeTCPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeTCPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,107 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.time; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.Date; + +import org.apache.commons.net.SocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.SocketClient#connect connect } + * and call either {@link #getTime getTime() } or + * {@link #getDate getDate() } to retrieve the time, then + * call {@link org.apache.commons.net.SocketClient#disconnect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * after calling this method. To retrieve another time, you must + * initiate another connection with + * {@link org.apache.commons.net.SocketClient#connect 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 + * {@link org.apache.commons.net.SocketClient#disconnect disconnect } + * after calling this method. To retrieve another time, you must + * initiate another connection with + * {@link org.apache.commons.net.SocketClient#connect 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); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeUDPClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeUDPClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeUDPClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/time/TimeUDPClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,125 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.time; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.util.Date; + +import org.apache.commons.net.DatagramSocketClient; + +/*** + * 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 + * {@link org.apache.commons.net.DatagramSocketClient#open open } + * and call {@link #getTime getTime } or + * {@link #getTime getDate } to retrieve the time. Then call + * {@link org.apache.commons.net.DatagramSocketClient#close close } + * to close the connection properly. Unlike + * {@link org.apache.commons.net.time.TimeTCPClient}, + * successive calls to {@link #getTime getTime } or + * {@link #getDate 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); + } + +} + Added: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/WhoisClient.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/WhoisClient.java?rev=437387&view=auto ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/WhoisClient.java (added) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/whois/WhoisClient.java Sun Aug 27 08:38:28 2006 @@ -0,0 +1,107 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.net.whois; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.net.finger.FingerClient; + +/*** + * 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); + } + +} + Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/test/java/org/apache/commons/net/time/TimeTCPClientTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/test/java/org/apache/commons/net/time/TimeTCPClientTest.java?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/test/java/org/apache/commons/net/time/TimeTCPClientTest.java (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/test/java/org/apache/commons/net/time/TimeTCPClientTest.java Sun Aug 27 08:38:28 2006 @@ -61,7 +61,6 @@ import java.util.TimeZone; import junit.framework.TestCase; -import org.apache.commons.net.TimeTCPClient; public class TimeTCPClientTest extends TestCase { Modified: jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/xdocs/changes.xml?rev=437387&r1=437386&r2=437387&view=diff ============================================================================== --- jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/xdocs/changes.xml (original) +++ jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/xdocs/changes.xml Sun Aug 27 08:38:28 2006 @@ -71,6 +71,9 @@ Added an FTP parser for Netware FTP servers. + + Remove reflective check for Socket::isConnected() (no longer needed) + --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org