Class Utils

java.lang.Object
zleurtor.scanmanager.model.Utils

public final class Utils extends Object
A utility class offering convenience methods.
Author:
Zleurtor
  • Method Details

    • execute

      public static Process execute(String command) throws IOException
      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

      public static Process execute(String command, boolean log) throws IOException
      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

      public static boolean isNumber(String s)
      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

      public static String extractIp(String address)
      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

      public static String getMacAddress(Socket socket) throws IOException, AddressNotAccessibleException
      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

      public static void recursiveDelete(File dir) throws IOException
      Delete recursively the directory.
      Parameters:
      dir - The directory to recursively delete.
      Throws:
      IOException - If an Input/Output error occurs.
    • getLogFile

      public static File getLogFile() throws IOException
      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

      public static org.apache.log4j.lf5.LogLevel getLogLevel() throws IOException
      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

      public static Comparator<String> 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

      public static int compareVersion(String v1, String v2)
      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

      public static int ipToInt(String ip)
      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.