docs: public static void main(String[] pArgs) throws IOException {
          // params:
          int timeout = 0;
          boolean followRedirects = true;
          boolean debugHeaders = false;
          String requestPropertiesFile = null;
          String requestHeaders = null;
          String postData = null;
          File putData = null;
          int argIdx = 0;
          boolean errArgs = false;
          boolean writeToFile = false;
          boolean writeToStdOut = false;
          String outFileName = null;
  
          while ((argIdx < pArgs.length) && (pArgs[argIdx].charAt(0) == '-') && (pArgs[argIdx].length() >= 2)) {
              if ((pArgs[argIdx].charAt(1) == 't') || pArgs[argIdx].equals("--timeout")) {
                  argIdx++;
                  try {
                      timeout = Integer.parseInt(pArgs[argIdx++]);
                  }
                  catch (NumberFormatException nfe) {
                      errArgs = true;
                      break;
                  }
              }
              else if ((pArgs[argIdx].charAt(1) == 'd') || pArgs[argIdx].equals("--debugheaders")) {
                  debugHeaders = true;
                  argIdx++;
              }
              else if ((pArgs[argIdx].charAt(1) == 'n') || pArgs[argIdx].equals("--nofollowredirects")) {
                  followRedirects = false;
                  argIdx++;
              }
              else if ((pArgs[argIdx].charAt(1) == 'r') || pArgs[argIdx].equals("--requestproperties")) {
                  argIdx++;
                  requestPropertiesFile = pArgs[argIdx++];
              }
              else if ((pArgs[argIdx].charAt(1) == 'p') || pArgs[argIdx].equals("--postdata")) {
                  argIdx++;
                  postData = pArgs[argIdx++];
              }
              else if ((pArgs[argIdx].charAt(1) == 'u') || pArgs[argIdx].equals("--putdata")) {
                  argIdx++;
                  putData = new File(pArgs[argIdx++]);
                  if (!putData.exists()) {
                      errArgs = true;
                      break;
                  }
              }
              else if ((pArgs[argIdx].charAt(1) == 'h') || pArgs[argIdx].equals("--header")) {
                  argIdx++;
                  requestHeaders = pArgs[argIdx++];
              }
              else if ((pArgs[argIdx].charAt(1) == 'f') || pArgs[argIdx].equals("--file")) {
                  argIdx++;
                  writeToFile = true;
  
                  // Get optional file name
                  if (!((argIdx >= (pArgs.length - 1)) || (pArgs[argIdx].charAt(0) == '-'))) {
                      outFileName = pArgs[argIdx++];
                  }
              }
              else if ((pArgs[argIdx].charAt(1) == 'o') || pArgs[argIdx].equals("--output")) {
                  argIdx++;
                  writeToStdOut = true;
              }
              else {
                  System.err.println("Unknown option \"" + pArgs[argIdx++] + "\"");
              }
          }
          if (errArgs || (pArgs.length < (argIdx + 1))) {
              System.err.println("Usage: java  NetUtil [-f|--file [<file name>]] [-d|--debugheaders] [-h|--header <header data>] [-p|--postdata <URL-encoded postdata>] [-u|--putdata <file name>] [-r|--requestProperties <properties file>] [-t|--timeout <miliseconds>] [-n|--nofollowredirects] fromUrl");
              System.exit(5);
          }
          String url = pArgs[argIdx/*++*/];
  
          // DONE ARGS
          // Get request properties
          Properties requestProperties = new Properties();
  
          if (requestPropertiesFile != null) {
  
              // Just read, no exception handling...
              requestProperties.load(new FileInputStream(new File(requestPropertiesFile)));
          }
          if (requestHeaders != null) {
  
              // Get request headers
              String[] headerPairs = StringUtil.toStringArray(requestHeaders, ",");
  
              for (String headerPair : headerPairs) {
                  String[] pair = StringUtil.toStringArray(headerPair, ":");
                  String key = (pair.length > 0)
                          ? pair[0].trim()
                          : null;
                  String value = (pair.length > 1)
                          ? pair[1].trim()
                          : "";
  
                  if (key != null) {
                      requestProperties.setProperty(key, value);
                  }
              }
          }
          HttpURLConnection conn;
  
          // Create connection
          URL reqURL = getURLAndSetAuthorization(url, requestProperties);
  
          conn = createHttpURLConnection(reqURL, requestProperties, followRedirects, timeout);
  
          // POST
          if (postData != null) {
              // HTTP POST method
              conn.setRequestMethod(HTTP_POST);
  
              // Set entity headers
              conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
              conn.setRequestProperty("Content-Length", String.valueOf(postData.length()));
              conn.setRequestProperty("Content-Encoding", "ISO-8859-1");
  
              // Get outputstream (this is where the connect actually happens)
              OutputStream os = conn.getOutputStream();
  
              System.err.println("OutputStream: " + os.getClass().getName() + "@" + System.identityHashCode(os));
              OutputStreamWriter writer = new OutputStreamWriter(os, "ISO-8859-1");
  
              // Write post data to the stream
              writer.write(postData);
              writer.write("\r\n");
  
              //writer.flush();
              writer.close();  // Does this close the underlying stream?
          }
          // PUT
          else if (putData != null) {
              // HTTP PUT method
              conn.setRequestMethod(HTTP_PUT);
  
              // Set entity headers
              //conn.setRequestProperty("Content-Type", "???");
              // TODO: Set Content-Type to correct type?
              // TODO: Set content-encoding? Or can binary data be sent directly?
              conn.setRequestProperty("Content-Length", String.valueOf(putData.length()));
  
              // Get outputstream (this is where the connect actually happens)
              OutputStream os = conn.getOutputStream();
  
              System.err.println("OutputStream: " + os.getClass().getName() + "@" + System.identityHashCode(os));
  
              // Write put data to the stream
              FileUtil.copy(new FileInputStream(putData), os);
  
              os.close();
          }
  
          //
          InputStream is;
  
          if (conn.getResponseCode() == 200) {
  
              // Connect and get stream
              is = conn.getInputStream();
          }
          else {
              is = conn.getErrorStream();
          }
  
          //
          if (debugHeaders) {
              System.err.println("Request (debug):");
              System.err.println(conn.getClass());
              System.err.println("Response (debug):");
  
              // Headerfield 0 is response code
              System.err.println(conn.getHeaderField(0));
  
              // Loop from 1, as headerFieldKey(0) == null...
              for (int i = 1; ; i++) {
                  String key = conn.getHeaderFieldKey(i);
  
                  // Seems to be the way to loop through them all...
                  if (key == null) {
                      break;
                  }
                  System.err.println(key + ": " + conn.getHeaderField(key));
              }
          }
  
          // Create output file if specified
          OutputStream os;
  
          if (writeToFile) {
              if (outFileName == null) {
                  outFileName = reqURL.getFile();
                  if (StringUtil.isEmpty(outFileName)) {
                      outFileName = conn.getHeaderField("Location");
                      if (StringUtil.isEmpty(outFileName)) {
                          outFileName = "index";
  
                          // Find a suitable extension
                          // TODO: Replace with MIME-type util with MIME/file ext mapping
                          String ext = conn.getContentType();
  
                          if (!StringUtil.isEmpty(ext)) {
                              int idx = ext.lastIndexOf('/');
  
                              if (idx >= 0) {
                                  ext = ext.substring(idx + 1);
                              }
                              idx = ext.indexOf(';');
                              if (idx >= 0) {
                                  ext = ext.substring(0, idx);
                              }
                              outFileName += "." + ext;
                          }
                      }
                  }
                  int idx = outFileName.lastIndexOf('/');
  
                  if (idx >= 0) {
                      outFileName = outFileName.substring(idx + 1);
                  }
                  idx = outFileName.indexOf('?');
                  if (idx >= 0) {
                      outFileName = outFileName.substring(0, idx);
                  }
              }
              File outFile = new File(outFileName);
  
              if (!outFile.createNewFile()) {
                  if (outFile.exists()) {
                      System.err.println("Cannot write to file " + outFile.getAbsolutePath() + ", file allready exists.");
                  }
                  else {
                      System.err.println("Cannot write to file " + outFile.getAbsolutePath() + ", check write permissions.");
                  }
                  System.exit(5);
              }
              os = new FileOutputStream(outFile);
          }
          else if (writeToStdOut) {
              os = System.out;
          }
          else {
              os = null;
          }
  
          // Get data.
          if ((writeToFile || writeToStdOut) && is != null) {
              FileUtil.copy(is, os);
          }
  
          /*
                      Hashtable postData = new Hashtable();
                      postData.put("SearchText", "condition");
  
                      try {
                          InputStream in = getInputStreamHttpPost(pArgs[argIdx], postData,
                                                               props, true, 0);
                          out = new FileOutputStream(file);
                          FileUtil.copy(in, out);
                      }
                      catch (Exception e) {
                          System.err.println("Error: " + e);
                          e.printStackTrace(System.err);
                          continue;
                      }
           */
      }