Skip to content

Use an ArrayList instead of List.of #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/net/sbbi/upnp/impls/InternetGatewayDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -43,6 +45,14 @@
public class InternetGatewayDevice {
private final static Logger log = Logger.getLogger(InternetGatewayDevice.class);

private final static List<String> IGD_URNS;
static {
List<String> list = new ArrayList<String>();
list.add("urn:schemas-upnp-org:device:InternetGatewayDevice:1");
list.add("urn:schemas-upnp-org:device:InternetGatewayDevice:2");
IGD_URNS = Collections.unmodifiableList(list);
}

private final UPNPRootDevice igd;
private UPNPMessageFactory msgFactory;

Expand Down Expand Up @@ -227,9 +237,9 @@ private static InternetGatewayDevice[] lookupDeviceDevices(int timeout, int ttl,
UPNPRootDevice[] devices = null;
InternetGatewayDevice[] rtrVal = null;
if (timeout == -1) {
devices = Discovery.discover(Discovery.DEFAULT_TIMEOUT, ttl, mx, List.of("urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:2"), ni);
devices = Discovery.discover(Discovery.DEFAULT_TIMEOUT, ttl, mx, IGD_URNS, ni);
} else {
devices = Discovery.discover(timeout, ttl, mx, List.of("urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:2"), ni);
devices = Discovery.discover(timeout, ttl, mx, IGD_URNS, ni);
}
if (devices != null) {
Set<InternetGatewayDevice> valid = new HashSet<InternetGatewayDevice>();
Expand Down
16 changes: 13 additions & 3 deletions src/net/sbbi/upnp/remote/UnicastRemoteObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.List;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.ExportException;
Expand All @@ -25,6 +24,9 @@
import java.rmi.server.RemoteStub;
import java.rmi.server.ServerCloneException;
import java.rmi.server.ServerRef;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.sbbi.upnp.Discovery;
import net.sbbi.upnp.devices.UPNPDevice;
Expand Down Expand Up @@ -73,6 +75,14 @@ public class UnicastRemoteObject extends RemoteServer {
int.class, RMIClientSocketFactory.class, RMIServerSocketFactory.class
};

private final static List<String> IGD_URNS;
static {
List<String> list = new ArrayList<String>();
list.add("urn:schemas-upnp-org:device:InternetGatewayDevice:1");
list.add("urn:schemas-upnp-org:device:InternetGatewayDevice:2");
IGD_URNS = Collections.unmodifiableList(list);
}

private final static Object DISCOVERY_PROCESS = new Object();
private final static Object ANONYMOUS_PORT_LOOKUP = new Object();
private UPNPDevice wanConnDevice = null;
Expand Down Expand Up @@ -386,9 +396,9 @@ private final void discoverDevice() throws RemoteException {
try {
String timeout = System.getProperty("net.sbbi.upnp.remote.discoveryTimeout");
if (timeout != null) {
devices = Discovery.discover(Integer.parseInt(timeout), List.of("urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:2"));
devices = Discovery.discover(Integer.parseInt(timeout), IGD_URNS);
} else {
devices = Discovery.discover(List.of("urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:2"));
devices = Discovery.discover(IGD_URNS);
}
} catch (IOException ex) {
throw new RemoteException("IOException occured during devices discovery", ex);
Expand Down