Example usage for java.text SimpleDateFormat SimpleDateFormat

List of usage examples for java.text SimpleDateFormat SimpleDateFormat

Introduction

In this page you can find the example usage for java.text SimpleDateFormat SimpleDateFormat.

Prototype

public SimpleDateFormat(String pattern) 

Source Link

Document

Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:MainGeneratePicasaIniFile.java

public static void main(String[] args) {
    try {/*from w  w  w  . ja va 2  s  . c  o  m*/

        Calendar start = Calendar.getInstance();

        start.set(1899, 11, 30, 0, 0);

        PicasawebService myService = new PicasawebService("My Application");
        myService.setUserCredentials(args[0], args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album");
        System.out.println("Getting Picasa Web Albums entries...\n");
        UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);

        // resultFeed.

        File root = new File(args[2]);
        File[] albuns = root.listFiles();

        int j = 0;
        List<GphotoEntry> entries = resultFeed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            GphotoEntry entry = entries.get(i);
            String href = entry.getHtmlLink().getHref();

            String name = entry.getTitle().getPlainText();

            for (File album : albuns) {
                if (album.getName().equals(name) && !href.contains("02?")) {
                    File picasaini = new File(album, "Picasa.ini");

                    if (!picasaini.exists()) {
                        StringBuilder builder = new StringBuilder();

                        builder.append("\n");
                        builder.append("[Picasa]\n");
                        builder.append("name=");
                        builder.append(name);
                        builder.append("\n");
                        builder.append("location=");
                        Collection<Extension> extensions = entry.getExtensions();

                        for (Extension extension : extensions) {

                            if (extension instanceof GphotoLocation) {
                                GphotoLocation location = (GphotoLocation) extension;
                                if (location.getValue() != null) {
                                    builder.append(location.getValue());
                                }
                            }
                        }
                        builder.append("\n");
                        builder.append("category=Folders on Disk");
                        builder.append("\n");
                        builder.append("date=");
                        String source = name.substring(0, 10);

                        DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");

                        Date date = formater.parse(source);

                        Calendar end = Calendar.getInstance();

                        end.setTime(date);

                        builder.append(daysBetween(start, end));
                        builder.append(".000000");
                        builder.append("\n");
                        builder.append(args[0]);
                        builder.append("_lh=");
                        builder.append(entry.getGphotoId());
                        builder.append("\n");
                        builder.append("P2category=Folders on Disk");
                        builder.append("\n");

                        URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0]
                                + "/albumid/" + entry.getGphotoId());

                        AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);

                        for (GphotoEntry photo : feed.getEntries()) {
                            builder.append("\n");
                            builder.append("[");
                            builder.append(photo.getTitle().getPlainText());
                            builder.append("]");
                            builder.append("\n");
                            long id = Long.parseLong(photo.getGphotoId());

                            builder.append("IIDLIST_");
                            builder.append(args[0]);
                            builder.append("_lh=");
                            builder.append(Long.toHexString(id));
                            builder.append("\n");
                        }

                        System.out.println(builder.toString());
                        IOUtils.write(builder.toString(), new FileOutputStream(picasaini));
                        j++;
                    }
                }

            }

        }
        System.out.println(j);
        System.out.println("\nTotal Entries: " + entries.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.anthonypoon.ngram.correlation.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("a", "action", true, "Action");
    options.addOption("i", "input", true, "input");
    options.addOption("o", "output", true, "output");
    //options.addOption("f", "format", true, "Format");
    options.addOption("u", "upbound", true, "Year up bound");
    options.addOption("l", "lowbound", true, "Year low bound");
    options.addOption("t", "target", true, "Correlation Target URI"); // Can only take file from S# or HDFS
    options.addOption("L", "lag", true, "Lag factor");
    options.addOption("T", "threshold", true, "Correlation threshold");
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    Configuration conf = new Configuration();
    if (cmd.hasOption("lag")) {
        conf.set("lag", cmd.getOptionValue("lag"));
    }//from  w  w  w.  j a  va  2 s.co  m
    if (cmd.hasOption("threshold")) {
        conf.set("threshold", cmd.getOptionValue("threshold"));
    }
    if (cmd.hasOption("upbound")) {
        conf.set("upbound", cmd.getOptionValue("upbound"));
    } else {
        conf.set("upbound", "9999");
    }
    if (cmd.hasOption("lowbound")) {
        conf.set("lowbound", cmd.getOptionValue("lowbound"));
    } else {
        conf.set("lowbound", "0");
    }
    if (cmd.hasOption("target")) {
        conf.set("target", cmd.getOptionValue("target"));
    } else {
        throw new Exception("Missing correlation target file uri");
    }
    Job job = Job.getInstance(conf);
    /**
    if (cmd.hasOption("format")) {
    switch (cmd.getOptionValue("format")) {
        case "compressed":
            job.setInputFormatClass(SequenceFileAsTextInputFormat.class);
            break;
        case "text":
            job.setInputFormatClass(KeyValueTextInputFormat.class);
            break;
    }
            
    }**/
    job.setJarByClass(Main.class);
    switch (cmd.getOptionValue("action")) {
    case "get-correlation":
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        for (String inputPath : cmd.getOptionValue("input").split(",")) {
            MultipleInputs.addInputPath(job, new Path(inputPath), KeyValueTextInputFormat.class,
                    CorrelationMapper.class);
        }
        job.setReducerClass(CorrelationReducer.class);
        break;
    default:
        throw new IllegalArgumentException("Missing action");
    }

    String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date());

    //FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input")));
    FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

From source file:javatest.IndicatorsToChart.java

public static void main(String[] args) {

    /**/*from ww  w. j  a v  a 2s  .  c om*/
     * Getting time series
     */
    TimeSeries series = CsvTicksLoader.loadAppleIncSeries();

    /**
     * Creating indicators
     */
    // Close price
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    // Bollinger bands
    BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(closePrice);
    BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, closePrice);
    BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, closePrice);
    SMAIndicator ind = new SMAIndicator(closePrice, 240);
    /**
     * Building chart dataset
     */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, ind, "sms "));
    dataset.addSeries(buildChartTimeSeries(series, closePrice, "close"));
    // dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Neli ist lieb", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

From source file:com.stumbleupon.hbaseadmin.HBaseCompact.java

/**
 * Main entry point/*from   w  w w  .  j  av  a  2  s  .c om*/
 * @param args command line arguments
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    String hbaseSite = null;
    String jmxRemotePasswordFile = null;
    String jmxPort = null;
    Date startDate = null;
    Date endDate = null;
    int throttleFactor = 1;
    int numCycles = 1;
    int pauseInterval = DEFAULT_PAUSE_INTERVAL;
    int waitInterval = DEFAULT_WAIT_INTERVAL;
    int filesKeep = DEFAULT_FILES_KEEP;
    long regionCompactWaitTime = DEFAULT_REGION_COMPACT_WAIT_TIME;
    long maxStoreFileAge = 0;
    boolean excludeTables = false;
    String tableNamesString = "";
    List<String> tableNames = new ArrayList<String>();
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

    // Parse command line options
    try {
        cmd = parser.parse(getOptions(), args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println(e.getMessage());
        printOptions();
        System.exit(-1);
    }

    for (Option option : cmd.getOptions()) {
        switch (option.getId()) {
        case 'c':
            hbaseSite = option.getValue();
            break;
        case 'j':
            jmxRemotePasswordFile = option.getValue();
            break;
        case 't':
            throttleFactor = Integer.parseInt(option.getValue());
            break;
        case 'n':
            numCycles = Integer.parseInt(option.getValue());
            break;
        case 'p':
            pauseInterval = Integer.parseInt(option.getValue());
            break;
        case 'w':
            waitInterval = Integer.parseInt(option.getValue());
            break;
        case 's':
            startDate = sdf.parse(option.getValue());
            break;
        case 'e':
            endDate = sdf.parse(option.getValue());
            break;
        case 'b':
            tableNamesString = option.getValue();
            tableNames = Arrays.asList(option.getValue().split(","));
            break;
        case 'f':
            filesKeep = Integer.parseInt(option.getValue());
            break;
        case 'r':
            jmxPort = option.getValue();
            break;
        case 'x':
            excludeTables = true;
            break;
        case 'm':
            regionCompactWaitTime = Long.parseLong(option.getValue());
            break;
        case 'a':
            maxStoreFileAge = Long.parseLong(option.getValue());
            break;
        default:
            throw new IllegalArgumentException("unexpected option " + option);
        }
    }

    LOG.info("Starting compactor");
    LOG.info("--------------------------------------------------");
    LOG.info("HBase site              : {}", hbaseSite);
    LOG.info("RegionServer Jmx port   : {}", jmxPort);
    LOG.info("Jmx password file       : {}", jmxRemotePasswordFile);
    LOG.info("Compact interval        : {}", pauseInterval);
    LOG.info("Check interval          : {}", waitInterval);
    LOG.info("Throttle factor         : {}", throttleFactor);
    LOG.info("Number of cycles        : {}", numCycles);
    LOG.info("Off-peak start time     : {}", Utils.dateString(startDate, "HH:mm"));
    LOG.info("Off-peak end time       : {}", Utils.dateString(endDate, "HH:mm"));
    LOG.info("Minimum store files     : {}", filesKeep);
    LOG.info("Table names             : {}", tableNamesString);
    LOG.info("Exclude tables          : {}", excludeTables);
    LOG.info("Region compact wait time: {}", regionCompactWaitTime);
    LOG.info("Max store file age      : {}", maxStoreFileAge);
    LOG.info("--------------------------------------------------");

    // Get command line options
    final Configuration conf = HBaseConfiguration.create();
    conf.addResource(new Path(hbaseSite));

    HBaseCompact compact = new HBaseCompact();
    ClusterUtils clusterUtils = new ClusterUtils(compact, regionCompactWaitTime);

    compact.setClusterUtils(clusterUtils);
    compact.setAdmin(new HBaseAdmin(conf));
    compact.setSleepBetweenCompacts(pauseInterval);
    compact.setSleepBetweenChecks(waitInterval);
    compact.setThrottleFactor(throttleFactor);
    compact.setNumCycles(numCycles);
    compact.setStartDate(startDate);
    compact.setEndDate(endDate);
    compact.setNumStoreFiles(filesKeep);
    compact.setTableNames(tableNames);
    compact.setExcludeTables(excludeTables);
    compact.setMaxStoreFileAge(maxStoreFileAge);

    clusterUtils.setJmxPort(jmxPort);
    clusterUtils.setJmxPasswordFile(jmxRemotePasswordFile);

    compact.runCompactions();
}

From source file:de.codesourcery.eve.skills.ui.ChartTest.java

public static void main(String[] args) {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Day(1, 2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);
    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);// w  w  w  .j  a  v  a  2  s  .c  om
    dataset.addSeries(s2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // display chart
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);

    JFrame frame = new JFrame("test");
    frame.setContentPane(chartPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

From source file:BookRank.java

/** Grab the sales rank off the web page and log it. */
public static void main(String[] args) throws Exception {

    Properties p = new Properties();
    String title = p.getProperty("title", "NO TITLE IN PROPERTIES");
    // The url must have the "isbn=" at the very end, or otherwise
    // be amenable to being string-catted to, like the default.
    String url = p.getProperty("url", "http://test.ing/test.cgi?isbn=");
    // The 10-digit ISBN for the book.
    String isbn = p.getProperty("isbn", "0000000000");
    // The RE pattern (MUST have ONE capture group for the number)
    String pattern = p.getProperty("pattern", "Rank: (\\d+)");

    // Looking for something like this in the input:
    //    <b>QuickBookShop.web Sales Rank: </b>
    //    26,252//  www . ja v  a  2  s.c  o  m
    //    </font><br>

    Pattern r = Pattern.compile(pattern);

    // Open the URL and get a Reader from it.
    BufferedReader is = new BufferedReader(new InputStreamReader(new URL(url + isbn).openStream()));
    // Read the URL looking for the rank information, as
    // a single long string, so can match RE across multi-lines.
    String input = "input from console";
    // System.out.println(input);

    // If found, append to sales data file.
    Matcher m = r.matcher(input);
    if (m.find()) {
        PrintWriter pw = new PrintWriter(new FileWriter(DATA_FILE, true));
        String date = // `date +'%m %d %H %M %S %Y'`;
                new SimpleDateFormat("MM dd hh mm ss yyyy ").format(new Date());
        // Paren 1 is the digits (and maybe ','s) that matched; remove comma
        Matcher noComma = Pattern.compile(",").matcher(m.group(1));
        pw.println(date + noComma.replaceAll(""));
        pw.close();
    } else {
        System.err.println("WARNING: pattern `" + pattern + "' did not match in `" + url + isbn + "'!");
    }

    // Whether current data found or not, draw the graph, using
    // external plotting program against all historical data.
    // Could use gnuplot, R, any other math/graph program.
    // Better yet: use one of the Java plotting APIs.

    String gnuplot_cmd = "set term png\n" + "set output \"" + GRAPH_FILE + "\"\n" + "set xdata time\n"
            + "set ylabel \"Book sales rank\"\n" + "set bmargin 3\n" + "set logscale y\n"
            + "set yrange [1:60000] reverse\n" + "set timefmt \"%m %d %H %M %S %Y\"\n" + "plot \"" + DATA_FILE
            + "\" using 1:7 title \"" + title + "\" with lines\n";

    Process proc = Runtime.getRuntime().exec("/usr/local/bin/gnuplot");
    PrintWriter gp = new PrintWriter(proc.getOutputStream());
    gp.print(gnuplot_cmd);
    gp.close();
}

From source file:GIST.IzbirkomExtractor.IzbirkomExtractor.java

/**
 * @param args//from w  w w  .j  a  va 2s  . c om
 */
public static void main(String[] args) {

    // process command-line options
    Options options = new Options();
    options.addOption("n", "noaddr", false, "do not do any address matching (for testing)");
    options.addOption("i", "info", false, "create and populate address information table");
    options.addOption("h", "help", false, "this message");

    // database connection
    options.addOption("s", "server", true, "database server to connect to");
    options.addOption("d", "database", true, "OSM database name");
    options.addOption("u", "user", true, "OSM database user name");
    options.addOption("p", "pass", true, "OSM database password");

    // logging options
    options.addOption("l", "logdir", true, "log file directory (default './logs')");
    options.addOption("e", "loglevel", true, "log level (default 'FINEST')");

    // automatically generate the help statement
    HelpFormatter help_formatter = new HelpFormatter();

    // database URI for connection
    String dburi = null;

    // Information message for help screen
    String info_msg = "IzbirkomExtractor [options] <html_directory>";

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption('h') || cmd.getArgs().length != 1) {
            help_formatter.printHelp(info_msg, options);
            System.exit(1);
        }

        /* prohibit n and i together */
        if (cmd.hasOption('n') && cmd.hasOption('i')) {
            System.err.println("Options 'n' and 'i' cannot be used together.");
            System.exit(1);
        }

        /* require database arguments without -n */
        if (cmd.hasOption('n')
                && (cmd.hasOption('s') || cmd.hasOption('d') || cmd.hasOption('u') || cmd.hasOption('p'))) {
            System.err.println("Options 'n' and does not need any databse parameters.");
            System.exit(1);
        }

        /* require all 4 database options to be used together */
        if (!cmd.hasOption('n')
                && !(cmd.hasOption('s') && cmd.hasOption('d') && cmd.hasOption('u') && cmd.hasOption('p'))) {
            System.err.println(
                    "For database access all of the following arguments have to be specified: server, database, user, pass");
            System.exit(1);
        }

        /* useful variables */
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm");
        String dateString = formatter.format(new Date());

        /* setup logging */
        File logdir = new File(cmd.hasOption('l') ? cmd.getOptionValue('l') : "logs");
        FileUtils.forceMkdir(logdir);
        File log_file_name = new File(
                logdir + "/" + IzbirkomExtractor.class.getName() + "-" + formatter.format(new Date()) + ".log");
        FileHandler log_file = new FileHandler(log_file_name.getPath());

        /* create "latest" link to currently created log file */
        Path latest_log_link = Paths.get(logdir + "/latest");
        Files.deleteIfExists(latest_log_link);
        Files.createSymbolicLink(latest_log_link, Paths.get(log_file_name.getName()));

        log_file.setFormatter(new SimpleFormatter());
        LogManager.getLogManager().reset(); // prevents logging to console
        logger.addHandler(log_file);
        logger.setLevel(cmd.hasOption('e') ? Level.parse(cmd.getOptionValue('e')) : Level.FINEST);

        // open directory with HTML files and create file list
        File dir = new File(cmd.getArgs()[0]);
        if (!dir.isDirectory()) {
            System.err.println("Unable to find directory '" + cmd.getArgs()[0] + "', exiting");
            System.exit(1);
        }
        PathMatcher pmatcher = FileSystems.getDefault()
                .getPathMatcher("glob:?  * ?*.html");
        ArrayList<File> html_files = new ArrayList<>();
        for (Path file : Files.newDirectoryStream(dir.toPath()))
            if (pmatcher.matches(file.getFileName()))
                html_files.add(file.toFile());
        if (html_files.size() == 0) {
            System.err.println("No matching HTML files found in '" + dir.getAbsolutePath() + "', exiting");
            System.exit(1);
        }

        // create csvResultSink
        FileOutputStream csvout_file = new FileOutputStream("parsed_addresses-" + dateString + ".csv");
        OutputStreamWriter csvout = new OutputStreamWriter(csvout_file, "UTF-8");
        ResultSink csvResultSink = new CSVResultSink(csvout, new CSVStrategy('|', '"', '#'));

        // Connect to DB and osmAddressMatcher
        AddressMatcher osmAddressMatcher;
        DBSink dbSink = null;
        DBInfoSink dbInfoSink = null;
        if (cmd.hasOption('n')) {
            osmAddressMatcher = new DummyAddressMatcher();
        } else {
            dburi = "jdbc:postgresql://" + cmd.getOptionValue('s') + "/" + cmd.getOptionValue('d');
            Connection con = DriverManager.getConnection(dburi, cmd.getOptionValue('u'),
                    cmd.getOptionValue('p'));
            osmAddressMatcher = new OsmAddressMatcher(con);
            dbSink = new DBSink(con);
            if (cmd.hasOption('i'))
                dbInfoSink = new DBInfoSink(con);
        }

        /* create resultsinks */
        SinkMultiplexor sm = SinkMultiplexor.newSinkMultiplexor();
        sm.addResultSink(csvResultSink);
        if (dbSink != null) {
            sm.addResultSink(dbSink);
            if (dbInfoSink != null)
                sm.addResultSink(dbInfoSink);
        }

        // create tableExtractor
        TableExtractor te = new TableExtractor(osmAddressMatcher, sm);

        // TODO: printout summary of options: processing date/time, host, directory of HTML files, jdbc uri, command line with parameters

        // iterate through files
        logger.info("Start processing " + html_files.size() + " files in " + dir);
        for (int i = 0; i < html_files.size(); i++) {
            System.err.println("Parsing #" + i + ": " + html_files.get(i));
            te.processHTMLfile(html_files.get(i));
        }

        System.err.println("Processed " + html_files.size() + " HTML files");
        logger.info("Finished processing " + html_files.size() + " files in " + dir);

    } catch (ParseException e1) {
        System.err.println("Failed to parse CLI: " + e1.getMessage());
        help_formatter.printHelp(info_msg, options);
        System.exit(1);
    } catch (IOException e) {
        System.err.println("I/O Exception: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    } catch (SQLException e) {
        System.err.println("Database '" + dburi + "': " + e.getMessage());
        System.exit(1);
    } catch (ResultSinkException e) {
        System.err.println("Failed to initialize ResultSink: " + e.getMessage());
        System.exit(1);
    } catch (TableExtractorException e) {
        System.err.println("Failed to initialize Table Extractor: " + e.getMessage());
        System.exit(1);
    } catch (CloneNotSupportedException | IllegalAccessException | InstantiationException e) {
        System.err.println("Something really odd happened: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:eu.trentorise.opendata.jackan.test.ckan.CkanTestReporter.java

/**
 * Takes as first argument the catalog list files to be used. If not
 * provided, by default test/resources/ckan-instances.txt file is used.
 *//*ww  w . ja v a  2  s .  c  o m*/
public static void main(String[] args) {

    JackanTestConfig.of().loadConfig();

    String catFilename;

    if (args.length == 2) {
        catFilename = args[1];
        logger.log(Level.INFO, "Using provided catalogs file {0}", catFilename);
    } else {
        catFilename = "ckan-instances.txt";
        logger.log(Level.INFO,
                "Using default catalogs file {0}. If you wish to provide yours pass filename as first argument.",
                catFilename);
    }

    Map<String, String> catalogsNames = readCatalogsList(catFilename);

    List<String> testNames = ALL_TEST_NAMES;

    RunSuite testResults = runTests(catalogsNames, testNames);

    String content = renderRunSuite(catalogsNames, testNames, testResults);

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd--HH-mm-ss");
    saveToDirectory(new File("reports/" + REPORT_PREFIX + "-" + formatter.format(new Date())), content,
            testResults);

    File latestDir = new File("reports/" + REPORT_PREFIX + "-latest");

    FileUtils.deleteQuietly(latestDir);
    saveToDirectory(latestDir, content, testResults);

}

From source file:ca.uqac.info.Job.Launcher.JobLauncher.java

public static void main(final String[] args) {
    // Parse command line arguments
    Options options = setupOptions();/*from www  . j a  va2 s.  c  o  m*/
    CommandLine c_line = setupCommandLine(args, options);

    String batFolder = "";
    String outFolderStr = "";

    File folderBat = null;
    File[] listOfFiles = null;
    String files = "";

    String username = "";
    String password = "";
    String recipient = "";
    String message = "";

    boolean emailOpt = false;
    GoogleMail Gmail = null;

    if (c_line.hasOption("e")) {
        emailOpt = Boolean.parseBoolean(c_line.getOptionValue("email"));
    }

    if (emailOpt == true) {
        Gmail = new GoogleMail();
    }

    // boolean nextJob = true;

    if (c_line.hasOption("h")) {
        showUsage(options);
        System.exit(ERR_OK);
    }

    //Contains a bat folder
    if (c_line.hasOption("b")) {
        batFolder = c_line.getOptionValue("BatFolder");
    } else {
        System.err.println("No Bat Folder in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a Output folder
    if (c_line.hasOption("o")) {
        outFolderStr = c_line.getOptionValue("OutputFolder");
    } else {
        System.err.println("No Output Folder in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Use the email option
    if (emailOpt == true) {
        //Contains the username
        if (c_line.hasOption("username")) {
            username = c_line.getOptionValue("u");
        } else {
            System.err.println("No username in Arguments");
            System.exit(ERR_ARGUMENTS);
        }

        //Contains the password
        if (c_line.hasOption("password")) {
            password = c_line.getOptionValue("p");
        } else {
            System.err.println("No password in Arguments");
            System.exit(ERR_ARGUMENTS);
        }

        //Contains the recipient Email
        if (c_line.hasOption("recipientEmail")) {
            recipient = c_line.getOptionValue("r");
        } else {
            System.err.println("No recipient Email in Arguments");
            System.exit(ERR_ARGUMENTS);
        }
    }

    folderBat = new File(batFolder);
    listOfFiles = folderBat.listFiles();

    File outFolder = new File(outFolderStr);

    //Make sure to test all of the files
    for (int i = 0; i < listOfFiles.length; i++) {

        if (listOfFiles[i].isFile()) {
            files = listOfFiles[i].getName();
            String outName = outFolderStr + "\\Results_" + files + ".txt";
            message = outName;

            //Make sure to use only the bat files
            if (files.endsWith(".bat") || files.endsWith(".Bat")) {
                try {
                    String StartDay = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date());
                    long timeBefore = new Date().getTime();

                    int exitStatus = launchJob(listOfFiles[i].getAbsolutePath(), outName, outFolder);

                    long timeAfter = new Date().getTime();
                    String EndDay = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date());
                    long timeLaunch = timeAfter - timeBefore;

                    if (exitStatus != 0)// An error arrived in the job launch
                    {
                        message += " exitStatus : " + exitStatus;
                        message += " \n Total : " + timeLaunch + " ms";
                        message += " \n Start : " + StartDay;
                        message += "\n End : " + EndDay;

                        //Send the email to tell the launch job status
                        sendEmail(Gmail, emailOpt, username, password, recipient, "Error :" + files, message);
                    } else // Every things is fine 
                    {
                        message += " \n Total : " + timeLaunch + " ms";
                        message += " \n Start : " + StartDay;
                        message += "\n End : " + EndDay;

                        //Send the email to tell the launch job status
                        sendEmail(Gmail, emailOpt, username, password, recipient, files + " Done !!!", message);
                    }
                } catch (Exception e) {
                    //Send a email for the error from the launch of the job
                    sendEmail(Gmail, emailOpt, username, password, recipient, "Error :" + files,
                            "Launch Job and/or SMTP error !!!");

                    e.printStackTrace();
                }
            } // if files .bat
        } // if isFile
    } // For listOfFiles

}

From source file:com.mozilla.socorro.RawDumpSizeScan.java

public static void main(String[] args) throws ParseException {
    String startDateStr = args[0];
    String endDateStr = args[1];// w ww  .  j  av a 2s. com

    // Set both start/end time and start/stop row
    Calendar startCal = Calendar.getInstance();
    Calendar endCal = Calendar.getInstance();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

    if (!StringUtils.isBlank(startDateStr)) {
        startCal.setTime(sdf.parse(startDateStr));
    }
    if (!StringUtils.isBlank(endDateStr)) {
        endCal.setTime(sdf.parse(endDateStr));
    }

    DescriptiveStatistics stats = new DescriptiveStatistics();
    long numNullRawBytes = 0L;
    HTable table = null;
    Map<String, Integer> rowValueSizeMap = new HashMap<String, Integer>();
    try {
        table = new HTable(TABLE_NAME_CRASH_REPORTS);
        Scan[] scans = generateScans(startCal, endCal);
        for (Scan s : scans) {
            ResultScanner rs = table.getScanner(s);
            Iterator<Result> iter = rs.iterator();
            while (iter.hasNext()) {
                Result r = iter.next();
                ImmutableBytesWritable rawBytes = r.getBytes();
                //length = r.getValue(RAW_DATA_BYTES, DUMP_BYTES);
                if (rawBytes != null) {
                    int length = rawBytes.getLength();
                    if (length > 20971520) {
                        rowValueSizeMap.put(new String(r.getRow()), length);
                    }
                    stats.addValue(length);
                } else {
                    numNullRawBytes++;
                }

                if (stats.getN() % 10000 == 0) {
                    System.out.println("Processed " + stats.getN());
                    System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(),
                            stats.getMax(), stats.getMean()));
                    System.out.println(
                            String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f",
                                    stats.getPercentile(25.0d), stats.getPercentile(50.0d),
                                    stats.getPercentile(75.0d)));
                    System.out.println("Number of large entries: " + rowValueSizeMap.size());
                }
            }
            rs.close();
        }

        System.out.println("Finished Processing!");
        System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(), stats.getMax(),
                stats.getMean()));
        System.out.println(String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f",
                stats.getPercentile(25.0d), stats.getPercentile(50.0d), stats.getPercentile(75.0d)));

        for (Map.Entry<String, Integer> entry : rowValueSizeMap.entrySet()) {
            System.out.println(String.format("RowId: %s => Length: %d", entry.getKey(), entry.getValue()));
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (table != null) {
            try {
                table.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}