For debugging. Prints all known MIME types and file extensions.

@param pArgs command line arguments
17863
public static void main(String[] pArgs) {
        if (pArgs.length > 1) {
            String type = pArgs[0];
            String family = pArgs[1];
            boolean incuded = includes(family, type);
            System.out.println(
                    "Mime type family " + family
                    + (incuded ? " includes " : " does not include ")
                    + "type " + type
            );
        }
        if (pArgs.length > 0) {
            String str = pArgs[0];

            if (str.indexOf('/') >= 0) {
                // MIME
                String extension = getExtension(str);
                System.out.println("Default extension for MIME type '" + str + "' is "
                        + (extension != null ? ": '" + extension + "'" : "unknown") + ".");
                System.out.println("All possible: " + getExtensions(str));
            }
            else {
                // EXT
                String mimeType = getMIMEType(str);
                System.out.println("Default MIME type for extension '" + str + "' is "
                        + (mimeType != null ? ": '" + mimeType + "'" : "unknown") + ".");
                System.out.println("All possible: " + getMIMETypes(str));
            }

            return;
        }

        Set set = sMIMEToExt.keySet();
        String[] mimeTypes = new String[set.size()];
        int i = 0;
        for (Iterator iterator = set.iterator(); iterator.hasNext(); i++) {
            String mime = (String) iterator.next();
            mimeTypes[i] = mime;
        }
        Arrays.sort(mimeTypes);

        System.out.println("Known MIME types (" + mimeTypes.length + "):");
        for (int j = 0; j < mimeTypes.length; j++) {
            String mimeType = mimeTypes[j];

            if (j != 0) {
                System.out.print(", ");
            }

            System.out.print(mimeType);
        }

        System.out.println("\n");

        set = sExtToMIME.keySet();
        String[] extensions = new String[set.size()];
        i = 0;
        for (Iterator iterator = set.iterator(); iterator.hasNext(); i++) {
            String ext = (String) iterator.next();
            extensions[i] = ext;
        }
        Arrays.sort(extensions);

        System.out.println("Known file types (" + extensions.length + "):");
        for (int j = 0; j < extensions.length; j++) {
            String extension = extensions[j];

            if (j != 0) {
                System.out.print(", ");
            }

            System.out.print(extension);
        }
        System.out.println();
    }
33394
@FFDCIgnore(IOException.class)
    public static Map<String, Object> parseExtensions(Extension[] extensions) {
        final Map<String, Object> map = new HashMap<String, Object>();
        for (Extension extension : extensions) {
            final String name = extension.name();
            final String key = name.length() > 0 ? StringUtils.prependIfMissing(name, "x-") : name;
            Object value = null;
            try {
                value = Json.mapper().readTree(extension.value());
            } catch (IOException e) {
                value = extension.value();
            }           
            map.put(key, value);
        }

        return map;
    }
180934
private static void parseOptions(String args[])
  {
    if (!(args.length == 14 || args.length == 12 || args.length == 5)) {
      usage();
    }

    /*
     * As described in usage():
     * -s dfs-server
     * -p dfs-port [-t [create|create-write|stat|readdir|read|rename|delete]
     * -a planfile-path
     * -c host
     * -n process-name
     * -P prefix
     */
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-s") && i+1 < args.length) {
        dfsServer_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-p") && i+1 < args.length) {
        dfsPort_ = Integer.parseInt(args[i+1]);
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-t") && i+1 < args.length) {
        testName_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-a") && i+1 < args.length) {
        planfilePath_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-c") && i+1 < args.length) {
        hostName_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-n") && i+1 < args.length) {
        processName_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      } else if (args[i].equals("-P") && i+1 < args.length) {
        prefix_ = args[i+1];
        System.out.println(args[i+1]);
        i++;
      }
    }

    if (dfsServer_.length() == 0    ||
        testName_.length() == 0     ||
        planfilePath_.length() == 0 ||
        hostName_.length() == 0     ||
        processName_.length() == 0  ||
        dfsPort_ == 0) {
      usage();
    }
    if (prefix_ == null) {
      prefix_ = new String("PATH_PREFIX_");
    }
    prefixLen_ = prefix_.length();
  }
1096631
public static void main(String[] args)
   {
      try
      {
         if (args.length != 1)
         {
            System.out.println("Usage: MpxCreate <output file name>");
         }
         else
         {
            create(args[0]);
         }
      }

      catch (Exception ex)
      {
         ex.printStackTrace(System.out);
      }
   }
102693
public static void main(String args[]) {
		SmapGenerator g = new SmapGenerator();
		g.setOutputFileName("foo.java");
		SmapStratum s = new SmapStratum("JSP");
		s.addFile("foo.jsp");
		s.addFile("bar.jsp", "/foo/foo/bar.jsp");
		s.addLineData(1, "foo.jsp", 1, 1, 1);
		s.addLineData(2, "foo.jsp", 1, 6, 1);
		s.addLineData(3, "foo.jsp", 2, 10, 5);
		s.addLineData(20, "bar.jsp", 1, 30, 1);
		g.addStratum(s, true);
		System.out.print(g);

		System.out.println("---");

		SmapGenerator embedded = new SmapGenerator();
		embedded.setOutputFileName("blargh.tier2");
		s = new SmapStratum("Tier2");
		s.addFile("1.tier2");
		s.addLineData(1, "1.tier2", 1, 1, 1);
		embedded.addStratum(s, true);
		g.addSmap(embedded.toString(), "JSP");
		System.out.println(g);
	}
867642
protected final void parse(List<String> args) {
    Pattern eqSeparatedOpt = Pattern.compile("(--[^=]+)=(.+)");

    int idx = 0;
    for (idx = 0; idx < args.size(); idx++) {
      String arg = args.get(idx);
      String value = null;

      Matcher m = eqSeparatedOpt.matcher(arg);
      if (m.matches()) {
        arg = m.group(1);
        value = m.group(2);
      }

      // Look for options with a value.
      String name = findCliOption(arg, opts);
      if (name != null) {
        if (value == null) {
          if (idx == args.size() - 1) {
            throw new IllegalArgumentException(
                String.format("Missing argument for option '%s'.", arg));
          }
          idx++;
          value = args.get(idx);
        }
        if (!handle(name, value)) {
          break;
        }
        continue;
      }

      // Look for a switch.
      name = findCliOption(arg, switches);
      if (name != null) {
        if (!handle(name, null)) {
          break;
        }
        continue;
      }

      if (!handleUnknown(arg)) {
        break;
      }
    }

    if (idx < args.size()) {
      idx++;
    }
    handleExtraArgs(args.subList(idx, args.size()));
  }
552988
public static void main(String[] args)
   {
      try
      {
         if (args.length != 2)
         {
            System.out.println("Usage: MpxjConvert <input file name> <output file name>");
         }
         else
         {
            MpxjConvert convert = new MpxjConvert();
            convert.process(args[0], args[1]);
         }

         System.exit(0);
      }

      catch (Exception ex)
      {
         System.out.println();
         System.out.print("Conversion Error: ");
         ex.printStackTrace(System.out);
         System.out.println();
         System.exit(1);
      }
   }
818203
private String printConfigMappingTypes(
      Map<QName, MtasParserType<MtasParserMapping<?>>> types) {
    StringBuilder text = new StringBuilder();
    for (Entry<QName, MtasParserType<MtasParserMapping<?>>> entry : types
        .entrySet()) {
      text.append("- " + entry.getKey().getLocalPart() + ": "
          + entry.getValue().items.size() + " mapping(s)\n");
      for (int i = 0; i < entry.getValue().items.size(); i++) {
        text.append("\t" + entry.getValue().items.get(i) + "\n");
      }
    }
    return text.toString();
  }
109576
public static void main(String pArgs[]) {
        // Defaults
        int argIdx = 0;
        int speedTest = -1;
        boolean overWrite = false;
        boolean monochrome = false;
        boolean gray = false;
        int numColors = 256;
        String dither = null;
        String quality = null;
        String format = null;
        Color background = null;
        boolean transparency = false;
        String paletteFileName = null;
        boolean errArgs = false;

        // Parse args
        while ((argIdx < pArgs.length) && (pArgs[argIdx].charAt(0) == '-') && (pArgs[argIdx].length() >= 2)) {
            if ((pArgs[argIdx].charAt(1) == 's') || pArgs[argIdx].equals("--speedtest")) {
                argIdx++;

                // Get number of iterations
                if ((pArgs.length > argIdx) && (pArgs[argIdx].charAt(0) != '-')) {
                    try {
                        speedTest = Integer.parseInt(pArgs[argIdx++]);
                    }
                    catch (NumberFormatException nfe) {
                        errArgs = true;
                        break;
                    }
                }
                else {

                    // Default to 10 iterations
                    speedTest = 10;
                }
            }
            else if ((pArgs[argIdx].charAt(1) == 'w') || pArgs[argIdx].equals("--overwrite")) {
                overWrite = true;
                argIdx++;
            }
            else if ((pArgs[argIdx].charAt(1) == 'c') || pArgs[argIdx].equals("--colors")) {
                argIdx++;

                try {
                    numColors = Integer.parseInt(pArgs[argIdx++]);
                }
                catch (NumberFormatException nfe) {
                    errArgs = true;
                    break;
                }
            }
            else if ((pArgs[argIdx].charAt(1) == 'g') || pArgs[argIdx].equals("--grayscale")) {
                argIdx++;
                gray = true;
            }
            else if ((pArgs[argIdx].charAt(1) == 'm') || pArgs[argIdx].equals("--monochrome")) {
                argIdx++;
                numColors = 2;
                monochrome = true;
            }
            else if ((pArgs[argIdx].charAt(1) == 'd') || pArgs[argIdx].equals("--dither")) {
                argIdx++;
                dither = pArgs[argIdx++];
            }
            else if ((pArgs[argIdx].charAt(1) == 'p') || pArgs[argIdx].equals("--palette")) {
                argIdx++;
                paletteFileName = pArgs[argIdx++];
            }
            else if ((pArgs[argIdx].charAt(1) == 'q') || pArgs[argIdx].equals("--quality")) {
                argIdx++;
                quality = pArgs[argIdx++];
            }
            else if ((pArgs[argIdx].charAt(1) == 'b') || pArgs[argIdx].equals("--bgcolor")) {
                argIdx++;
                try {
                    background = StringUtil.toColor(pArgs[argIdx++]);
                }
                catch (Exception e) {
                    errArgs = true;
                    break;
                }
            }
            else if ((pArgs[argIdx].charAt(1) == 't') || pArgs[argIdx].equals("--transparency")) {
                argIdx++;
                transparency = true;
            }
            else if ((pArgs[argIdx].charAt(1) == 'f') || pArgs[argIdx].equals("--outputformat")) {
                argIdx++;
                format = StringUtil.toLowerCase(pArgs[argIdx++]);
            }
            else if ((pArgs[argIdx].charAt(1) == 'h') || pArgs[argIdx].equals("--help")) {
                argIdx++;

                // Setting errArgs to true, to print usage
                errArgs = true;
            }
            else {
                System.err.println("Unknown option \"" + pArgs[argIdx++] + "\"");
            }
        }
        if (errArgs || (pArgs.length < (argIdx + 1))) {
            System.err.println("Usage: IndexImage [--help|-h] [--speedtest|-s <integer>] [--bgcolor|-b <color>] [--colors|-c <integer> | --grayscale|g | --monochrome|-m | --palette|-p <file>] [--dither|-d (default|diffusion|none)] [--quality|-q (default|high|low)] [--transparency|-t] [--outputformat|-f (gif|jpeg|png|wbmp|...)] [--overwrite|-w] <input> [<output>]");
            System.err.print("Input format names: ");
            String[] readers = ImageIO.getReaderFormatNames();

            for (int i = 0; i < readers.length; i++) {
                System.err.print(readers[i] + ((i + 1 < readers.length)
                        ? ", "
                        : "\n"));
            }

            System.err.print("Output format names: ");
            String[] writers = ImageIO.getWriterFormatNames();

            for (int i = 0; i < writers.length; i++) {
                System.err.print(writers[i] + ((i + 1 < writers.length)
                        ? ", "
                        : "\n"));
            }
            System.exit(5);
        }

        // Read in image
        File in = new File(pArgs[argIdx++]);

        if (!in.exists()) {
            System.err.println("File \"" + in.getAbsolutePath() + "\" does not exist!");
            System.exit(5);
        }

        // Read palette if needed
        File paletteFile = null;

        if (paletteFileName != null) {
            paletteFile = new File(paletteFileName);
            if (!paletteFile.exists()) {
                System.err.println("File \"" + in.getAbsolutePath() + "\" does not exist!");
                System.exit(5);
            }
        }

        // Make sure we can write
        File out;

        if (argIdx < pArgs.length) {
            out = new File(pArgs[argIdx/*++*/]);

            // Get format from file extension
            if (format == null) {
                format = FileUtil.getExtension(out);
            }
        }
        else {
            // Create new file in current dir, same name + format extension
            String baseName = FileUtil.getBasename(in);

            // Use png as default format
            if (format == null) {
                format = "png";
            }
            out = new File(baseName + '.' + format);
        }

        if (!overWrite && out.exists()) {
            System.err.println("The file \"" + out.getAbsolutePath() + "\" allready exists!");
            System.exit(5);
        }

        // Do the image processing
        BufferedImage image = null;
        BufferedImage paletteImg = null;

        try {
            image = ImageIO.read(in);
            if (image == null) {
                System.err.println("No reader for image: \"" + in.getAbsolutePath() + "\"!");
                System.exit(5);
            }
            if (paletteFile != null) {
                paletteImg = ImageIO.read(paletteFile);
                if (paletteImg == null) {
                    System.err.println("No reader for image: \"" + paletteFile.getAbsolutePath() + "\"!");
                    System.exit(5);
                }
            }
        }
        catch (IOException ioe) {
            ioe.printStackTrace(System.err);
            System.exit(5);
        }

        // Create hints
        int hints = DITHER_DEFAULT;

        if ("DIFFUSION".equalsIgnoreCase(dither)) {
            hints |= DITHER_DIFFUSION;
        }
        else if ("DIFFUSION_ALTSCANS".equalsIgnoreCase(dither)) {
            hints |= DITHER_DIFFUSION_ALTSCANS;
        }
        else if ("NONE".equalsIgnoreCase(dither)) {
            hints |= DITHER_NONE;
        }
        else {

            // Don't care, use default
        }
        if ("HIGH".equalsIgnoreCase(quality)) {
            hints |= COLOR_SELECTION_QUALITY;
        }
        else if ("LOW".equalsIgnoreCase(quality)) {
            hints |= COLOR_SELECTION_FAST;
        }
        else {

            // Don't care, use default
        }
        if (transparency) {
            hints |= TRANSPARENCY_BITMASK;
        }

        //////////////////////////////
        // Apply bg-color WORKAROUND!
        // This needs to be done BEFORE palette creation to have desired effect..
        if ((background != null) && (paletteImg == null)) {
            paletteImg = createSolid(image, background);
        }

        ///////////////////////////////
        // Index
        long start = 0;

        if (speedTest > 0) {
            // SPEED TESTING
            System.out.println("Measuring speed!");
            start = System.currentTimeMillis();
            // END SPEED TESTING
        }

        BufferedImage indexed;
        IndexColorModel colors;

        if (monochrome) {
            indexed = getIndexedImage(image, MonochromeColorModel.getInstance(), background, hints);
            colors = MonochromeColorModel.getInstance();
        }
        else if (gray) {
            //indexed = ImageUtil.toBuffered(ImageUtil.grayscale(image), BufferedImage.TYPE_BYTE_GRAY);
            image = ImageUtil.toBuffered(ImageUtil.grayscale(image));
            indexed = getIndexedImage(image, colors = getIndexColorModel(image, numColors, hints), background, hints);

            // In casse of speedtest, this makes sense...
            if (speedTest > 0) {
                colors = getIndexColorModel(indexed, numColors, hints);
            }
        }
        else if (paletteImg != null) {
            // Get palette from image
            indexed = getIndexedImage(ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_ARGB),
                                      colors = getIndexColorModel(paletteImg, numColors, hints), background, hints);
        }
        else {
            image = ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_ARGB);
            indexed = getIndexedImage(image, colors = getIndexColorModel(image, numColors, hints), background, hints);
        }

        if (speedTest > 0) {
            // SPEED TESTING
            System.out.println("Color selection + dither: " + (System.currentTimeMillis() - start) + " ms");
            // END SPEED TESTING
        }

        // Write output (in given format)
        try {
            if (!ImageIO.write(indexed, format, out)) {
                System.err.println("No writer for format: \"" + format + "\"!");
            }
        }
        catch (IOException ioe) {
            ioe.printStackTrace(System.err);
        }

        if (speedTest > 0) {
            // SPEED TESTING
            System.out.println("Measuring speed!");

            // Warmup!
            for (int i = 0; i < 10; i++) {
                getIndexedImage(image, colors, background, hints);
            }

            // Measure
            long time = 0;

            for (int i = 0; i < speedTest; i++) {
                start = System.currentTimeMillis();
                getIndexedImage(image, colors, background, hints);
                time += (System.currentTimeMillis() - start);
                System.out.print('.');
                if ((i + 1) % 10 == 0) {
                    System.out.println("\nAverage (after " + (i + 1) + " iterations): " + (time / (i + 1)) + "ms");
                }
            }

            System.out.println("\nDither only:");
            System.out.println("Total time (" + speedTest + " invocations): " + time + "ms");
            System.out.println("Average: " + time / speedTest + "ms");
            // END SPEED TESTING
        }
    }
319643
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;
                    }
         */
    }
1086138
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.println("Usage: PosTagger [-d tagdict] [-di case_insensiteve_tagdict] model < tokenized_sentences");
      System.exit(1);
    }
    int ai=0;
    boolean test = false;
    String tagdict = null;
    boolean caseSensitive = true;
    while(ai < args.length && args[ai].startsWith("-")) {
      if (args[ai].equals("-d")) {
        tagdict = args[ai+1];
        ai+=2;
      }
      else if (args[ai].equals("-di")) {
        tagdict = args[ai+1];
        ai+=2;
        caseSensitive = false;
      }
    }
    POSTaggerME tagger;
    String model = args[ai++];
    String dictFile = null;
    if (ai < args.length) {
      dictFile = args[ai++];
    }
    
    if (tagdict != null) {
      if (dictFile != null) {
        tagger = new PosTagger(model,new Dictionary(dictFile),new POSDictionary(tagdict,caseSensitive));
      }
      else {
        tagger = new PosTagger(model,new POSDictionary(tagdict,caseSensitive));
      }
    }
    else {
      if (dictFile != null) {
        tagger = new PosTagger(model,new Dictionary(dictFile));
      }
      else {
        tagger = new PosTagger(model,(Dictionary)null);
      }
    }
    if (test) {
      System.out.println(tagger.tag(args[ai]));
    }
    else {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      
      for (String line = in.readLine(); line != null; line = in.readLine()) {
        System.out.println(tagger.tag(line));
      }
    }
  }
1232653
def print_files(opts, file_paths):
    
    print("Parsing the following files:")
    for file_path in file_paths:
        print("  " + strip_prefix(file_path, opts.abs_input))
    print("--------------------")
    print(str(len(file_paths)) + " total\n")
575453
private static void display(String format, Object... args) {
        System.out.println(MessageFormatter.arrayFormat(format, args).getMessage());
    }
132716
@Override
    public boolean parseArguments(final PrintStream messageStream, final String[] args) {
        this.argv = args;
        this.messageStream = messageStream;
        if (prefix.isEmpty()) {
            commandLine = callerOptions.getClass().getSimpleName();
        }
        for (int i = 0; i < args.length; ++i) {
            final String arg = args[i];
            if (arg.equals("-h") || arg.equals("--help")) {
                messageStream.append(usage(false, true));
                return false;
            }
            if (arg.equals("-H") || arg.equals("--stdhelp")) {
                messageStream.append(usage(true, true));
                return false;
            }

            if (arg.equals("--version")) {
                messageStream.println(getVersion());
                return false;
            }

            final String[] pair = arg.split("=", 2);
            if (pair.length == 2) {
                if (pair[1].isEmpty() && i < args.length - 1) {
                    pair[1] = args[++i];
                }
                if (!parseOption(pair[0], pair[1], false)) {
                    messageStream.println();
                    messageStream.append(usage(true, true));
                    return false;
                }
            } else if (!parsePositionalArgument(arg)) {
                messageStream.println();
                messageStream.append(usage(false, true));
                return false;
            }
        }
        if (!checkNumArguments()) {
            messageStream.println();
            messageStream.append(usage(false, true));
            return false;
        }

        return true;
    }
342522
public static void main(String[] pArgs) throws Exception {
    // -- Print DTD
    System.out.println("DTD: \n" + DTD);
    System.out.println("--");

    // -- Test load
    System.out.println("Reading properties from \"" + pArgs[0] + "\"...");
    XMLProperties props = new XMLProperties();

    props.load(new FileInputStream(new File(pArgs[0])));
    props.list(System.out);
    System.out.println("--");

    // -- Test recursion
    String     key = "key";
    Object     old = props.setProperty(key, "AAA");
    Properties p1  = new XMLProperties(new XMLProperties(props));
    Properties p2  = new Properties(new Properties(props));

    System.out.println("XMLProperties: " + p1.getProperty(key) + " ==" + " Properties: " + p2.getProperty(key));
    if (old == null) {
      props.remove("key");
    } else {
      props.put("key", old);  // Put old value back, to avoid confusion...
    }
    System.out.println("--");

    // -- Test store
    //props.store(System.out, "XML Properties file written by XMLProperties.");
    File out = new File("copy_of_" + pArgs[0]);

    System.out.println("Writing properties to \"" + out.getName() + "\"");
    if (!out.exists()) {
      props.store(new FileOutputStream(out), "XML Properties file written by XMLProperties.");
    } else {
      System.err.println("File \"" + out.getName() + "\" allready exists, cannot write!");
    }

    // -- Test utility methods
    // Write normal properties from XMLProperties
    out = new File("copy_of_" + pArgs[0].substring(0, pArgs[0].lastIndexOf(".")) + ".properties");
    System.out.println("Writing properties to \"" + out.getName() + "\"");
    if (!out.exists()) {
      storeProperties(props, new FileOutputStream(out), "Properties file written by XMLProperties.");
    } else {
      System.err.println("File \"" + out.getName() + "\" allready exists, cannot write!");
    }
    System.out.println("--");

    // -- Test type attribute
    System.out.println("getPropertyValue(\"one\"): " + props.getPropertyValue("one") + " class: "
                       + props.getPropertyValue("one").getClass());
    System.out.println("setPropertyValue(\"now\", " + new Date() + "): " + props.setPropertyValue("now", new Date()) + " class: "
                       + props.getPropertyValue("now").getClass());
    System.out.println("getPropertyValue(\"date\"): " + props.getPropertyValue("date") + " class: "
                       + props.getPropertyValue("date").getClass());
    System.out.println("getPropertyValue(\"time\"): " + props.getPropertyValue("time") + " class: "
                       + props.getPropertyValue("time").getClass());
  }
1191016
public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        RegularExpression<String> regex = RegularExpressionParsers.word.parse(args[0]);
        System.out.println("regex: " + regex);
        System.out.println();

        while (scan.hasNextLine()) {
            String line = scan.nextLine();

            System.out.println("contains: " + regex.apply(Arrays.asList(line.split("\\s+"))));
            System.out.println("matches:  " + regex.matches(Arrays.asList(line.split("\\s+"))));
            System.out.println();
        }

        scan.close();
    }
1293026
def main(pargs):
    
    input_file = sys.argv[1]
    fp = ParseFileLineByLine(input_file)
    for i in fp:
        print(i)