public class EtUtils
extends java.lang.Object
Constructor and Description |
---|
EtUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
bytesToInt(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into an int.
|
static int |
bytesToInt(byte[] b,
int off)
Converts 4 bytes of a byte array into an integer.
|
static long |
bytesToLong(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a long.
|
static long |
bytesToLong(byte[] b,
int off)
Converts 8 bytes of a byte array into a long.
|
static short |
bytesToShort(byte[] data,
java.nio.ByteOrder byteOrder,
int off)
Turn section of byte array into a short.
|
static short |
bytesToShort(byte[] b,
int off)
Converts 2 bytes of a byte array into a short.
|
static java.util.List<java.lang.String> |
getAllBroadcastAddresses()
Get all local IP broadcast addresses in a list in dotted-decimal form.
|
static java.util.Collection<java.lang.String> |
getAllIpAddresses()
Get all local IP addresses in a list in dotted-decimal form.
|
static java.lang.String |
getBroadcastAddress(java.lang.String ip)
Given a local IP address as an argument, this method will return its
broadcast or subnet address.
|
static java.lang.String |
getBroadcastAddress2(java.lang.String ip)
Given a local IP address as an argument, this method will return its
broadcast or subnet address.
|
static java.lang.String |
getMatchingLocalIpAddress(java.lang.String ip)
Given an IP address as an argument, this method will return that if it matches
one of the local IP addresses.
|
static void |
intToBytes(int intVal,
byte[] b,
int off)
Copies an integer value into 4 bytes of a byte array.
|
static void |
intToBytes(int data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn int into byte array.
|
static byte[] |
isDottedDecimal(java.lang.String ipAddress)
This method tells whether the given IPv4 address is in dot-decimal notation or not.
|
static boolean |
isHostLocal(java.util.ArrayList<java.lang.String> addrs)
Is the given list of IP addresses identical to those of the local host?
|
static boolean |
isHostLocal(java.lang.String hostName)
Determine whether a given host name refers to the local host.
|
static boolean |
isHostSame(java.lang.String hostName1,
java.lang.String hostName2)
Determine whether two given host names refers to the same host.
|
static void |
longToBytes(long longVal,
byte[] b,
int off)
Copies an long (64 bit) value into 8 bytes of a byte array.
|
static void |
longToBytes(long data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn long into byte array.
|
(package private) static boolean |
onSameSubnet(java.lang.String ipAddress1,
byte[] ipAddress2,
int subnetMask)
This method tells whether the 2 given IP addresses (one in dot-decimal
notation and the other in raw form) are on the same subnet or not given
a subnet mask in integer form (local byte order).
|
(package private) static boolean |
onSameSubnet(java.lang.String ipAddress1,
java.lang.String ipAddress2,
int subnetMask)
This method tells whether the 2 given IP addresses in dot-decimal notation
are on the same subnet or not given a subnet mask in integer form
(local byte order).
|
static java.util.List<java.lang.String> |
orderIPAddresses(java.util.List<java.lang.String> ipAddresses)
Takes a list of dotted-decimal formatted IP address strings and orders them
so that those on local subnets are first and others come last.
|
static java.util.List<java.lang.String> |
orderIPAddresses(java.util.List<java.lang.String> ipAddresses,
java.util.List<java.lang.String> broadAddresses,
java.lang.String preferredAddress)
Takes a list of dotted-decimal formatted IP address strings and their corresponding
broadcast addresses and orders them so that those on the given local subnet are first,
those on other local subnets are next, and all others come last.
|
static java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> |
orderIPAddresses(java.util.List<java.lang.String> ipAddresses,
java.util.List<java.lang.String> broadAddresses,
java.lang.String preferredAddress,
boolean etOnLocalHost)
Takes a list of dotted-decimal formatted IP address strings and their corresponding
broadcast addresses and orders them so that those on the given local subnet are first,
those on other local subnets are next, and all others come last.
|
static void |
shortToBytes(short shortVal,
byte[] b,
int off)
Copies a short value into 2 bytes of a byte array.
|
static void |
shortToBytes(short data,
java.nio.ByteOrder byteOrder,
byte[] dest,
int off)
Turn short into byte array.
|
static void |
sleepNanos(long nanoDuration)
Spin-yield loop based alternative to Thread.sleep
Based on the code of Andy Malakov
http://andy-malakov.blogspot.fr/2010/06/alternative-to-threadsleep.html
|
static void |
swapArrayInt(byte[] b,
int off)
Swaps 4 bytes of a byte array in place.
|
static void |
swapArrayShort(byte[] b,
int off)
Swaps 2 bytes of a byte array in place.
|
public static void sleepNanos(long nanoDuration) throws java.lang.InterruptedException
nanoDuration
- number of nano sec to sleep.java.lang.InterruptedException
- if thread interrupted during sleep.public static void shortToBytes(short data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
data
- short to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placedpublic static void intToBytes(int data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
data
- int to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placedpublic static void longToBytes(long data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
data
- long to convertbyteOrder
- byte order of returned bytes (big endian if null)dest
- array in which to store returned bytesoff
- offset into dest array where returned bytes are placedpublic static void shortToBytes(short shortVal, byte[] b, int off)
shortVal
- short valueb
- byte arrayoff
- offset into the byte arraypublic static void intToBytes(int intVal, byte[] b, int off)
intVal
- integer valueb
- byte arrayoff
- offset into the byte arraypublic static void longToBytes(long longVal, byte[] b, int off)
longVal
- long valueb
- byte arrayoff
- offset into the byte arraypublic static short bytesToShort(byte[] data, java.nio.ByteOrder byteOrder, int off)
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data arraypublic static int bytesToInt(byte[] data, java.nio.ByteOrder byteOrder, int off)
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data arraypublic static long bytesToLong(byte[] data, java.nio.ByteOrder byteOrder, int off)
data
- byte array to convertbyteOrder
- byte order of supplied bytes (big endian if null)off
- offset into data arraypublic static short bytesToShort(byte[] b, int off)
b
- byte arrayoff
- offset into the byte array (0 = start at first element)public static int bytesToInt(byte[] b, int off)
b
- byte arrayoff
- offset into the byte array (0 = start at first element)public static long bytesToLong(byte[] b, int off)
b
- byte arrayoff
- offset into the byte array (0 = start at first element)public static void swapArrayInt(byte[] b, int off)
b
- byte arrayoff
- offset into the byte arraypublic static void swapArrayShort(byte[] b, int off)
b
- byte arrayoff
- offset into the byte arraypublic static boolean isHostLocal(java.util.ArrayList<java.lang.String> addrs) throws java.net.UnknownHostException
addrs
- list of String (dot decimal) addresses to testtrue
if host is local, else false
java.net.UnknownHostException
- if host cannot be resolvedpublic static boolean isHostLocal(java.lang.String hostName)
hostName
- host name that is checked to see if its local or notpublic static boolean isHostSame(java.lang.String hostName1, java.lang.String hostName2)
hostName1
- host name that is checked to see if it is the same as the other arg or not.hostName2
- host name that is checked to see if it is the same as the other arg or not.public static java.util.Collection<java.lang.String> getAllIpAddresses()
public static java.util.List<java.lang.String> getAllBroadcastAddresses()
public static java.lang.String getMatchingLocalIpAddress(java.lang.String ip) throws org.jlab.coda.et.exception.EtException
ip
- IP or subnet address in dotted-decimal formatorg.jlab.coda.et.exception.EtException
- if arg not in dotted-decimal formatpublic static java.lang.String getBroadcastAddress2(java.lang.String ip) throws org.jlab.coda.et.exception.EtException
ip
- IP or subnet address in dotted-decimal formatorg.jlab.coda.et.exception.EtException
- if arg is null or not in dotted-decimal formatpublic static java.lang.String getBroadcastAddress(java.lang.String ip) throws org.jlab.coda.et.exception.EtException
ip
- IP or subnet address in dotted-decimal formatorg.jlab.coda.et.exception.EtException
- if arg is null or not in dotted-decimal formatpublic static java.util.List<java.lang.String> orderIPAddresses(java.util.List<java.lang.String> ipAddresses)
ipAddresses
- list of addresses to order; null if arg is nullpublic static java.util.List<java.lang.String> orderIPAddresses(java.util.List<java.lang.String> ipAddresses, java.util.List<java.lang.String> broadAddresses, java.lang.String preferredAddress)
ipAddresses
- list of addresses to order; null if arg is nullbroadAddresses
- list of broadcast addresses - each associated w/ corresponding
ip addresspreferredAddress
- if not null, it is the preferred subnet(broadcast) address
used in sorting so that addresses on the given list which
exist on the preferred subnet are first on the returned list.
If a local, non-subnet ip address is given, it will be
converted internally to the subnet it is on.public static java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> orderIPAddresses(java.util.List<java.lang.String> ipAddresses, java.util.List<java.lang.String> broadAddresses, java.lang.String preferredAddress, boolean etOnLocalHost)
ipAddresses
- list of addresses to order; null if arg is nullbroadAddresses
- list of broadcast addresses - each associated w/ corresponding
ip addresspreferredAddress
- if not null, it is the preferred subnet(broadcast) address
used in sorting so that addresses on the given list which
exist on the preferred subnet are first on the returned list.
If a local, non-subnet ip address is given, it will be
converted internally to the subnet it is on.etOnLocalHost
- is the ET system that client is trying to connect to, on the local host?static boolean onSameSubnet(java.lang.String ipAddress1, java.lang.String ipAddress2, int subnetMask) throws org.jlab.coda.et.exception.EtException
ipAddress1
- first IP address in dot-decimal notationipAddress2
- second IP address in dot-decimal notationsubnetMask
- subnet mask as LOCAL-byte-ordered 32 bit inttrue
if on same subnet, else false
.org.jlab.coda.et.exception.EtException
- if one or both IP address args are not dot-decimal format or arg is null.static boolean onSameSubnet(java.lang.String ipAddress1, byte[] ipAddress2, int subnetMask) throws org.jlab.coda.et.exception.EtException
ipAddress1
- first IP address in dot-decimal notationipAddress2
- second IP address in raw form (net byte order
meaning highest order byte in element 0)subnetMask
- subnet mask as LOCAL-byte-ordered 32 bit inttrue
if on same subnet, else false
.org.jlab.coda.et.exception.EtException
- if first IP address arg is not dot-decimal format or arg is null.public static byte[] isDottedDecimal(java.lang.String ipAddress)
ipAddress
- IPV4 address