Package com.arjuna.ats.arjuna.utils
Class Utility
java.lang.Object
com.arjuna.ats.arjuna.utils.Utility
Various useful functions that we wrap in a single class. Some of these
functions are needed simply for backwards compatibility with older versions
of Java.
- Since:
- JTS 1.0.
- Version:
- $Id: Utility.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic final intgetpid()static Uidstatic inthexCharsOf(int value) Determine the number of hex chars needed to represent the given int value.static inthexCharsOf(long value) Determine the number of hex chars needed to represent the given long value.static intConvert a hex String to an integer.static longConvert a hex String to a longstatic long[]static InetAddresshostNameToInetAddress(String host) Convert a host name into an InetAddress objectstatic StringintToHexString(int number) Convert integer to hex String.static booleanstatic final booleanstatic StringlongToHexString(long number) Convert a long to a hex String.static final voidstatic voidtoHexChars(int value, byte[] ascii, int offset, int expectedHexChars) Convert a int to hex chars.static voidtoHexChars(long value, byte[] ascii, int offset, int expectedHexChars) Convert a long to hex chars.static voidvalidatePortRange(int port)
-
Field Details
-
BACKLOG
public static final int BACKLOGThe maximum queue length for incoming connection indications (a request to connect)- See Also:
-
MAX_PORT
public static final int MAX_PORTMaximum value for a socket port- See Also:
-
-
Constructor Details
-
Utility
public Utility()
-
-
Method Details
-
intToHexString
Convert integer to hex String.- Throws:
NumberFormatException
-
hexStringToInt
Convert a hex String to an integer. Be careful of -1. Java IO is really bad!- Throws:
NumberFormatException
-
longToHexString
Convert a long to a hex String.- Throws:
NumberFormatException
-
hexCharsOf
public static int hexCharsOf(int value) Determine the number of hex chars needed to represent the given int value. This is at least 1.- Parameters:
value- the int value- Returns:
- the number of hex chars needed to represent the value
-
toHexChars
public static void toHexChars(int value, byte[] ascii, int offset, int expectedHexChars) Convert a int to hex chars. The byte array must be big enough to hold the expected number of hex chars. SeehexCharsOf(int)to determine the number of hex chars needed.- Parameters:
value- the int value to convertascii- the byte array to hold the hex charsoffset- the offset into the byte array to start writingexpectedHexChars- the expected number of hex chars to write
-
hexCharsOf
public static int hexCharsOf(long value) Determine the number of hex chars needed to represent the given long value. This is at least 1.- Parameters:
value- the long value- Returns:
- the number of hex chars needed to represent the value
-
toHexChars
public static void toHexChars(long value, byte[] ascii, int offset, int expectedHexChars) Convert a long to hex chars. The byte array must be big enough to hold the expected number of hex chars. SeehexCharsOf(long)to determine the number of hex chars needed.- Parameters:
value- the long value to convertascii- the byte array to hold the hex charsoffset- the offset into the byte array to start writingexpectedHexChars- the expected number of hex chars to write
-
hexStringToLong
Convert a hex String to a long- Throws:
NumberFormatException
-
hostInetAddr
- Returns:
- Long(s) representing the ip v6 address of the local machine. Essentially the bytes of the InetAddress are shuffled into the long(s). This was once part of the Uid class but has been separated for general availability.
- Throws:
UnknownHostException- Since:
- JTS 2.1.
-
hostNameToInetAddress
Convert a host name into an InetAddress object- Parameters:
host- if empty or null then the loopback address is used- Returns:
- an InetAddress structure corresponding the desired host name
- Throws:
UnknownHostException- if the hostname cannot be found
-
getpid
public static final int getpid()- Returns:
- the process id. This had better be unique between processes on the same machine. If not we're in trouble!
- Since:
- JTS 2.1.
-
getProcessUid
- Returns:
- a Uid representing this process.
- Since:
- JTS 2.1.
-
isWindows
public static final boolean isWindows() -
setProcess
-
validatePortRange
public static void validatePortRange(int port) -
getDefaultProcessId
-
isAndroid
public static boolean isAndroid()
-