You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/24 15:02:11 UTC

[commons-net] branch master updated (5586d0d3 -> 92a80e47)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


    from 5586d0d3 Clean up exception handling in example
     new 3502a3b0 Add and use DatagramSocketClient#getSoTimeoutDuration().
     new fd4fc19d Don't reinitialize to default values
     new a6816444 Add and use DatagramSocketClient.checkOpen()
     new 3d75d6fe Javadoc
     new 252832a6 Better name
     new d817fef6 Better name
     new 83d1d9ff Better name
     new 582ee31c Better name
     new 92a80e47 Use Boolean.getBoolean()

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  9 ++++
 .../apache/commons/net/DatagramSocketClient.java   | 61 +++++++++++++++++-----
 .../apache/commons/net/DatagramSocketFactory.java  |  4 +-
 .../commons/net/DefaultDatagramSocketFactory.java  | 11 ++--
 .../commons/net/chargen/CharGenUDPClient.java      |  4 +-
 .../commons/net/daytime/DaytimeUDPClient.java      |  4 +-
 .../commons/net/discard/DiscardUDPClient.java      |  2 +-
 .../org/apache/commons/net/echo/EchoUDPClient.java |  2 +-
 .../apache/commons/net/examples/unix/chargen.java  |  3 +-
 .../org/apache/commons/net/examples/unix/echo.java |  3 +-
 .../java/org/apache/commons/net/ftp/FTPClient.java |  2 +-
 .../org/apache/commons/net/ntp/NTPUDPClient.java   |  4 +-
 .../java/org/apache/commons/net/tftp/TFTP.java     | 16 +++---
 .../org/apache/commons/net/time/TimeUDPClient.java |  4 +-
 .../org/apache/commons/net/tftp/TFTPServer.java    | 20 +++----
 15 files changed, 96 insertions(+), 53 deletions(-)


[commons-net] 03/09: Add and use DatagramSocketClient.checkOpen()

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit a6816444010d0dcad14e497de7a068ce6dd095eb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:49:16 2023 -0400

    Add and use DatagramSocketClient.checkOpen()
---
 src/changes/changes.xml                            |  3 +++
 .../apache/commons/net/DatagramSocketClient.java   | 23 ++++++++++++++++------
 .../commons/net/chargen/CharGenUDPClient.java      |  4 ++--
 .../commons/net/daytime/DaytimeUDPClient.java      |  4 ++--
 .../commons/net/discard/DiscardUDPClient.java      |  2 +-
 .../org/apache/commons/net/echo/EchoUDPClient.java |  2 +-
 .../org/apache/commons/net/ntp/NTPUDPClient.java   |  4 ++--
 .../java/org/apache/commons/net/tftp/TFTP.java     | 10 +++++-----
 .../org/apache/commons/net/time/TimeUDPClient.java |  4 ++--
 9 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6a5fbe00..3af73342 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -78,6 +78,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">
         Add and use DatagramSocketClient#setSoTimeout(Duration).
       </action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">
+        Add and use DatagramSocketClient.checkOpen().
+      </action>
       <!-- FIX -->
       <action type="fix" issue="NET-650" dev="ggregory" due-to="Matthew McGillis, exceptionfactory, sebbASF">
         Delegate host resolution to Socket.connect() #138.
diff --git a/src/main/java/org/apache/commons/net/DatagramSocketClient.java b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
index f3bf647d..a9f75fe8 100644
--- a/src/main/java/org/apache/commons/net/DatagramSocketClient.java
+++ b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
@@ -22,6 +22,7 @@ import java.net.InetAddress;
 import java.net.SocketException;
 import java.nio.charset.Charset;
 import java.time.Duration;
+import java.util.Objects;
 
 /**
  * The DatagramSocketClient provides the basic operations that are required of client objects accessing datagram sockets. It is meant to be subclassed to avoid
@@ -68,6 +69,16 @@ public abstract class DatagramSocketClient {
     public DatagramSocketClient() {
     }
 
+    /**
+     * Returns the non-null DatagramSocket or throwns {@link NullPointerException}.
+     *
+     * @return the non-null DatagramSocket.
+     * @since 3.10.0
+     */
+    protected DatagramSocket checkOpen() {
+        return Objects.requireNonNull(_socket_, "DatagramSocket");
+    }
+
     /**
      * 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
      * {@link #open open() } again. _isOpen_ is set to false and _socket_ is set to null.
@@ -118,7 +129,7 @@ public abstract class DatagramSocketClient {
      * @return The local address to which the client's socket is bound.
      */
     public InetAddress getLocalAddress() {
-        return _socket_.getLocalAddress();
+        return checkOpen().getLocalAddress();
     }
 
     /**
@@ -128,7 +139,7 @@ public abstract class DatagramSocketClient {
      * @return The port number of the open socket on the local host used for the connection.
      */
     public int getLocalPort() {
-        return _socket_.getLocalPort();
+        return checkOpen().getLocalPort();
     }
 
     /**
@@ -141,7 +152,7 @@ public abstract class DatagramSocketClient {
      */
     @Deprecated
     public int getSoTimeout() throws SocketException {
-        return _socket_.getSoTimeout();
+        return checkOpen().getSoTimeout();
     }
 
     /**
@@ -152,7 +163,7 @@ public abstract class DatagramSocketClient {
      * @throws SocketException if an error getting the timeout.
      */
     public Duration getSoTimeoutDuration() throws SocketException {
-        return Duration.ofMillis(_socket_.getSoTimeout());
+        return Duration.ofMillis(checkOpen().getSoTimeout());
     }
 
     /**
@@ -265,7 +276,7 @@ public abstract class DatagramSocketClient {
      * @since 3.10.0
      */
     public void setSoTimeout(final Duration timeout) throws SocketException {
-        _socket_.setSoTimeout(Math.toIntExact(timeout.toMillis()));
+        checkOpen().setSoTimeout(Math.toIntExact(timeout.toMillis()));
     }
 
     /**
@@ -277,6 +288,6 @@ public abstract class DatagramSocketClient {
      */
     @Deprecated
     public void setSoTimeout(final int timeout) throws SocketException {
-        _socket_.setSoTimeout(timeout);
+        checkOpen().setSoTimeout(timeout);
     }
 }
diff --git a/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java b/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java
index 815b32f5..8253bcbb 100644
--- a/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java
+++ b/src/main/java/org/apache/commons/net/chargen/CharGenUDPClient.java
@@ -76,7 +76,7 @@ public final class CharGenUDPClient extends DatagramSocketClient {
         final int length;
         final byte[] result;
 
-        _socket_.receive(receivePacket);
+        checkOpen().receive(receivePacket);
 
         result = new byte[length = receivePacket.getLength()];
         System.arraycopy(receiveData, 0, result, 0, length);
@@ -104,7 +104,7 @@ public final class CharGenUDPClient extends DatagramSocketClient {
     public void send(final InetAddress host, final int port) throws IOException {
         sendPacket.setAddress(host);
         sendPacket.setPort(port);
-        _socket_.send(sendPacket);
+        checkOpen().send(sendPacket);
     }
 
 }
diff --git a/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java b/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java
index deb439ac..84495441 100644
--- a/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java
+++ b/src/main/java/org/apache/commons/net/daytime/DaytimeUDPClient.java
@@ -66,8 +66,8 @@ public final class DaytimeUDPClient extends DatagramSocketClient {
         sendPacket = new DatagramPacket(dummyData, dummyData.length, host, port);
         receivePacket = new DatagramPacket(timeData, timeData.length);
 
-        _socket_.send(sendPacket);
-        _socket_.receive(receivePacket);
+        checkOpen().send(sendPacket);
+        checkOpen().receive(receivePacket);
 
         return new String(receivePacket.getData(), 0, receivePacket.getLength(), getCharset()); // Java 1.6 can use getCharset()
     }
diff --git a/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java b/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java
index 5fb9f409..4353dd53 100644
--- a/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java
+++ b/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java
@@ -81,7 +81,7 @@ public class DiscardUDPClient extends DatagramSocketClient {
         sendPacket.setLength(length);
         sendPacket.setAddress(host);
         sendPacket.setPort(port);
-        _socket_.send(sendPacket);
+        checkOpen().send(sendPacket);
     }
 
 }
diff --git a/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java b/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java
index fb4caa55..da642a4e 100644
--- a/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java
+++ b/src/main/java/org/apache/commons/net/echo/EchoUDPClient.java
@@ -63,7 +63,7 @@ public final class EchoUDPClient extends DiscardUDPClient {
     public int receive(final byte[] data, final int length) throws IOException {
         receivePacket.setData(data);
         receivePacket.setLength(length);
-        _socket_.receive(receivePacket);
+        checkOpen().receive(receivePacket);
         return receivePacket.getLength();
     }
 
diff --git a/src/main/java/org/apache/commons/net/ntp/NTPUDPClient.java b/src/main/java/org/apache/commons/net/ntp/NTPUDPClient.java
index 9fe4a711..c606252f 100644
--- a/src/main/java/org/apache/commons/net/ntp/NTPUDPClient.java
+++ b/src/main/java/org/apache/commons/net/ntp/NTPUDPClient.java
@@ -88,8 +88,8 @@ public final class NTPUDPClient extends DatagramSocketClient {
         // in server response is all 0's which is "Thu Feb 07 01:28:16 EST 2036".
         message.setTransmitTime(now);
 
-        _socket_.send(sendPacket);
-        _socket_.receive(receivePacket);
+        checkOpen().send(sendPacket);
+        checkOpen().receive(receivePacket);
 
         final long returnTimeMillis = System.currentTimeMillis();
 
diff --git a/src/main/java/org/apache/commons/net/tftp/TFTP.java b/src/main/java/org/apache/commons/net/tftp/TFTP.java
index afee0a0d..84ee0d84 100644
--- a/src/main/java/org/apache/commons/net/tftp/TFTP.java
+++ b/src/main/java/org/apache/commons/net/tftp/TFTP.java
@@ -157,7 +157,7 @@ public class TFTP extends DatagramSocketClient {
     public final TFTPPacket bufferedReceive() throws IOException, InterruptedIOException, SocketException, TFTPPacketException {
         receiveDatagram.setData(receiveBuffer);
         receiveDatagram.setLength(receiveBuffer.length);
-        _socket_.receive(receiveDatagram);
+        checkOpen().receive(receiveDatagram);
 
         final TFTPPacket newTFTPPacket = TFTPPacket.newTFTPPacket(receiveDatagram);
         trace("<", newTFTPPacket);
@@ -177,7 +177,7 @@ public class TFTP extends DatagramSocketClient {
      */
     public final void bufferedSend(final TFTPPacket packet) throws IOException {
         trace(">", packet);
-        _socket_.send(packet.newDatagram(sendDatagram, sendBuffer));
+        checkOpen().send(packet.newDatagram(sendDatagram, sendBuffer));
     }
 
     /**
@@ -197,7 +197,7 @@ public class TFTP extends DatagramSocketClient {
 
         try {
             while (true) {
-                _socket_.receive(datagram);
+                checkOpen().receive(datagram);
             }
         } catch (final SocketException | InterruptedIOException e) {
             // Do nothing. We timed out, so we hope we're caught up.
@@ -232,7 +232,7 @@ public class TFTP extends DatagramSocketClient {
 
         packet = new DatagramPacket(new byte[PACKET_SIZE], PACKET_SIZE);
 
-        _socket_.receive(packet);
+        checkOpen().receive(packet);
 
         final TFTPPacket newTFTPPacket = TFTPPacket.newTFTPPacket(packet);
         trace("<", newTFTPPacket);
@@ -247,7 +247,7 @@ public class TFTP extends DatagramSocketClient {
      */
     public final void send(final TFTPPacket packet) throws IOException {
         trace(">", packet);
-        _socket_.send(packet.newDatagram());
+        checkOpen().send(packet.newDatagram());
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/net/time/TimeUDPClient.java b/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
index 4b9d4d7c..37b10a9d 100644
--- a/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
+++ b/src/main/java/org/apache/commons/net/time/TimeUDPClient.java
@@ -98,8 +98,8 @@ public final class TimeUDPClient extends DatagramSocketClient {
         sendPacket = new DatagramPacket(dummyData, dummyData.length, host, port);
         receivePacket = new DatagramPacket(timeData, timeData.length);
 
-        _socket_.send(sendPacket);
-        _socket_.receive(receivePacket);
+        checkOpen().send(sendPacket);
+        checkOpen().receive(receivePacket);
 
         time = 0L;
         time |= (((timeData[0] & 0xff) << 24) & 0xffffffffL);


[commons-net] 05/09: Better name

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 252832a663d9ba036f677c072ad00af2d7f8c42b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:50:27 2023 -0400

    Better name
---
 .../java/org/apache/commons/net/DefaultDatagramSocketFactory.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java b/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
index 72a7842d..27191c00 100644
--- a/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
+++ b/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
@@ -59,12 +59,12 @@ public class DefaultDatagramSocketFactory implements DatagramSocketFactory {
      * 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.
+     * @param localAddress The local address to use.
      * @return a new DatagramSocket
      * @throws SocketException If the socket could not be created.
      */
     @Override
-    public DatagramSocket createDatagramSocket(final int port, final InetAddress laddr) throws SocketException {
-        return new DatagramSocket(port, laddr);
+    public DatagramSocket createDatagramSocket(final int port, final InetAddress localAddress) throws SocketException {
+        return new DatagramSocket(port, localAddress);
     }
 }


[commons-net] 01/09: Add and use DatagramSocketClient#getSoTimeoutDuration().

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 3502a3b0834ced423894a48c7453f681ef47d4c4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:40:17 2023 -0400

    Add and use DatagramSocketClient#getSoTimeoutDuration().
    
    Add and use DatagramSocketClient#setSoTimeout(Duration).
---
 src/changes/changes.xml                            |  6 +++++
 .../apache/commons/net/DatagramSocketClient.java   | 30 ++++++++++++++++++++--
 .../apache/commons/net/examples/unix/chargen.java  |  3 ++-
 .../org/apache/commons/net/examples/unix/echo.java |  3 ++-
 .../java/org/apache/commons/net/tftp/TFTP.java     |  6 ++---
 5 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3c828368..6a5fbe00 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,12 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">
         Add and use TFTP.DEFAULT_TIMEOUT_DURATION and deprecate org.apache.commons.net.tftp.TFTP.DEFAULT_TIMEOUT.
       </action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">
+        Add and use DatagramSocketClient#getSoTimeoutDuration().
+      </action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">
+        Add and use DatagramSocketClient#setSoTimeout(Duration).
+      </action>
       <!-- FIX -->
       <action type="fix" issue="NET-650" dev="ggregory" due-to="Matthew McGillis, exceptionfactory, sebbASF">
         Delegate host resolution to Socket.connect() #138.
diff --git a/src/main/java/org/apache/commons/net/DatagramSocketClient.java b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
index 2280f3a7..ff78bea4 100644
--- a/src/main/java/org/apache/commons/net/DatagramSocketClient.java
+++ b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
@@ -140,12 +140,25 @@ public abstract class DatagramSocketClient {
      * thrown.
      *
      * @return The timeout in milliseconds of the currently opened socket.
-     * @throws SocketException if an error getting the timeout
+     * @throws SocketException if an error getting the timeout.
+     * @deprecated Use {@link #getSoTimeoutDuration()}.
      */
+    @Deprecated
     public int getSoTimeout() throws SocketException {
         return _socket_.getSoTimeout();
     }
 
+    /**
+     * Returns the timeout duration 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.
+     * @throws SocketException if an error getting the timeout.
+     */
+    public Duration getSoTimeoutDuration() throws SocketException {
+        return Duration.ofMillis(_socket_.getSoTimeout());
+    }
+
     /**
      * Returns true if the client has a currently open socket.
      *
@@ -248,12 +261,25 @@ public abstract class DatagramSocketClient {
         _timeout_ = timeout;
     }
 
+    /**
+     * Set the timeout duration of a currently open connection. Only call this method after a connection has been opened by {@link #open open()}.
+     *
+     * @param timeout The timeout in milliseconds to use for the currently open datagram socket connection.
+     * @throws SocketException if an error setting the timeout.
+     * @since 3.10.0
+     */
+    public void setSoTimeout(final Duration timeout) throws SocketException {
+        _socket_.setSoTimeout(Math.toIntExact(timeout.toMillis()));
+    }
+
     /**
      * Set the timeout in milliseconds of a currently open connection. Only call this method after a connection has been opened by {@link #open open()}.
      *
      * @param timeout The timeout in milliseconds to use for the currently open datagram socket connection.
-     * @throws SocketException if an error setting the timeout
+     * @throws SocketException if an error setting the timeout.
+     * @deprecated Use {@link #setSoTimeout(Duration)}.
      */
+    @Deprecated
     public void setSoTimeout(final int timeout) throws SocketException {
         _socket_.setSoTimeout(timeout);
     }
diff --git a/src/main/java/org/apache/commons/net/examples/unix/chargen.java b/src/main/java/org/apache/commons/net/examples/unix/chargen.java
index 326a7ef0..57482257 100644
--- a/src/main/java/org/apache/commons/net/examples/unix/chargen.java
+++ b/src/main/java/org/apache/commons/net/examples/unix/chargen.java
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
 import java.io.InterruptedIOException;
 import java.net.InetAddress;
 import java.net.SocketException;
+import java.time.Duration;
 
 import org.apache.commons.net.chargen.CharGenTCPClient;
 import org.apache.commons.net.chargen.CharGenUDPClient;
@@ -71,7 +72,7 @@ public final class chargen {
         client.open();
         // If we don't receive a return packet within 5 seconds, assume
         // the packet is lost.
-        client.setSoTimeout(5000);
+        client.setSoTimeout(Duration.ofSeconds(5));
 
         while (packets-- > 0) {
             client.send(address);
diff --git a/src/main/java/org/apache/commons/net/examples/unix/echo.java b/src/main/java/org/apache/commons/net/examples/unix/echo.java
index b753179d..a61097b4 100644
--- a/src/main/java/org/apache/commons/net/examples/unix/echo.java
+++ b/src/main/java/org/apache/commons/net/examples/unix/echo.java
@@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.InetAddress;
 import java.net.SocketException;
+import java.time.Duration;
 
 import org.apache.commons.net.echo.EchoTCPClient;
 import org.apache.commons.net.echo.EchoUDPClient;
@@ -77,7 +78,7 @@ public final class echo {
 
         client.open();
         // If we don't receive an echo within 5 seconds, assume the packet is lost.
-        client.setSoTimeout(5000);
+        client.setSoTimeout(Duration.ofSeconds(5));
         System.out.println("Ready to echo to " + host + ".");
 
         // Remember, there are no guarantees about the ordering of returned
diff --git a/src/main/java/org/apache/commons/net/tftp/TFTP.java b/src/main/java/org/apache/commons/net/tftp/TFTP.java
index fe187b65..afee0a0d 100644
--- a/src/main/java/org/apache/commons/net/tftp/TFTP.java
+++ b/src/main/java/org/apache/commons/net/tftp/TFTP.java
@@ -187,13 +187,13 @@ public class TFTP extends DatagramSocketClient {
      * @throws IOException if an I/O error occurs.
      */
     public final void discardPackets() throws IOException {
-        final int to;
+        final Duration to;
         final DatagramPacket datagram;
 
         datagram = new DatagramPacket(new byte[PACKET_SIZE], PACKET_SIZE);
 
-        to = getSoTimeout();
-        setSoTimeout(1);
+        to = getSoTimeoutDuration();
+        setSoTimeout(Duration.ofMillis(1));
 
         try {
             while (true) {


[commons-net] 08/09: Better name

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 582ee31c9a36545ebd7aa8632c3b4fd6be6fa52e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:52:15 2023 -0400

    Better name
---
 .../java/org/apache/commons/net/tftp/TFTPServer.java | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
index a593713f..e08b32c5 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
@@ -462,7 +462,7 @@ public class TFTPServer implements Runnable {
     private File serverReadDirectory;
     private File serverWriteDirectory;
     private final int port;
-    private final InetAddress laddr;
+    private final InetAddress localAddress;
 
     private Exception serverException;
 
@@ -489,17 +489,17 @@ public class TFTPServer implements Runnable {
      * @param serverReadDirectory  directory for GET requests
      * @param serverWriteDirectory directory for PUT requests
      * @param port                 The local port to bind to.
-     * @param localaddr            The local address to bind to.
+     * @param localAddress            The local address to bind to.
      * @param mode                 A value as specified above.
      * @param log                  Stream to write log message to. If not provided, uses System.out
      * @param errorLog             Stream to write error messages to. If not provided, uses System.err.
      * @throws IOException if the server directory is invalid or does not exist.
      */
-    public TFTPServer(final File serverReadDirectory, final File serverWriteDirectory, final int port, final InetAddress localaddr, final ServerMode mode,
+    public TFTPServer(final File serverReadDirectory, final File serverWriteDirectory, final int port, final InetAddress localAddress, final ServerMode mode,
             final PrintStream log, final PrintStream errorLog) throws IOException {
         this.port = port;
         this.mode = mode;
-        this.laddr = localaddr;
+        this.localAddress = localAddress;
         this.log = log == null ? nullStream : log;
         this.logError = errorLog == null ? nullStream : errorLog;
         launch(serverReadDirectory, serverWriteDirectory);
@@ -527,16 +527,16 @@ public class TFTPServer implements Runnable {
             final PrintStream log, final PrintStream errorLog) throws IOException {
         this.mode = mode;
         this.port = port;
-        InetAddress iaddr = null;
+        InetAddress inetAddress = null;
         if (localiface != null) {
             final Enumeration<InetAddress> ifaddrs = localiface.getInetAddresses();
             if ((ifaddrs != null) && ifaddrs.hasMoreElements()) {
-                iaddr = ifaddrs.nextElement();
+                inetAddress = ifaddrs.nextElement();
             }
         }
         this.log = log == null ? nullStream : log;
         this.logError = errorLog == null ? nullStream : errorLog;
-        this.laddr = iaddr;
+        this.localAddress = inetAddress;
         launch(serverReadDirectory, serverWriteDirectory);
     }
 
@@ -563,7 +563,7 @@ public class TFTPServer implements Runnable {
         this.mode = mode;
         this.log = log == null ? nullStream : log;
         this.logError = errorLog == null ? nullStream : errorLog;
-        this.laddr = null;
+        this.localAddress = null;
         launch(serverReadDirectory, serverWriteDirectory);
     }
 
@@ -646,8 +646,8 @@ public class TFTPServer implements Runnable {
         // we want the server thread to listen forever.
         serverTftp.setDefaultTimeout(Duration.ZERO);
 
-        if (laddr != null) {
-            serverTftp.open(port, laddr);
+        if (localAddress != null) {
+            serverTftp.open(port, localAddress);
         } else {
             serverTftp.open(port);
         }


[commons-net] 09/09: Use Boolean.getBoolean()

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 92a80e479b162a21b5f2fa78641b5ab4ff3be1f9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 11:02:06 2023 -0400

    Use Boolean.getBoolean()
---
 src/main/java/org/apache/commons/net/ftp/FTPClient.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index e8ff80ef..9decbc59 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -562,7 +562,7 @@ public class FTPClient extends FTP implements Configurable {
     /** Map of FEAT responses. If null, has not been initialized. */
     private HashMap<String, Set<String>> featuresMap;
 
-    private boolean ipAddressFromPasvResponse = Boolean.parseBoolean(System.getProperty(FTPClient.FTP_IP_ADDRESS_FROM_PASV_RESPONSE));
+    private boolean ipAddressFromPasvResponse = Boolean.getBoolean(FTPClient.FTP_IP_ADDRESS_FROM_PASV_RESPONSE);
 
     /**
      * Default FTPClient constructor. Creates a new FTPClient instance with the data connection mode set to <code> ACTIVE_LOCAL_DATA_CONNECTION_MODE </code>,


[commons-net] 04/09: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 3d75d6fe2838542736cd4af8103aa2ec11331880
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:50:11 2023 -0400

    Javadoc
---
 .../java/org/apache/commons/net/DefaultDatagramSocketFactory.java    | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java b/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
index 62154bad..72a7842d 100644
--- a/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
+++ b/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
@@ -22,9 +22,8 @@ import java.net.InetAddress;
 import java.net.SocketException;
 
 /**
- * DefaultDatagramSocketFactory implements the DatagramSocketFactory interface by simply wrapping the java.net.DatagramSocket constructors. It is the default
- * DatagramSocketFactory used by {@link org.apache.commons.net.DatagramSocketClient} implementations.
- *
+ * Implements the DatagramSocketFactory interface by simply wrapping the {@link DatagramSocket} constructors. It is the default DatagramSocketFactory used by
+ * {@link org.apache.commons.net.DatagramSocketClient} implementations.
  *
  * @see DatagramSocketFactory
  * @see DatagramSocketClient


[commons-net] 02/09: Don't reinitialize to default values

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit fd4fc19dc8d391c17ec4bc38fb23e8e3a1b6514e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:43:47 2023 -0400

    Don't reinitialize to default values
---
 src/main/java/org/apache/commons/net/DatagramSocketClient.java | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/DatagramSocketClient.java b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
index ff78bea4..f3bf647d 100644
--- a/src/main/java/org/apache/commons/net/DatagramSocketClient.java
+++ b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
@@ -60,16 +60,12 @@ public abstract class DatagramSocketClient {
     protected boolean _isOpen_;
 
     /** The datagram socket's DatagramSocketFactory. */
-    protected DatagramSocketFactory _socketFactory_;
+    protected DatagramSocketFactory _socketFactory_ = DEFAULT_SOCKET_FACTORY;
 
     /**
      * 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;
     }
 
     /**


[commons-net] 06/09: Better name

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit d817fef62e0fb0014959945fc54b368e6e74b046
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:50:52 2023 -0400

    Better name
---
 src/main/java/org/apache/commons/net/DatagramSocketClient.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/DatagramSocketClient.java b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
index a9f75fe8..0ca79396 100644
--- a/src/main/java/org/apache/commons/net/DatagramSocketClient.java
+++ b/src/main/java/org/apache/commons/net/DatagramSocketClient.java
@@ -211,11 +211,11 @@ public abstract class DatagramSocketClient {
      * _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.
+     * @param localAddress The local address to use.
      * @throws SocketException If the socket could not be opened or the timeout could not be set.
      */
-    public void open(final int port, final InetAddress laddr) throws SocketException {
-        _socket_ = _socketFactory_.createDatagramSocket(port, laddr);
+    public void open(final int port, final InetAddress localAddress) throws SocketException {
+        _socket_ = _socketFactory_.createDatagramSocket(port, localAddress);
         _socket_.setSoTimeout(_timeout_);
         _isOpen_ = true;
     }


[commons-net] 07/09: Better name

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 83d1d9ff5e1a366821dc4fa0d8dfb3a3a0c92062
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 24 10:51:13 2023 -0400

    Better name
---
 src/main/java/org/apache/commons/net/DatagramSocketFactory.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/DatagramSocketFactory.java b/src/main/java/org/apache/commons/net/DatagramSocketFactory.java
index 22c04fb0..fc8c2125 100644
--- a/src/main/java/org/apache/commons/net/DatagramSocketFactory.java
+++ b/src/main/java/org/apache/commons/net/DatagramSocketFactory.java
@@ -51,9 +51,9 @@ public interface DatagramSocketFactory {
      * 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.
+     * @param localAddress The local address to use.
      * @return the socket
      * @throws SocketException If the socket could not be created.
      */
-    DatagramSocket createDatagramSocket(int port, InetAddress laddr) throws SocketException;
+    DatagramSocket createDatagramSocket(int port, InetAddress localAddress) throws SocketException;
 }