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.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 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.
|
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 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 |
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 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 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 byte[] isDottedDecimal(java.lang.String ipAddress)
ipAddress
- IPV4 address