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:com.game.ui.views.MapEditor.java

public static void main(String[] args) throws Exception {
    GameBean.doInit();/*from w  ww .  ja v  a2 s  .  c o  m*/
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                new MapEditor();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
}

From source file:com.cloudera.util.StatusHttpServer.java

/**
 * Test harness to get precompiled jsps working.
 * /*from   ww w. j a v a 2 s .co  m*/
 * @param argv
 */
public static void main(String[] argv) {
    Preconditions.checkArgument(argv.length == 3);
    String name = argv[0];
    String path = argv[1];
    int port = Integer.parseInt(argv[2]);

    try {
        StatusHttpServer http = new StatusHttpServer(name, path, "0.0.0.0", port, false);
        http.start();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:PlyBounder.java

public static void main(String[] args) {

    // Get the commandline arguments
    Options options = new Options();
    // Available options
    Option plyPath = OptionBuilder.withArgName("dir").hasArg()
            .withDescription("directory containing input .ply files").create("plyPath");
    Option boundingbox = OptionBuilder.withArgName("string").hasArg()
            .withDescription("bounding box in WKT notation").create("boundingbox");
    Option outputPlyFile = OptionBuilder.withArgName("file").hasArg().withDescription("output PLY file name")
            .create("outputPlyFile");
    options.addOption(plyPath);//ww w .j  a v  a 2s . c om
    options.addOption(boundingbox);
    options.addOption(outputPlyFile);

    String plydir = ".";
    String boundingboxstr = "";
    String outputfilename = "";

    CommandLineParser parser = new DefaultParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        boundingboxstr = line.getOptionValue("boundingbox");
        outputfilename = line.getOptionValue("outputPlyFile");

        if (line.hasOption("plyPath")) {
            // print the value of block-size
            plydir = line.getOptionValue("plyPath");
            System.out.println("Using plyPath=" + plydir);
        } else {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("PlyBounder", options);
        }
        //System.out.println( "plyPath=" + line.getOptionValue( "plyPath" ) );
    } catch (ParseException exp) {
        System.err.println("Error getting arguments: " + exp.getMessage());
    }

    // input directory
    // Get list of files
    File dir = new File(plydir);

    //System.out.println("Getting all files in " + dir.getCanonicalPath());
    List<File> files = (List<File>) FileUtils.listFiles(dir, new String[] { "ply", "PLY" }, false);
    for (File file : files) {
        try {
            System.out.println("file=" + file.getCanonicalPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    String sometempfile = "magweg.wkt";
    String s = null;

    // Loop through .ply files in directory
    for (File file : files) {
        try {
            String cmdl[] = { "./ply-tool.py", "intersection", file.getCanonicalPath(), boundingboxstr,
                    sometempfile };
            //System.out.println("Running: " + Arrays.toString(cmdl));
            Process p = Runtime.getRuntime().exec(cmdl);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("cmdout:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("cmderr:\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Write new .ply file
    //ply-tool write setfile outputPlyFile
    try {
        String cmdl = "./ply-tool.py write " + sometempfile + " " + outputfilename;
        System.out.println("Running: " + cmdl);
        Process p = Runtime.getRuntime().exec(cmdl);

        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

        // read the output from the command
        System.out.println("cmdout:\n");
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        // read any errors from the attempted command
        System.out.println("cmderr:\n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Done
    System.out.println("Done");
}

From source file:edu.xiyou.fruits.WebCrawler.fetcher.Fetcher.java

public static void main(String[] args) {
    Scheduler scheduler1 = new BloomScheduler();
    scheduler1.putTasks(Arrays.asList("http://www.importnew.com/all-posts", "http://blog.csdn.net/"));
    Fetcher fetcher = new Fetcher(scheduler1, new Handler() {
        @Override//from w  w w.j  av a2  s.  c  o  m
        public void onSuccess(Response response) {
            //                System.out.println(((Html) response).getUrl() + response.getStatusLine());
            //                System.out.println(new String(((Html)response).getContent()));
            String path = "/home/andrew/Data/";
            String fileName = path + System.currentTimeMillis();
            try {
                FileUtils.write2File(new File(fileName), ((Html) response).getContent());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFail(Response response) {

        }

        @Override
        public List<String> handleAndGetLinks(Response response) {
            LinksList list = new LinksList();
            RegexRule regexRule = new RegexRule();
            regexRule.addPositive(Arrays.asList("http://blog.csdn.net/\\w+/article/details/\\d+",
                    "http://www.importnew.com/\\d+.html", "http://blog.csdn.net/?&page=\\d+"));
            list.getLinkByA(Jsoup.parse(new String(response.getContent())), regexRule);
            return list;
        }
    }, 0);

    //        try {
    //            System.out.println(scheduler1.takeTasks());
    //        } catch (InterruptedException e) {
    //            logger.error(e.getMessage() + "bbbbbbbbbbbbbb");
    //        }
    fetcher.fetch();
}

From source file:com.xiangzhurui.util.email.POP3Mail.java

public static void main(String[] args) {
    if (args.length < 3) {
        System.err/*from   w  w  w .  j a  v  a 2  s.c o  m*/
                .println("Usage: POP3Mail <pop3 server hostname> <username> <password> [TLS [true=implicit]]");
        System.exit(1);
    }

    String server = args[0];
    String username = args[1];
    String password = args[2];

    String proto = args.length > 3 ? args[3] : null;
    boolean implicit = args.length > 4 && Boolean.parseBoolean(args[4]);

    POP3Client pop3;

    if (proto != null) {
        System.out.println("Using secure protocol: " + proto);
        pop3 = new POP3SClient(proto, implicit);
    } else {
        pop3 = new POP3Client();
    }
    System.out.println("Connecting to server " + server + " on " + pop3.getDefaultPort());

    // We want to timeout if a response takes longer than 60 seconds
    pop3.setDefaultTimeout(60000);

    // suppress login details
    pop3.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));

    try {
        pop3.connect(server);
    } catch (IOException e) {
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    try {
        if (!pop3.login(username, password)) {
            System.err.println("Could not login to server.  Check password.");
            pop3.disconnect();
            System.exit(1);
        }

        POP3MessageInfo[] messages = pop3.listMessages();

        if (messages == null) {
            System.err.println("Could not retrieve message list.");
            pop3.disconnect();
            return;
        } else if (messages.length == 0) {
            System.out.println("No messages");
            pop3.logout();
            pop3.disconnect();
            return;
        }

        for (POP3MessageInfo msginfo : messages) {
            BufferedReader reader = (BufferedReader) pop3.retrieveMessageTop(msginfo.number, 0);

            if (reader == null) {
                System.err.println("Could not retrieve message header.");
                pop3.disconnect();
                System.exit(1);
            }
            printMessageInfo(reader, msginfo.number);
        }

        pop3.logout();
        pop3.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}

From source file:examples.mail.POP3Mail.java

public static void main(String[] args) {
    if (args.length < 3) {
        System.err/*from w  w  w. j a v a 2s  .  c  o  m*/
                .println("Usage: POP3Mail <pop3 server hostname> <username> <password> [TLS [true=implicit]]");
        System.exit(1);
    }

    String server = args[0];
    String username = args[1];
    String password = args[2];

    String proto = args.length > 3 ? args[3] : null;
    boolean implicit = args.length > 4 ? Boolean.parseBoolean(args[4]) : false;

    POP3Client pop3;

    if (proto != null) {
        System.out.println("Using secure protocol: " + proto);
        pop3 = new POP3SClient(proto, implicit);
    } else {
        pop3 = new POP3Client();
    }
    System.out.println("Connecting to server " + server + " on " + pop3.getDefaultPort());

    // We want to timeout if a response takes longer than 60 seconds
    pop3.setDefaultTimeout(60000);

    // suppress login details
    pop3.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));

    try {
        pop3.connect(server);
    } catch (IOException e) {
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    try {
        if (!pop3.login(username, password)) {
            System.err.println("Could not login to server.  Check password.");
            pop3.disconnect();
            System.exit(1);
        }

        POP3MessageInfo[] messages = pop3.listMessages();

        if (messages == null) {
            System.err.println("Could not retrieve message list.");
            pop3.disconnect();
            return;
        } else if (messages.length == 0) {
            System.out.println("No messages");
            pop3.logout();
            pop3.disconnect();
            return;
        }

        for (POP3MessageInfo msginfo : messages) {
            BufferedReader reader = (BufferedReader) pop3.retrieveMessageTop(msginfo.number, 0);

            if (reader == null) {
                System.err.println("Could not retrieve message header.");
                pop3.disconnect();
                System.exit(1);
            }
            printMessageInfo(reader, msginfo.number);
        }

        pop3.logout();
        pop3.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.lternet.pasta.client.EmlUtility.java

/**
 * @param args   String array with three arguments:
 *   arg[0] absolute path to the input XML file
 *   arg[1] absolute path to the output HTML file
 *   arg[2] absolute path to the EML XSLT stylesheet
 *//*from   w w w . j a va 2s . c  o  m*/
public static void main(String[] args) {

    String inputPath = args[0];
    String outputPath = args[1];
    String emlXslPath = args[2];
    ConfigurationListener.configure();

    File inFile = new File(inputPath);
    File outFile = new File(outputPath);
    String eml = null;

    try {
        eml = FileUtils.readFileToString(inFile);
    } catch (IOException e1) {
        logger.error(e1.getMessage());
        e1.printStackTrace();
    }

    EmlUtility eu = null;

    try {
        eu = new EmlUtility(eml);
    } catch (ParseException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

    String html = eu.xmlToHtml(emlXslPath, null);

    try {
        FileUtils.writeStringToFile(outFile, html);
    } catch (IOException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

}

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

/**
 * @param args//from  w  w w  .  j  a  va2  s  .  c  om
 */
public static void main(String[] args) {
    objectMapper = new ObjectMapper();
    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) {
        e.printStackTrace();
    }
}

From source file:ab.demo.MainEntry.java

public static void main(String args[]) {

    LoggingHandler.initConsoleLog();/* ww  w.  j av  a  2  s. c  o m*/

    //args = new String[]{"-su"};
    Options options = new Options();
    options.addOption("s", "standalone", false, "runs the reinforcement learning agent in standalone mode");
    options.addOption("p", "proxyPort", true, "the port which is to be used by the proxy");
    options.addOption("h", "help", false, "displays this help");
    options.addOption("n", "naiveAgent", false, "runs the naive agent in standalone mode");
    options.addOption("c", "competition", false, "runs the naive agent in the server/client competition mode");
    options.addOption("u", "updateDatabaseTables", false, "executes CREATE TABLE IF NOT EXIST commands");
    options.addOption("l", "level", true, "if set the agent is playing only in this one level");
    options.addOption("m", "manual", false,
            "runs the empirical threshold determination agent in standalone mode");
    options.addOption("r", "real", false, "shows the recognized shapes in a new frame");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    StandaloneAgent agent;

    Properties properties = new Properties();
    InputStream configInputStream = null;

    try {
        Class.forName("org.sqlite.JDBC");
        //parse configuration file
        configInputStream = new FileInputStream("config.properties");

        properties.load(configInputStream);

    } catch (IOException exception) {
        exception.printStackTrace();
    } catch (ClassNotFoundException exception) {
        exception.printStackTrace();
    } finally {
        if (configInputStream != null) {
            try {
                configInputStream.close();
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
    }

    String dbPath = properties.getProperty("db_path");
    String dbUser = properties.getProperty("db_user");
    String dbPass = properties.getProperty("db_pass");
    DBI dbi = new DBI(dbPath, dbUser, dbPass);

    QValuesDAO qValuesDAO = dbi.open(QValuesDAO.class);
    GamesDAO gamesDAO = dbi.open(GamesDAO.class);
    MovesDAO movesDAO = dbi.open(MovesDAO.class);
    ProblemStatesDAO problemStatesDAO = dbi.open(ProblemStatesDAO.class);

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("help", options);
            return;
        }

        int proxyPort = 9000;
        if (cmd.hasOption("proxyPort")) {
            proxyPort = Integer.parseInt(cmd.getOptionValue("proxyPort"));
            logger.info("Set proxy port to " + proxyPort);
        }
        Proxy.setPort(proxyPort);

        LoggingHandler.initFileLog();

        if (cmd.hasOption("standalone")) {
            agent = new ReinforcementLearningAgent(gamesDAO, movesDAO, problemStatesDAO, qValuesDAO);
        } else if (cmd.hasOption("naiveAgent")) {
            agent = new NaiveStandaloneAgent();
        } else if (cmd.hasOption("manual")) {
            agent = new ManualGamePlayAgent(gamesDAO, movesDAO, problemStatesDAO);
        } else if (cmd.hasOption("competition")) {
            System.out.println("We haven't implemented a competition ready agent yet.");
            return;
        } else {
            System.out.println("Please specify which solving strategy we should be using.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("help", options);
            return;
        }

        if (cmd.hasOption("updateDatabaseTables")) {
            qValuesDAO.createTable();
            gamesDAO.createTable();
            movesDAO.createTable();
            problemStatesDAO.createTable();
            problemStatesDAO.createObjectsTable();
        }

        if (cmd.hasOption("level")) {
            agent.setFixedLevel(Integer.parseInt(cmd.getOptionValue("level")));
        }

        if (cmd.hasOption("real")) {
            ShowSeg.useRealshape = true;
            Thread thread = new Thread(new ShowSeg());
            thread.start();
        }

    } catch (UnrecognizedOptionException e) {
        System.out.println("Unrecognized commandline option: " + e.getOption());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        return;
    } catch (ParseException e) {
        System.out.println(
                "There was an error while parsing your command line input. Did you rechecked your syntax before running?");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        return;
    }

    agent.run();
}

From source file:com.nidhinova.tools.ssh.SFTPClient.java

public static void main(String[] args) {
    SFTPClient client = null;/*from w w w.  j  a  va 2 s .  c o  m*/
    try {
        client = new SFTPClient("my.secureserver.com", "foo", "bar", "", new File("./.ssh/keyfile"));
        client.connect();

        client.deleteRemoteFolder("/parentfoldername", "relativepath/delete/thisfolder");

        client.disconnect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SftpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            if (client != null)
                client.disconnect();
        } catch (Exception e) {

        }
    }

}