code: static boolean isPortAvailable(int port) {
          ServerSocket ss = null;
          try {
              ss = new ServerSocket(port);
              ss.setReuseAddress(true);
              return true;
          } catch (IOException ioe) { // NOSONAR
              return false;
          } finally {
              closeQuietly(ss);
          }
      }
docs: Find out if the provided port is available.
  
  @param port The port to be inspected.
  @return true if the port is avaiable.