Class NetworkUtility
- java.lang.Object
-
- com.sun.enterprise.mgmt.transport.NetworkUtility
-
public class NetworkUtility extends Object
Utility class that can be used by any calling code to do common routines about Network I/O- Author:
- Bongjae Chang
-
-
Field Summary
Fields Modifier and Type Field Description static List<InetAddress>allLocalAddressesstatic InetAddressANYADDRESSConstant which works as the IP "Any Address" valuestatic InetAddressANYADDRESSV4static InetAddressANYADDRESSV6static InetAddressfirstInetAddressV4static InetAddressfirstInetAddressV6static StringIPV4ANYADDRESSstatic StringIPV4LOOPBACKstatic StringIPV6ANYADDRESSstatic StringIPV6LOOPBACKstatic InetAddressLOOPBACKConstant which works as the IP "Local Loopback" value;static InetAddressLOOPBACKV4static InetAddressLOOPBACKV6
-
Constructor Summary
Constructors Constructor Description NetworkUtility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddeserialize(InputStream is, int count, Map<String,Serializable> messages)static List<InetAddress>getAllLocalAddresses()Returns all local addresses except for lookback and any local address But, if any addresses were not found locally, the lookback is added to the list.static InetAddressgetAnyAddress()static InetAddressgetFirstInetAddress()Return a firstInetAddressof the first network interface check java property java.net.preferIPv6Addresses for whether to favor IPv4 or IPv6.static InetAddressgetFirstInetAddress(boolean preferIPv6)Return a firstInetAddressof the first network interface But, if any network interfaces were not found locally,nullcould be returned.static NetworkInterfacegetFirstNetworkInterface(boolean preferIPv6)Return a first network interface except for the lookback But, if any network interfaces were not found locally, the lookback interface is returned.static intgetIntFromByteArray(byte[] bytes, int offset)static InetAddressgetLocalHostAddress()static InetAddressgetLoopbackAddress()static InetAddressgetNetworkInetAddress(NetworkInterface anInterface, boolean preferIPv6)Return a firstInetAddressof network interface But, if any network interfaces were not found locally,nullcould be returned.static booleangetPreferIpv6Addresses()static booleanisBindAddressValid(String addressString)static booleanisLoopbackNetworkInterface(NetworkInterface anInterface)static booleanisUp(NetworkInterface anInterface)static voidmain(String[] args)static InetAddressresolveBindInterfaceName(String addressString)static intserialize(OutputStream baos, Map<String,Serializable> messages)static booleansupportsMulticast(NetworkInterface anInterface)static voidwriteIntToByteArray(byte[] bytes, int offset, int value)
-
-
-
Field Detail
-
IPV4ANYADDRESS
public static final String IPV4ANYADDRESS
- See Also:
- Constant Field Values
-
IPV6ANYADDRESS
public static final String IPV6ANYADDRESS
- See Also:
- Constant Field Values
-
IPV4LOOPBACK
public static final String IPV4LOOPBACK
- See Also:
- Constant Field Values
-
IPV6LOOPBACK
public static final String IPV6LOOPBACK
- See Also:
- Constant Field Values
-
ANYADDRESS
public static final InetAddress ANYADDRESS
Constant which works as the IP "Any Address" value
-
ANYADDRESSV4
public static final InetAddress ANYADDRESSV4
-
ANYADDRESSV6
public static final InetAddress ANYADDRESSV6
-
LOOPBACK
public static final InetAddress LOOPBACK
Constant which works as the IP "Local Loopback" value;
-
LOOPBACKV4
public static final InetAddress LOOPBACKV4
-
LOOPBACKV6
public static final InetAddress LOOPBACKV6
-
allLocalAddresses
public static volatile List<InetAddress> allLocalAddresses
-
firstInetAddressV4
public static volatile InetAddress firstInetAddressV4
-
firstInetAddressV6
public static volatile InetAddress firstInetAddressV6
-
-
Method Detail
-
getAllLocalAddresses
public static List<InetAddress> getAllLocalAddresses()
Returns all local addresses except for lookback and any local address But, if any addresses were not found locally, the lookback is added to the list.- Returns:
- List which contains available addresses locally
-
getAnyAddress
public static InetAddress getAnyAddress()
-
getLoopbackAddress
public static InetAddress getLoopbackAddress()
-
getFirstNetworkInterface
public static NetworkInterface getFirstNetworkInterface(boolean preferIPv6) throws IOException
Return a first network interface except for the lookback But, if any network interfaces were not found locally, the lookback interface is returned.- Parameters:
preferIPv6- flag to indicate if IPV6 is preferred- Returns:
- a first network interface
- Throws:
IOException- if an I/O error occurs or a network interface was not found
-
getLocalHostAddress
public static InetAddress getLocalHostAddress()
-
getPreferIpv6Addresses
public static boolean getPreferIpv6Addresses()
-
getFirstInetAddress
public static InetAddress getFirstInetAddress() throws IOException
Return a firstInetAddressof the first network interface check java property java.net.preferIPv6Addresses for whether to favor IPv4 or IPv6. (java default is to favor IPv4 addresses) If unable to find a valid network interface, then fallback to trying to get localhost address as last resort.- Returns:
- a first found
InetAddress. - Throws:
IOException- if an I/O error occurs or a network interface was not found
-
getFirstInetAddress
public static InetAddress getFirstInetAddress(boolean preferIPv6) throws IOException
Return a firstInetAddressof the first network interface But, if any network interfaces were not found locally,nullcould be returned.- Parameters:
preferIPv6- if true, prefer IPv6 InetAddress. otherwise prefer IPv4 InetAddress- Returns:
- a first found
InetAddress. - Throws:
IOException- if an I/O error occurs or a network interface was not found
-
getNetworkInetAddress
public static InetAddress getNetworkInetAddress(NetworkInterface anInterface, boolean preferIPv6) throws IOException
Return a firstInetAddressof network interface But, if any network interfaces were not found locally,nullcould be returned.- Parameters:
anInterface- the type of network interfacepreferIPv6- if true, prefer IPv6 InetAddress. otherwise prefer IPv4 InetAddress- Returns:
- a first found
InetAddress. - Throws:
IOException- if an I/O error occurs or a network interface was not found
-
isLoopbackNetworkInterface
public static boolean isLoopbackNetworkInterface(NetworkInterface anInterface)
-
supportsMulticast
public static boolean supportsMulticast(NetworkInterface anInterface)
-
isUp
public static boolean isUp(NetworkInterface anInterface)
-
writeIntToByteArray
public static void writeIntToByteArray(byte[] bytes, int offset, int value) throws IllegalArgumentException- Throws:
IllegalArgumentException
-
getIntFromByteArray
public static int getIntFromByteArray(byte[] bytes, int offset) throws IllegalArgumentException- Throws:
IllegalArgumentException
-
serialize
public static int serialize(OutputStream baos, Map<String,Serializable> messages) throws MessageIOException
- Throws:
MessageIOException
-
deserialize
public static void deserialize(InputStream is, int count, Map<String,Serializable> messages) throws MessageIOException
- Throws:
MessageIOException
-
isBindAddressValid
public static boolean isBindAddressValid(String addressString)
-
resolveBindInterfaceName
public static InetAddress resolveBindInterfaceName(String addressString)
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
-