From 62893376ddaad6f3aaf8d7cac5c6713cfde42568 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 19 Aug 2014 19:22:08 +0200 Subject: [PATCH] Cleanup Bytestream and Streamhost remove unnecessary setPort() setter. --- .../socks5/Socks5BytestreamManager.java | 5 +--- .../bytestreams/socks5/packet/Bytestream.java | 23 +++++++------------ .../socks5/Socks5ByteStreamManagerTest.java | 5 ++-- .../socks5/Socks5ClientForInitiatorTest.java | 16 ++++++------- .../bytestreams/socks5/Socks5ClientTest.java | 12 ++++------ .../bytestreams/socks5/Socks5ProxyTest.java | 1 - 6 files changed, 24 insertions(+), 38 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java index d70848e73..b82596ad4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java @@ -674,10 +674,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { continue outerloop; } } - StreamHost streamHost = new StreamHost(this.connection.getUser(), - address); - streamHost.setPort(port); - streamHosts.add(streamHost); + streamHosts.add(new StreamHost(connection.getUser(), address, port)); } return streamHosts; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java index 9d8879c6f..1d3b65cbe 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java @@ -49,7 +49,6 @@ public class Bytestream extends IQ { * The default constructor */ public Bytestream() { - super(); } /** @@ -59,7 +58,6 @@ public class Bytestream extends IQ { * @see #setSessionID(String) */ public Bytestream(final String SID) { - super(); setSessionID(SID); } @@ -123,8 +121,7 @@ public class Bytestream extends IQ { * @return The added stream host. */ public StreamHost addStreamHost(final String JID, final String address, final int port) { - StreamHost host = new StreamHost(JID, address); - host.setPort(port); + StreamHost host = new StreamHost(JID, address, port); addStreamHost(host); return host; @@ -276,7 +273,11 @@ public class Bytestream extends IQ { private final String addy; - private int port = 0; + private final int port; + + public StreamHost(String jid, String address) { + this(jid, address, 0); + } /** * Default constructor. @@ -284,9 +285,10 @@ public class Bytestream extends IQ { * @param JID The JID of the stream host. * @param address The internet address of the stream host. */ - public StreamHost(final String JID, final String address) { + public StreamHost(final String JID, final String address, int port) { this.JID = JID; this.addy = address; + this.port = port; } /** @@ -307,15 +309,6 @@ public class Bytestream extends IQ { return addy; } - /** - * Sets the port of the stream host. - * - * @param port The port on which the potential stream host would accept the connection. - */ - public void setPort(final int port) { - this.port = port; - } - /** * Returns the port on which the potential stream host would accept the connection. * diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java index 1a06159e5..4b5440a77 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java @@ -813,8 +813,9 @@ public class Socks5ByteStreamManagerTest { // connect to proxy as target socks5Proxy.addTransfer(digest); - StreamHost streamHost = new StreamHost(targetJID, socks5Proxy.getLocalAddresses().get(0)); - streamHost.setPort(socks5Proxy.getPort()); + StreamHost streamHost = new StreamHost(targetJID, + socks5Proxy.getLocalAddresses().get(0), + socks5Proxy.getPort()); Socks5Client socks5Client = new Socks5Client(streamHost, digest); InputStream inputStream = socks5Client.getSocket(2000).getInputStream(); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java index 3b5c169c6..478b4c118 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java @@ -95,8 +95,8 @@ public class Socks5ClientForInitiatorTest { // build stream host information for local SOCKS5 proxy StreamHost streamHost = new StreamHost(connection.getUser(), - socks5Proxy.getLocalAddresses().get(0)); - streamHost.setPort(socks5Proxy.getPort()); + socks5Proxy.getLocalAddresses().get(0), + socks5Proxy.getPort()); // create digest to get the socket opened by target String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID); @@ -142,8 +142,8 @@ public class Socks5ClientForInitiatorTest { // build stream host information final StreamHost streamHost = new StreamHost(connection.getUser(), - socks5Proxy.getLocalAddresses().get(0)); - streamHost.setPort(socks5Proxy.getPort()); + socks5Proxy.getLocalAddresses().get(0), + socks5Proxy.getPort()); // target connects to local SOCKS5 proxy Thread targetThread = new Thread() { @@ -216,8 +216,8 @@ public class Socks5ClientForInitiatorTest { Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort); socks5Proxy.start(); - StreamHost streamHost = new StreamHost(proxyJID, socks5Proxy.getAddress()); - streamHost.setPort(socks5Proxy.getPort()); + StreamHost streamHost = new StreamHost(proxyJID, + socks5Proxy.getAddress(), socks5Proxy.getPort()); // create digest to get the socket opened by target String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID); @@ -276,8 +276,8 @@ public class Socks5ClientForInitiatorTest { Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort); socks5Proxy.start(); - StreamHost streamHost = new StreamHost(proxyJID, socks5Proxy.getAddress()); - streamHost.setPort(socks5Proxy.getPort()); + StreamHost streamHost = new StreamHost(proxyJID, + socks5Proxy.getAddress(), socks5Proxy.getPort()); // create digest to get the socket opened by target String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java index ffaf06428..34800a10c 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java @@ -72,8 +72,7 @@ public class Socks5ClientTest { @Override public void run() { - StreamHost streamHost = new StreamHost(proxyJID, serverAddress); - streamHost.setPort(serverPort); + StreamHost streamHost = new StreamHost(proxyJID, serverAddress, serverPort); Socks5Client socks5Client = new Socks5Client(streamHost, digest); @@ -131,8 +130,7 @@ public class Socks5ClientTest { @Override public void run() { - StreamHost streamHost = new StreamHost(proxyJID, serverAddress); - streamHost.setPort(serverPort); + StreamHost streamHost = new StreamHost(proxyJID, serverAddress, serverPort); Socks5Client socks5Client = new Socks5Client(streamHost, digest); try { @@ -194,8 +192,7 @@ public class Socks5ClientTest { @Override public void run() { - StreamHost streamHost = new StreamHost(proxyJID, serverAddress); - streamHost.setPort(serverPort); + StreamHost streamHost = new StreamHost(proxyJID, serverAddress, serverPort); Socks5Client socks5Client = new Socks5Client(streamHost, digest); try { @@ -261,8 +258,7 @@ public class Socks5ClientTest { @Override public void run() { - StreamHost streamHost = new StreamHost(proxyJID, serverAddress); - streamHost.setPort(serverPort); + StreamHost streamHost = new StreamHost(proxyJID, serverAddress, serverPort); Socks5Client socks5Client = new Socks5Client(streamHost, digest); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java index 3a2cb5134..0116414ef 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java @@ -30,7 +30,6 @@ import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.After;