docs: public static boolean changeHost(String hostName,
                                       boolean enable,
                                       boolean disable,
                                       boolean remove,
                                       boolean isEnabled,
                                       boolean exists) throws Exception {
  
          // Open the file that is the first
          // command line parameter
          File hostsFile = new File("/etc/hosts");
          FileInputStream fstream = new FileInputStream("/etc/hosts");
  
          File outFile = null;
          BufferedWriter bw = null;
          // only do file output for destructive operations
          if (!exists && !isEnabled) {
              outFile = File.createTempFile("HostsEdit", ".tmp");
              bw = new BufferedWriter(new FileWriter(outFile));
              System.out.println("File name: " + outFile.getPath());
          }
  
          // Get the object of DataInputStream
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;
          boolean foundHost = false;
          boolean hostEnabled = false;
  
  		/*
           * Group 1 - possible commented out host entry
  		 * Group 2 - destination address
  		 * Group 3 - host name
  		 * Group 4 - everything else
  		 */
          Pattern pattern = Pattern.compile("\\s*(#?)\\s*([^\\s]+)\\s*([^\\s]+)(.*)");
          while ((strLine = br.readLine()) != null) {
  
              Matcher matcher = pattern.matcher(strLine);
  
              // if there is a match to the pattern and the host name is the same as the one we want to set
              if (matcher.find() &&
                      matcher.group(3).toLowerCase().compareTo(hostName.toLowerCase()) == 0) {
                  foundHost = true;
                  if (remove) {
                      // skip this line altogether
                      continue;
                  } else if (enable) {
                      // we will disregard group 2 and just set it to 127.0.0.1
                      if (!exists && !isEnabled)
                          bw.write("127.0.0.1 " + matcher.group(3) + matcher.group(4));
                  } else if (disable) {
                      if (!exists && !isEnabled)
                          bw.write("# " + matcher.group(2) + " " + matcher.group(3) + matcher.group(4));
                  } else if (isEnabled && matcher.group(1).compareTo("") == 0) {
                      // host exists and there is no # before it
                      hostEnabled = true;
                  }
              } else {
                  // just write the line back out
                  if (!exists && !isEnabled)
                      bw.write(strLine);
              }
  
              if (!exists && !isEnabled)
                  bw.write('\n');
          }
  
          // if we didn't find the host in the file but need to enable it
          if (!foundHost && enable) {
              // write a new host entry
              if (!exists && !isEnabled)
                  bw.write("127.0.0.1 " + hostName + '\n');
          }
          // Close the input stream
          in.close();
  
          if (!exists && !isEnabled) {
              bw.close();
              outFile.renameTo(hostsFile);
          }
  
          // return false if the host wasn't found
          if (exists && !foundHost)
              return false;
  
          // return false if the host wasn't enabled
          if (isEnabled && !hostEnabled)
              return false;
  
          return true;
      }