Package zleurtor.scanmanager.model
Class Utils
java.lang.Object
zleurtor.scanmanager.model.Utils
A utility class offering convenience methods.
- Author:
- Zleurtor
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
compareVersion
(String v1, String v2) Compare two version numbers.static Process
Executes the specified command.static Process
Executes the specified command.static String
Extracts the IP address from the specified address String.static Comparator<String>
Creates and return a comparator that shall be used to compare String IPs.static File
Extract the log file name from the log4j configuration file.static org.apache.log4j.lf5.LogLevel
Extract the log level from the log4j configuration file.static String
getMacAddress
(Socket socket) Get the mac address of the network interface to which the given socket is bound.static int
Convert an ip (an array of 4 bytes) as a string to an integer.static boolean
Tests whether the specified String represents a number.static void
recursiveDelete
(File dir) Delete recursively the directory.static byte[]
toArray
(int i) Convert an integer to an array of bytes.static int
toInt
(byte[] array) Convert an array of bytes to an integer.
-
Method Details
-
execute
Executes the specified command.- Parameters:
command
- The command to execute.- Returns:
- The process representing the command execution.
- Throws:
IOException
- If an Input/Output error occurs
-
execute
Executes the specified command.- Parameters:
command
- The command to execute.log
- Whether the information messages shall be logged.- Returns:
- The process representing the command execution.
- Throws:
IOException
- If an Input/Output error occurs
-
isNumber
Tests whether the specified String represents a number.- Parameters:
s
- The String to check whether it represents a number.- Returns:
- True if the specified String represents a number, false otherwise.
-
extractIp
Extracts the IP address from the specified address String.- Parameters:
address
- The address String from which the IP address shall be extracted.- Returns:
- The IP address extracted from the specified address String.
-
getMacAddress
Get the mac address of the network interface to which the given socket is bound.- Parameters:
socket
- A socket bound to the network interface from which we want the mac address.- Returns:
- The mac address of the network interface on which the specified socket was created.
- Throws:
IOException
- If an Input/Output error occurs.AddressNotAccessibleException
- If the address of the socket is not accessible.
-
recursiveDelete
Delete recursively the directory.- Parameters:
dir
- The directory to recursively delete.- Throws:
IOException
- If an Input/Output error occurs.
-
getLogFile
Extract the log file name from the log4j configuration file.- Returns:
- The log file name.
- Throws:
IOException
- If an input/output error occurs while reading the log4j configuration file.
-
getLogLevel
Extract the log level from the log4j configuration file.- Returns:
- The log level.
- Throws:
IOException
- If an input/output error occurs while reading the log4j configuration file.
-
getIpComparator
Creates and return a comparator that shall be used to compare String IPs.- Returns:
- A comparator that shall be used to compare String IPs.
-
compareVersion
Compare two version numbers.- Parameters:
v1
- The first version number to compare.v2
- second first version number to compare.- Returns:
- A negative integer, zero, or a positive integer as v1 is less than, equal to, or greater than v2.
-
toInt
public static int toInt(byte[] array) Convert an array of bytes to an integer.- Parameters:
array
- The array of bytes to convert.- Returns:
- The integer converted from the array of bytes.
-
toArray
public static byte[] toArray(int i) Convert an integer to an array of bytes.- Parameters:
i
- The integer to convert.- Returns:
- The array of bytes converted from the integer.
-
ipToInt
Convert an ip (an array of 4 bytes) as a string to an integer.- Parameters:
ip
- The ip given as a string.- Returns:
- the integer of the 4 bytes of the given ip.
-