public class AvailablePortFinder
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
static int |
MAX_PORT_NUMBER
The maximum number of server port number.
|
static int |
MIN_PORT_NUMBER
The minimum number of server port number.
|
限定符和类型 | 方法和说明 |
---|---|
static boolean |
available(int port)
Checks to see if a specific port is available.
|
static java.util.Set<java.lang.Integer> |
getAvailablePorts() |
static java.util.Set<java.lang.Integer> |
getAvailablePorts(int fromPort,
int toPort) |
static int |
getNextAvailable() |
static int |
getNextAvailable(int fromPort) |
public static final int MIN_PORT_NUMBER
public static final int MAX_PORT_NUMBER
public static java.util.Set<java.lang.Integer> getAvailablePorts()
Set
of currently available port numbers
(Integer
). This method is identical to
getAvailablePorts(MIN_PORT_NUMBER, MAX_PORT_NUMBER)
.
WARNING: this can take a very long time.public static int getNextAvailable()
java.util.NoSuchElementException
- if there are no ports availablepublic static int getNextAvailable(int fromPort)
fromPort
- the port to scan for availabilityjava.util.NoSuchElementException
- if there are no ports availablepublic static boolean available(int port)
port
- the port to check for availabilitypublic static java.util.Set<java.lang.Integer> getAvailablePorts(int fromPort, int toPort)
fromPort
- The port we start fromtoPort
- The posrt we stop atSet
of currently avalaible port numbers (Integer
)
between the specified port range.java.lang.IllegalArgumentException
- if port range is not between
MIN_PORT_NUMBER
and MAX_PORT_NUMBER
or
fromPort
if greater than toPort
.