Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

In this page you can find the example usage for java.io IOException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:experiments.SimpleExample.java

/**
 * Starts the example.//from w  w  w  . j a v  a  2s.  c o m
 * 
 * @param args
 *            if optional first argument provided, it represents the number
 *            of bits to use, but no more than 32
 * 
 * @author Neil Rotstan
 * @author Klaus Meffert
 * @throws IOException 
 * @since 2.0
 */
public static void main(String[] args) throws IOException {

    SimpleExample se = new SimpleExample();

    try {
        File[] result = { new File("ga_x.txt"), new File("ga_cos.txt"), new File("ga_ackley.txt"),
                new File("ga_quar.txt"), new File("ga_step.txt"), new File("ga_rosen.txt"),
                new File("ga_sch.txt"), new File("ga_gri.txt"), new File("ga_pen1.txt"),
                new File("ga_pen2.txt"), new File("ga_wei.txt"), new File("ga_non.txt") };
        BufferedWriter[] output = new BufferedWriter[result.length];
        for (int i = 0; i <= result.length - 1; i++) {
            if (result[i].exists()) {
                result[i].delete();
                if (result[i].createNewFile()) {
                    System.out.println("result" + i + " file create success!");
                } else {
                    System.out.println("result" + i + " file create failed!");
                }
            } else {
                if (result[i].createNewFile()) {
                    System.out.println("result" + i + " file create success!");
                } else {
                    System.out.println("result" + i + " file create failed!");
                }

            }
            output[i] = new BufferedWriter(new FileWriter(result[i]));
        }

        for (int a = 0; a <= 0; a++) {
            //            se.runga(100, 30, 40, -100,  100, new MaxFunction(), output[0]);
            //            se.runga(200, 30, 40, -100,  100, new MaxFunction(), output[0]);
            //            se.runga(120, 30, 40, -5.12,  5.12, new CosMaxFunction(), output[1]);
            //            se.runga(200, 30, 40, -5.12,  5.12, new CosMaxFunction(), output[1]);
            //            se.runga(120, 30, 40, -32,  32, new AckleyMaxFunction(), output[2]);
            se.runga(2000, 30, 40, -32, 32, new AckleyMaxFunction(), output[2]);
            //            se.runga(120, 30, 40, -100,  100, new QuardircMaxFunction(), output[3]);
            //            se.runga(200, 30, 40, -100,  100, new QuardircMaxFunction(), output[3]);
            //            se.runga(120, 30, 40, -100,  100, new StepMaxFunction(), output[4]);
            //            se.runga(200, 30, 40, -100,  100, new StepMaxFunction(), output[4]);
            //            se.runga(120, 30, 40, -30,  30, new RosenbrockMaxFunction(), output[5]);
            //            se.runga(200, 30, 40, -30,  30, new RosenbrockMaxFunction(), output[5]);
            //            se.runga(120, 30, 40, -500,  500, new SchwefelMaxFunction(), output[6]);
            //            se.runga(200, 30, 40, -500,  500, new SchwefelMaxFunction(), output[6]);
            //            se.runga(120, 30, 40, -600,  600, new GriewankMaxFunction(), output[7]);
            //            se.runga(200, 30, 40, -600,  600, new GriewankMaxFunction(), output[7]);
            //            se.runga(120, 30, 40, -50,  50, new PenalizedMaxFunction(), output[8]);
            //            se.runga(200, 30, 40, -50,  50, new PenalizedMaxFunction(), output[8]);
            //            se.runga(120, 30, 40, -50,  50, new Penalized2MaxFunction(), output[9]);
            //            se.runga(200, 30, 40, -50,  50, new Penalized2MaxFunction(), output[9]);
            //            se.runga(120, 30, 40, -5.12,  5.12, new WeiMaxFunction(), output[10]);
            //            se.runga(200, 30, 40, -5.12,  5.12, new WeiMaxFunction(), output[10]);
            //            se.runga(120, 30, 40, -0.5,  0.5, new NonMaxFunction(), output[11]);
            //            se.runga(200, 30, 40, -0.5,  0.5, new NonMaxFunction(), output[11]);
            for (BufferedWriter op : output) {
                op.write("\n");
                op.flush();
            }
        }

        for (BufferedWriter op : output) {
            op.close();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.hw13c.HttpClientPost.java

public static void main(String[] args) {
    output = new File("out");
    input = new File("in");
    try {/*from   w w  w  .j a v  a  2  s . co m*/
        //   URL urls = new URL("http://www.bbc.com/sport/0/sports-personality/30267315");
        // 1.   URL urls = new URL("http://abcnews.go.com/US/nypd-officer-indicted-eric-garner-choke-hold-death/story?id=27341079");
        URL urls = new URL(
                "http://www.chron.com/news/us/article/UN-campaign-seeks-64-million-for-Syrian-refugees-5932973.php");

        //URL urls = new URL("http://www.bbc.com/news/health-30254697");
        FileUtils.copyURLToFile(urls, input);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //  verifyArgs(args);
    HttpClientPost httpClientPost = new HttpClientPost();
    //httpClientPost.input = new File(args[0]);
    //httpClientPost.output = new File(args[1]);
    httpClientPost.client = new HttpClient();
    httpClientPost.client.getParams().setParameter("http.useragent", "Calais Rest Client");

    httpClientPost.run();
    try {
        queryRDFTriples();
    } catch (RepositoryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RDFParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:io.amient.kafka.metrics.DiscoveryTool.java

public static void main(String[] args) throws IOException {

    OptionParser parser = new OptionParser();

    parser.accepts("help", "Print usage help");
    OptionSpec<String> zookeeper = parser.accepts("zookeeper", "Address of the seed zookeeper server")
            .withRequiredArg().required();
    OptionSpec<String> dashboard = parser
            .accepts("dashboard", "Grafana dashboard name to be used in all generated configs")
            .withRequiredArg().required();
    OptionSpec<String> dashboardPath = parser
            .accepts("dashboard-path", "Grafana location, i.e. `./instance/.data/grafana/dashboards`")
            .withRequiredArg();/*www . jav  a  2  s.co m*/
    OptionSpec<String> topic = parser.accepts("topic", "Name of the metrics topic to consume measurements from")
            .withRequiredArg();
    OptionSpec<String> influxdb = parser
            .accepts("influxdb", "InfluxDB connect URL (including user and password)").withRequiredArg();
    OptionSpec<String> interval = parser.accepts("interval", "JMX scanning interval in seconds")
            .withRequiredArg().defaultsTo("10");
    //TODO --influxdb-database (DEFAULT_DATABASE)
    //TODO --dashboard-datasource (DEFAULT_DATASOURCE)

    if (args.length == 0 || args[0] == "-h" || args[0] == "--help") {
        parser.printHelpOn(System.err);
        System.exit(0);
    }

    OptionSet opts = parser.parse(args);

    try {

        DiscoveryTool tool = new DiscoveryTool(opts.valueOf(zookeeper));

        try {
            List<String> topics = tool.getKafkaTopics();
            List<Broker> brokers = tool.getKafkaBrokers();
            int interval_s = Integer.parseInt(opts.valueOf(interval));

            if (opts.has(dashboard) && opts.has(dashboardPath)) {
                tool.generateDashboard(opts.valueOf(dashboard), brokers, topics, DEFAULT_DATASOURCE,
                        opts.valueOf(dashboardPath), interval_s).save();
            }

            if (opts.has(topic)) {
                //producer/reporter settings
                System.out.println("kafka.metrics.topic=" + opts.valueOf(topic));
                System.out.println("kafka.metrics.polling.interval=" + interval_s + "s");
                //TODO --producer-bootstrap for truly non-intrusive agent deployment,
                // i.e. when producing to a different cluster from the one being discovered
                System.out.println("kafka.metrics.bootstrap.servers=" + brokers.get(0).hostPort());
                //consumer settings
                System.out.println("consumer.topic=" + opts.valueOf(topic));
                System.out.println("consumer.zookeeper.connect=" + opts.valueOf(zookeeper));
                System.out.println("consumer.group.id=kafka-metrics-" + opts.valueOf(dashboard));
            }

            if (!opts.has(influxdb) || !opts.has(topic)) {
                tool.generateScannerConfig(brokers, opts.valueOf(dashboard), interval_s).list(System.out);
            }

            if (opts.has(influxdb)) {
                URL url = new URL(opts.valueOf(influxdb));
                System.out.println("influxdb.database=" + DEFAULT_DATABASE);
                System.out.println("influxdb.url=" + url.toString());
                if (url.getUserInfo() != null) {
                    System.out.println("influxdb.username=" + url.getUserInfo().split(":")[0]);
                    if (url.getUserInfo().contains(":")) {
                        System.out.println("influxdb.password=" + url.getUserInfo().split(":")[1]);
                    }
                }
            }

            System.out.flush();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(3);
        } finally {
            tool.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(2);
    }

}

From source file:com.sinosoft.dtphone.rule.main.testJson.java

/**
 * @param args// ww  w  . j a  va 2  s .  com
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    objectMapper = new ObjectMapper();
    String body = null;
    RuleBean test = null;
    try {
        test = getTB();
        jsonGenerator = objectMapper.getFactory().createJsonGenerator(System.out, JsonEncoding.UTF8);
        jsonGenerator.writeObject(test);
        // System.out.println();
        // objectMapper.writeValue(System.out, test);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.zimbra.cs.db.MySQL.java

public static void main(String args[]) {
    // command line argument parsing
    Options options = new Options();
    CommandLine cl = Versions.parseCmdlineArgs(args, options);

    String outputDir = cl.getOptionValue("o");
    File outFile = new File(outputDir, "versions-init.sql");
    outFile.delete();//from  ww  w. j av  a2  s.  c om

    try {
        String redoVer = com.zimbra.cs.redolog.Version.latest().toString();
        String outStr = "-- AUTO-GENERATED .SQL FILE - Generated by the MySQL versions tool\n" + "USE zimbra;\n"
                + "INSERT INTO zimbra.config(name, value, description) VALUES\n" + "\t('db.version', '"
                + Versions.DB_VERSION + "', 'db schema version'),\n" + "\t('index.version', '"
                + Versions.INDEX_VERSION + "', 'index version'),\n" + "\t('redolog.version', '" + redoVer
                + "', 'redolog version')\n" + ";\nCOMMIT;\n";

        Writer output = new BufferedWriter(new FileWriter(outFile));
        output.write(outStr);
        if (output != null)
            output.close();
    } catch (IOException e) {
        System.out.println("ERROR - caught exception at\n");
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.alvermont.terraj.planet.ui.PlanetCLI.java

/**
 * Main entrypoint for this program/*from w ww  .  jav  a  2s  .co  m*/
 *
 * @param args The command line arguments
 */
public static void main(String[] args) {
    final PlanetCLI me = new PlanetCLI();

    LongOpt[] options = me.getOptionArray();
    String shortOpts = me.getShortOptions(options);

    try {
        AllPlanetParameters params = me.processOptions(args);

        if (params != null) {
            // then the options were accepted
            ProjectionManager mgr = new ProjectionManager();

            Projector proj = mgr.findByName(params.getProjectionParameters().getProjectionName());

            if (proj == null) {
                System.err.println("Error. Unknown projection name: "
                        + params.getProjectionParameters().getProjectionName());

                System.exit(1);
            }

            final BufferedImage image = me.generateTerrain(proj, params);

            me.writeImageFile(image, params);
        } else {
            // exit - getopt has printed the error message for us
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();

        System.exit(1);
    }
}

From source file:edu.umass.cs.reconfiguration.deprecated.ReconfigurableClientCreateTester.java

/**
 * Simple test client for the reconfiguration package. Clients only know the
 * set of all reconfigurators, not active replicas for any name. All
 * information about active replicas for a name is obtained from
 * reconfigurators. Any request can be sent to any reconfigurator and it
 * will forward to the appropriate reconfigurator if necessary and relay
 * back the response./*from w w w  .  j ava2  s .co m*/
 * 
 * @param args
 */
public static void main(String[] args) {
    try {
        /*
         * Client can only send/receive clear text or do server-only
         * authentication
         */
        JSONMessenger<?> messenger = new JSONMessenger<String>((new MessageNIOTransport<String, JSONObject>(
                null, null, new PacketDemultiplexerDefault(), true, ReconfigurationConfig.getClientSSLMode())));
        final ReconfigurableClientCreateTester client = new ReconfigurableClientCreateTester(
                ReconfigurationConfig.getReconfiguratorAddresses(), messenger);
        String initValue = "initVal";
        int numIterations = 1;

        for (int j = 0; j < numIterations; j++) {
            String namePrefix = "name" + (int) (Math.random() * Integer.MAX_VALUE);
            long t0 = System.currentTimeMillis();

            // ///////////////// batched create name//////////////////////
            t0 = System.currentTimeMillis();
            // do
            int numCreates = 1;
            int batchSize = 50000;
            for (int i = 0; i < numCreates; i++) {
                final int k = i;
                try {
                    // batch size is being specified here
                    CreateServiceName[] creates = client.makeCreateNameRequest(namePrefix + k, initValue,
                            batchSize);
                    for (CreateServiceName create : creates) {
                        client.sendRequest(create);
                        System.out.println("Sent batched request of size " + create.getNameStates().size());
                        while (!client.waitForSuccess(create.getServiceName()))
                            ;
                    }
                } catch (JSONException | IOException e) {
                    e.printStackTrace();
                }
                System.out.println("SUCCESS " + k);
            }
            DelayProfiler.updateDelay("createName", t0);
            System.out.println(System.currentTimeMillis() - t0);
            System.exit(1);
        }

    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:contractEditor.contractClients.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    obj.put("name", "clientTemplate");
    obj.put("context", "VM-deployment");
    //obj.put("Context", new Integer);

    HashMap serviceRequirement = new HashMap();

    HashMap serviceDescription = new HashMap();
    serviceRequirement.put("VM1_volume", "18_GB");
    serviceDescription.put("VM1_purpose", "dev");
    serviceDescription.put("VM1_data", "private");
    serviceDescription.put("VM1_application", "internal");

    serviceRequirement.put("VM2_volume", "20_GB");
    serviceDescription.put("VM2_purpose", "prod");
    serviceDescription.put("VM2_data", "public");
    serviceDescription.put("VM2_application", "business");

    serviceRequirement.put("VM3_volume", "30_GB");
    serviceDescription.put("VM3_purpose", "test");
    serviceDescription.put("VM3_data", "public");
    serviceDescription.put("VM3_application", "business");

    serviceRequirement.put("VM4_volume", "20_GB");
    serviceDescription.put("VM4_purpose", "prod");
    serviceDescription.put("VM4_data", "public");
    serviceDescription.put("VM4_application", "business");

    obj.put("serviceRequirement", serviceRequirement);
    obj.put("serviceDescription", serviceDescription);

    HashMap gauranteeTerm = new HashMap();
    gauranteeTerm.put("VM1_availability", "more_97_percentage");
    gauranteeTerm.put("VM2_availability", "more_99_percentage");
    gauranteeTerm.put("VM3_availability", "more_95_percentage");
    gauranteeTerm.put("VM4_availability", "more_99_percentage");
    obj.put("gauranteeTerm", gauranteeTerm);

    //Constraint1

    HashMap host_rule1 = new HashMap();
    HashMap VM_rule1 = new HashMap();
    host_rule1.put("certificate", "true");
    VM_rule1.put("purpose", "dev");

    ArrayList rule1 = new ArrayList();
    rule1.add("permission");
    rule1.add(host_rule1);/*from   w w  w  .  j a v  a 2  s. c  o  m*/
    rule1.add(VM_rule1);

    HashMap host_rule1_2 = new HashMap();
    HashMap VM_rule1_2 = new HashMap();
    host_rule1_2.put("certificate", "true");
    VM_rule1_2.put("purpose", "prod");

    ArrayList rule1_2 = new ArrayList();
    rule1_2.add("permission");
    rule1_2.add(host_rule1_2);
    rule1_2.add(VM_rule1_2);

    HashMap host_rule1_3 = new HashMap();
    HashMap VM_rule1_3 = new HashMap();
    host_rule1_3.put("certificate", "true");
    VM_rule1_3.put("purpose", "test");

    ArrayList rule1_3 = new ArrayList();
    rule1_3.add("permission");
    rule1_3.add(host_rule1_3);
    rule1_3.add(VM_rule1_3);

    HashMap host_rule2 = new HashMap();
    HashMap VM_rule2 = new HashMap();
    host_rule2.put("location", "France");
    VM_rule2.put("ID", "VM2");

    ArrayList rule2 = new ArrayList();
    rule2.add("permission");
    rule2.add(host_rule2);
    rule2.add(VM_rule2);

    HashMap host_rule2_1 = new HashMap();
    HashMap VM_rule2_1 = new HashMap();
    host_rule2_1.put("location", "UK");
    VM_rule2_1.put("ID", "VM2");

    ArrayList rule2_1 = new ArrayList();
    rule2_1.add("permission");
    rule2_1.add(host_rule2_1);
    rule2_1.add(VM_rule2_1);

    HashMap host_rule3 = new HashMap();
    HashMap VM_rule3 = new HashMap();
    host_rule3.put("location", "France");
    VM_rule3.put("application", "business");

    ArrayList rule3 = new ArrayList();
    rule3.add("permission");
    rule3.add(host_rule3);
    rule3.add(VM_rule3);

    HashMap host_rule3_1 = new HashMap();
    HashMap VM_rule3_1 = new HashMap();
    host_rule3_1.put("location", "UK");
    VM_rule3_1.put("application", "business");

    ArrayList rule3_1 = new ArrayList();
    rule3_1.add("permission");
    rule3_1.add(host_rule3_1);
    rule3_1.add(VM_rule3_1);

    HashMap VMSeperation_rule_1_1 = new HashMap();
    HashMap VMSeperation_rule_1_2 = new HashMap();

    VMSeperation_rule_1_1.put("ID", "VM1");
    VMSeperation_rule_1_2.put("ID", "VM3");

    ArrayList rule4 = new ArrayList();
    rule4.add("separation");
    rule4.add(VMSeperation_rule_1_1);
    rule4.add(VMSeperation_rule_1_2);

    ArrayList policyInConstraint1 = new ArrayList();
    policyInConstraint1.add(rule1);
    policyInConstraint1.add(rule1_2);
    policyInConstraint1.add(rule1_3);

    policyInConstraint1.add(rule2);
    policyInConstraint1.add(rule2_1);

    policyInConstraint1.add(rule3);
    policyInConstraint1.add(rule3_1);

    policyInConstraint1.add(rule4);

    ArrayList creationConstraint1 = new ArrayList();
    creationConstraint1.add("RP4");
    creationConstraint1.add("true");
    creationConstraint1.add("true");
    creationConstraint1.add(policyInConstraint1);

    ArrayList totalConstraint = new ArrayList();
    totalConstraint.add(creationConstraint1);

    obj.put("creationConstraint", totalConstraint);

    try {

        FileWriter file = new FileWriter("confClient" + File.separator + "test3.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

    /*
            
    JSONParser parser = new JSONParser();
            
    try {
            
    Object obj2 = parser.parse(new FileReader("test2.json"));
            
    JSONObject jsonObject = (JSONObject) obj2;
            
        HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription");
                 
        method.printHashMap(serviceDescription2);
                
                
        HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm");
                 
        method.printHashMap(gauranteeTerm2);
                
                
                
        ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint");
                
        method.printArrayList(creationConstraint);
            
            
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ParseException e) {
    e.printStackTrace();
    }
            
            
            
            
            
    */

}

From source file:com.appeligo.responsetest.ServerResponseChecker.java

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

    PatternLayout pattern = new PatternLayout("%d{ISO8601} %-5p [%-c{1} - %t] - %m%n");
    ConsoleAppender consoleAppender = new ConsoleAppender(pattern);
    LevelRangeFilter infoFilter = new LevelRangeFilter();
    infoFilter.setLevelMin(Level.INFO);
    consoleAppender.addFilter(infoFilter);
    BasicConfigurator.configure(consoleAppender);

    String configFile = "/etc/flip.tv/responsetest.xml";

    if (args.length > 0) {
        if (args.length == 2 && args[0].equals("-config")) {
            configFile = args[1];
        } else {
            log.error("Usage: java " + ServerResponseChecker.class.getName() + " [-config <xmlfile>]");
            System.exit(1);
        }
    }

    try {
        XMLConfiguration config = new XMLConfiguration(configFile);

        logFile = config.getString("logFile", logFile);
        servlet = config.getString("servlet", servlet);
        timeoutSeconds = config.getLong("timeoutSeconds", timeoutSeconds);
        responseTimeThresholdSeconds = config.getLong("responseTimeThresholdSeconds",
                responseTimeThresholdSeconds);
        reporter = config.getString("reporter", reporter);
        smtpServer = config.getString("smtpServer", smtpServer);
        smtpUsername = config.getString("smtpUsername", smtpUsername);
        smtpPassword = config.getString("smtpPassword", smtpPassword);
        smtpDebug = config.getBoolean("smtpDebug", smtpDebug);
        mailTo = config.getString("mailTo", mailTo);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }

    marker = logFile + ".mailed";

    try {
        BasicConfigurator.configure(new RollingFileAppender(pattern, logFile, true));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Add email appender
    SMTPAppender mailme = new SMTPAppender();
    LevelRangeFilter warnFilter = new LevelRangeFilter();
    warnFilter.setLevelMin(Level.WARN);
    mailme.addFilter(warnFilter);
    mailme.setSMTPDebug(smtpDebug);
    mailme.setSMTPHost(smtpServer);
    mailme.setTo(mailTo);
    mailme.setFrom(reporter + " <" + smtpUsername + ">");
    mailme.setBufferSize(1);
    mailme.setSubject(servlet + " Not Responding!");
    mailme.setSMTPUsername(smtpUsername);
    mailme.setSMTPPassword(smtpPassword);
    mailme.setLayout(new SimpleLayout());
    mailme.activateOptions();
    mailme.setLayout(pattern);
    BasicConfigurator.configure(mailme);

    long before;
    ConnectionThread connectionThread = new ConnectionThread();
    connectionThread.start();
    synchronized (connectionThread) {
        connectionThread.setOkToGo(true);
        connectionThread.notifyAll();
        before = System.currentTimeMillis();
        long delay = timeoutSeconds * 1000;
        while (!done && delay > 0) {
            try {
                connectionThread.wait(delay);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            delay -= (System.currentTimeMillis() - before);
        }
    }
    long after = System.currentTimeMillis();
    responseMillis = after - before;
    String reportStatus = "Could not report";
    try {
        StringBuilder sb = new StringBuilder();
        sb.append(servlet + "/responsetest/report.action");
        sb.append("?reporter=" + URLEncoder.encode(reporter));
        sb.append("&status=" + URLEncoder.encode(status));
        sb.append("&bytesRead=" + bytesRead);
        sb.append("&timedOut=" + (!done));
        if (throwable == null) {
            sb.append("&exception=none");
        } else {
            sb.append("&exception="
                    + URLEncoder.encode(throwable.getClass().getName() + "-" + throwable.getMessage()));
        }
        sb.append("&responseMillis=" + responseMillis);
        URL reportURL = new URL(sb.toString());
        connection = (HttpURLConnection) reportURL.openConnection();
        connection.connect();
        reportStatus = connection.getResponseCode() + " - " + connection.getResponseMessage();
    } catch (Throwable t) {
        reportStatus = t.getClass().getName() + "-" + t.getMessage();
    }
    StringBuilder sb = new StringBuilder();
    sb.append(servlet + ": ");
    sb.append(status + ", " + bytesRead + " bytes, ");
    if (done) {
        sb.append("DONE, ");
    } else {
        sb.append("TIMED OUT, ");
    }
    sb.append(responseMillis + " millisecond response, ");
    sb.append(" report status=" + reportStatus);
    File markerFile = new File(marker);
    if (done && status.startsWith("200") && (throwable == null)) {
        if ((responseMillis / 1000) < responseTimeThresholdSeconds) {
            if (markerFile.exists()) {
                markerFile.delete();
            }
            log.debug(sb.toString());
        } else {
            if (markerFile.exists()) {
                log.info(sb.toString());
            } else {
                try {
                    new FileOutputStream(marker).close();
                    log.warn(sb.toString());
                } catch (IOException e) {
                    log.info(sb.toString());
                    log.info("Can't send email alert because could not write marker file: " + marker + ". "
                            + e.getMessage());
                }
            }
        }
    } else {
        if (throwable != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            sb.append(sw.toString());
        }
        if (markerFile.exists()) {
            log.info(sb.toString());
        } else {
            try {
                new FileOutputStream(marker).close();
                log.fatal(sb.toString()); // chosen appender layout ignoresThrowable()
            } catch (IOException e) {
                log.info(sb.toString());
                log.info("Can't send email alert because could not write marker file: " + marker + ". "
                        + e.getMessage());
            }
        }
    }
}

From source file:com.wakacommerce.common.util.PomEvaluator.java

/**
 * @param args/*  ww w  .j a  v a2  s  .com*/
 */
public static void main(String[] args) {
    initializeKnownLibraries();
    BufferedReader br = null;

    try {
        String fileName = "/Users/brianpolster/blc-workspace/BroadleafCommerce/pom.xml";
        if (args.length > 0) {
            fileName = args[0];
        }

        br = new BufferedReader(new FileReader(fileName));

        forwardToTag("<dependencies>", br);

        List<Dependency> dependencies = populateDependencies(br);

        for (Dependency dependency : dependencies) {
            Category category = knownLibraries.get(dependency.groupId);
            if (category != null) {
                category.dependencyList.add(dependency);
                List<Dependency> licenseDependencyList = licenseDependencyMap.get(category.licenseType);
                if (licenseDependencyList == null) {
                    licenseDependencyList = new ArrayList<Dependency>();
                    licenseDependencyList.add(dependency);
                    licenseDependencyMap.put(category.licenseType, licenseDependencyList);
                }

            } else {

                if (dependency.scope != null
                        && (dependency.scope.equals("test") || dependency.scope.equals("provided"))) {
                    continue;
                }
                OTHER.dependencyList.add(dependency);
            }
        }

        Set<Category> categoryList = new HashSet<Category>(knownLibraries.values());

        System.out.println("Related Software Report\r");

        for (Category category : categoryList) {
            printOutDependencies(category, category.dependencyList);
        }

        if (OTHER.dependencyList.size() > 0) {
            printOutDependencies(OTHER, OTHER.dependencyList);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)
                br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}