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:NTP_Example.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("Usage: NTPClient <hostname-or-address-list>");
        System.exit(1);/*from w  w w .  j a va 2  s.c o  m*/
    }

    NTPUDPClient client = new NTPUDPClient();
    // We want to timeout if a response takes longer than 10 seconds
    client.setDefaultTimeout(10000);
    try {
        client.open();
        for (String arg : args) {
            System.out.println();
            try {
                InetAddress hostAddr = InetAddress.getByName(arg);
                System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress());
                TimeInfo info = client.getTime(hostAddr);
                processResponse(info);
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }

    client.close();
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.CorpusTfidf.java

public static void main(String[] args) {
    PROPERTIES = BaseProperties.setInstance(args, "sample/test.properties");

    String input = PROPERTIES.getProperty("input", "sample/test-check.json");

    TermCorpusBuilder cb = new TermCorpusBuilder();
    cb.setJson(input);/* www .  j  a v  a 2s  .  co m*/

    System.out.println("Building corpus.");
    TermCorpus c = cb.build();
    System.out.println(c.size());

    System.out.println("Generating terms.");
    c.genTerms();
    System.out.println("Generating idfs.");
    c.genIdfs();
    System.out.println(c.numTerms());
    System.out.println("Terms generated.");

    ObjectNode tfidfs = getCorpusTfidfs(c);

    String output = PROPERTIES.getProperty("output", "sample/test-tfidf-output.json");
    try (BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(output), "UTF-8"))) {
        bw.write(tfidfs.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.bbn.c2s2.pint.testdata.chart.ScatterPlot.java

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

    double[][] testData = populateData(50);
    ScatterPlot demo = new ScatterPlot("Fast Scatter Plot Demo", "X Label", "Y Label", testData);
    try {
        demo.toJpgFile("test-plot.jpg", 1000, 800);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    demo.toScreen();

}

From source file:com.waku.mmdataextract.ComprehensiveSearch.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    FileWriter fw = null;/*www  .  ja v  a2  s  . c  o m*/
    try {
        fw = new FileWriter(new File("output/ComprehensiveSearch.csv"));
        fw.write(
                ",??,?,?,,?,??,,?,1,2,3,\n");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Document firstPage = MyHttpClient.getAsDom4jDoc(START_ACTION);
    // System.out.println(doc.asXML());
    List<Element> brandOptions = firstPage.selectNodes("//select[@name='brandId']/option");
    for (Element brandOption : brandOptions) {
        String brandId = brandOption.attributeValue("value");
        if (!brandId.equalsIgnoreCase("0")) {
            for (int i = 1; true; i++) {
                logger.info("Get brandId/page -> " + brandId + "/" + i);
                if (searchDone(fw, brandId, i)) {
                    break;
                }
            }
        }
    }
    try {
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    logger.info("----> Done!");

    logger.info("----> Start to compare production search ... ");
    CompareProductions.start(prodIdList, 0);
}

From source file:com.kantenkugel.discordbot.Main.java

public static void main(String[] args) {
    boolean isDbBot = false;
    if (args.length == 2 && Boolean.parseBoolean(args[1])) {
        isDbBot = true;/*w ww.  j  a va 2  s .com*/
    } else if (args.length < 4) {
        System.out.println("Missing arguments!");
        return;
    }

    if (!BotConfig.load()) {
        System.out.println("Bot config created/updated. Please populate/check it before restarting the Bot");
        System.exit(Statics.NORMAL_EXIT_CODE);
    }

    if (BotConfig.get("logToFiles", true)) {
        try {
            SimpleLog.addFileLogs(new File("logs/main.txt"), new File("logs/err.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!isDbBot) {
        Statics.START_TIME = Long.parseLong(args[1]);
        Statics.VERSION = Integer.parseInt(args[3]);
    }

    if (!isDbBot && args.length > 4) {
        Statics.CHANGES = StringUtils.join(args, '\n', 4, args.length);
    } else {
        Statics.CHANGES = null;
    }

    if (isDbBot) {
        if ("".equals(BotConfig.get("historyBase"))) {
            Statics.LOG.fatal("Please specify a history-base in the config");
            System.exit(Statics.NORMAL_EXIT_CODE);
        }
        if (!DbEngine.init()) {
            Statics.LOG.fatal("Could not connect to db! shutting down");
            System.exit(Statics.NORMAL_EXIT_CODE);
        }
    } else {
        DocParser.init();
        Module.init();
    }
    try {
        JDABuilder jdaBuilder = new JDABuilder().setBotToken(args[0]).setAudioEnabled(false);
        if (isDbBot)
            jdaBuilder.addListener(new DbListener());
        else
            jdaBuilder.addListener(new StatusListener()).addListener(new InviteListener())
                    .addListener(new MessageListener());
        if (!isDbBot && !args[2].equals("-")) {
            boolean success = Boolean.parseBoolean(args[2]);
            if (success) {
                checker = UpdateValidator.getInstance();
                checker.start();
            }
            jdaBuilder.addListener(new UpdatePrintListener(success));
        }
        Statics.jdaInstance = jdaBuilder.buildAsync();
        if (!isDbBot)
            CommandRegistry.loadCommands(Statics.jdaInstance);
        new UpdateWatcher(Statics.jdaInstance);
    } catch (LoginException e) {
        Statics.LOG.fatal("Login informations were incorrect!");
        System.err.flush();
    }
}

From source file:edu.internet2.middleware.psp.names.CreateLdapNames.java

/**
 * @param args//from   www.  j  a  va2 s . co  m
 */

public static void main(String[] args) {

    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter("/tmp/people.ldif"));

        RandomCollection<String> givenNames = readGivenNames();

        RandomCollection<String> surnames = readSurnames();

        for (int i = 0; i < 1000; i++) {
            String surname = surnames.next();
            String givenName = givenNames.next();
            String ldif = getLdif(i, givenName, surname);
            // System.out.println(ldif);
            writer.write(ldif);
            writer.write("\n");
        }

        writer.close();

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

From source file:URLConnectionTest.java

public static void main(String[] args) {
    try {/*from w ww .  j a  va  2 s .c  om*/
        String urlName;
        if (args.length > 0)
            urlName = args[0];
        else
            urlName = "http://java.sun.com";

        URL url = new URL(urlName);
        URLConnection connection = url.openConnection();

        // set username, password if specified on command line

        if (args.length > 2) {
            String username = args[1];
            String password = args[2];
            String input = username + ":" + password;
            String encoding = base64Encode(input);
            connection.setRequestProperty("Authorization", "Basic " + encoding);
        }

        connection.connect();

        // print header fields

        Map<String, List<String>> headers = connection.getHeaderFields();
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            String key = entry.getKey();
            for (String value : entry.getValue())
                System.out.println(key + ": " + value);
        }

        // print convenience functions

        System.out.println("----------");
        System.out.println("getContentType: " + connection.getContentType());
        System.out.println("getContentLength: " + connection.getContentLength());
        System.out.println("getContentEncoding: " + connection.getContentEncoding());
        System.out.println("getDate: " + connection.getDate());
        System.out.println("getExpiration: " + connection.getExpiration());
        System.out.println("getLastModifed: " + connection.getLastModified());
        System.out.println("----------");

        Scanner in = new Scanner(connection.getInputStream());

        // print first ten lines of contents

        for (int n = 1; in.hasNextLine() && n <= 10; n++)
            System.out.println(in.nextLine());
        if (in.hasNextLine())
            System.out.println(". . .");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:monitor.java

public static void main(String argv[]) {
    if (argv.length != 5) {
        System.out.println("Usage: monitor <host> <user> <password> <mbox> <freq>");
        System.exit(1);/*from w w  w . ja v a  2 s  .c  o  m*/
    }
    System.out.println("\nTesting monitor\n");

    try {
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        // session.setDebug(true);

        // Get a Store object
        Store store = session.getStore("imap");

        // Connect
        store.connect(argv[0], argv[1], argv[2]);

        // Open a Folder
        Folder folder = store.getFolder(argv[3]);
        if (folder == null || !folder.exists()) {
            System.out.println("Invalid folder");
            System.exit(1);
        }

        folder.open(Folder.READ_WRITE);

        // Add messageCountListener to listen for new messages
        folder.addMessageCountListener(new MessageCountAdapter() {
            public void messagesAdded(MessageCountEvent ev) {
                Message[] msgs = ev.getMessages();
                System.out.println("Got " + msgs.length + " new messages");

                // Just dump out the new messages
                for (int i = 0; i < msgs.length; i++) {
                    try {
                        System.out.println("-----");
                        System.out.println("Message " + msgs[i].getMessageNumber() + ":");
                        msgs[i].writeTo(System.out);
                    } catch (IOException ioex) {
                        ioex.printStackTrace();
                    } catch (MessagingException mex) {
                        mex.printStackTrace();
                    }
                }
            }
        });

        // Check mail once in "freq" MILLIseconds
        int freq = Integer.parseInt(argv[4]);
        boolean supportsIdle = false;
        try {
            if (folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder) folder;
                f.idle();
                supportsIdle = true;
            }
        } catch (FolderClosedException fex) {
            throw fex;
        } catch (MessagingException mex) {
            supportsIdle = false;
        }
        for (;;) {
            if (supportsIdle && folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder) folder;
                f.idle();
                System.out.println("IDLE done");
            } else {
                Thread.sleep(freq); // sleep for freq milliseconds

                // This is to force the IMAP server to send us
                // EXISTS notifications. 
                folder.getMessageCount();
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:PagedSearch.java

public static void main(String[] args) {

    Hashtable<String, Object> env = new Hashtable<String, Object>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

    /* Specify host and port to use for directory service */
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial");

    try {//from   www. j a v  a  2  s . c  o  m
        LdapContext ctx = new InitialLdapContext(env, null);

        // Activate paged results
        int pageSize = 5;
        byte[] cookie = null;
        ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) });
        int total;

        do {
            /* perform the search */
            NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls());

            /* for each entry print out name + all attrs and values */
            while (results != null && results.hasMore()) {
                SearchResult entry = (SearchResult) results.next();
                System.out.println(entry.getName());
            }

            // Examine the paged results control response
            Control[] controls = ctx.getResponseControls();
            if (controls != null) {
                for (int i = 0; i < controls.length; i++) {
                    if (controls[i] instanceof PagedResultsResponseControl) {
                        PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
                        total = prrc.getResultSize();
                        if (total != 0) {
                            System.out.println("(total : " + total);
                        } else {
                            System.out.println("(total: unknown)");
                        }
                        cookie = prrc.getCookie();
                    }
                }
            } else {
                System.out.println("No controls were sent from the server");
            }
            ctx.setRequestControls(
                    new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });

        } while (cookie != null);

        ctx.close();

    } catch (NamingException e) {
        System.err.println("PagedSearch failed.");
        e.printStackTrace();
    } catch (IOException ie) {
        System.err.println("PagedSearch failed.");
        ie.printStackTrace();
    }
}

From source file:edu.lternet.pasta.common.HTMLUtility.java

public static void main(String[] args) {

    File badIn = new File("/Users/servilla/tmp/bad.txt");
    File goodOut = new File("/Users/servilla/tmp/good.txt");

    String bad = null;//ww  w .  jav  a2 s . c o m

    try {
        bad = FileUtils.readFileToString(badIn, "UTF-8");
    } catch (IOException e) {
        System.err.println("HTMLUtility: " + e.getMessage());
        e.printStackTrace();
    }

    String good = stripNonValidHTMLCharacters(bad);

    try {
        FileUtils.writeStringToFile(goodOut, good, "UTF-8");
    } catch (IOException e) {
        System.err.println("HTMLUtility: " + e.getMessage());
        e.printStackTrace();
    }

}