com.sun.enterprise.mgmt.transport
Class NetworkUtility

java.lang.Object
  extended by 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
static List<InetAddress> allLocalAddresses
           
static InetAddress ANYADDRESS
          Constant which works as the IP "Any Address" value
static InetAddress ANYADDRESSV4
           
static InetAddress ANYADDRESSV6
           
static InetAddress firstInetAddressV4
           
static InetAddress firstInetAddressV6
           
static NetworkInterface firstNetworkInterface
           
static String IPV4ANYADDRESS
           
static String IPV4LOOPBACK
           
static String IPV6ANYADDRESS
           
static String IPV6LOOPBACK
           
static InetAddress LOOPBACK
          Constant which works as the IP "Local Loopback" value;
static InetAddress LOOPBACKV4
           
static InetAddress LOOPBACKV6
           
static AtomicBoolean preferIPv6Addresses
           
 
Constructor Summary
NetworkUtility()
           
 
Method Summary
static void deserialize(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 InetAddress getAnyAddress()
           
static InetAddress getFirstInetAddress()
          Return a first InetAddress of the first network interface check java property java.net.preferIPv6Addresses for whether to favor IPv4 or IPv6.
static InetAddress getFirstInetAddress(boolean preferIPv6)
          Return a first InetAddress of the first network interface But, if any network interfaces were not found locally, null could be returned.
static NetworkInterface getFirstNetworkInterface()
          Return a first network interface except for the lookback But, if any network interfaces were not found locally, the lookback interface is returned.
static int getIntFromByteArray(byte[] bytes, int offset)
           
static InetAddress getLocalHostAddress()
           
static InetAddress getLoopbackAddress()
           
static InetAddress getNetworkInetAddress(NetworkInterface anInterface, boolean preferIPv6)
          Return a first InetAddress of network interface But, if any network interfaces were not found locally, null could be returned.
static boolean getPreferIpv6Addresses()
           
static boolean isBindAddressValid(String addressString)
           
static boolean isLoopbackNetworkInterface(NetworkInterface anInterface)
           
static boolean isUp(NetworkInterface anInterface)
           
static void main(String[] args)
           
static InetAddress resolveBindInterfaceName(String addressString)
           
static int serialize(OutputStream baos, Map<String,Serializable> messages)
           
static int serialize(OutputStream baos, Map<String,Serializable> messages, boolean debug)
           
static boolean supportsMulticast(NetworkInterface anInterface)
           
static void writeIntToByteArray(byte[] bytes, int offset, int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

firstNetworkInterface

public static volatile NetworkInterface firstNetworkInterface

firstInetAddressV4

public static volatile InetAddress firstInetAddressV4

firstInetAddressV6

public static volatile InetAddress firstInetAddressV6

preferIPv6Addresses

public static AtomicBoolean preferIPv6Addresses
Constructor Detail

NetworkUtility

public NetworkUtility()
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()
                                                 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.

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 first InetAddress of 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 first InetAddress of the first network interface But, if any network interfaces were not found locally, null could 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 first InetAddress of network interface But, if any network interfaces were not found locally, null could 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

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

serialize

public static int serialize(OutputStream baos,
                            Map<String,Serializable> messages,
                            boolean debug)
                     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


Copyright © 2012. All Rights Reserved.