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:examples.ntp.TimeClient.java

public static void main(String[] args) {

    if (args.length == 1) {
        try {/*from   w  w w.  j  av a2s. c o m*/
            timeTCP(args[0]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else if (args.length == 2 && args[0].equals("-udp")) {
        try {
            timeUDP(args[1]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        System.err.println("Usage: TimeClient [-udp] <hostname>");
        System.exit(1);
    }

}

From source file:ThreadedEchoServer.java

public static void main(String[] args) {
    try {// w  ww.  j  av  a 2  s  .  c  o  m
        int i = 1;
        ServerSocket s = new ServerSocket(8189);

        while (true) {
            Socket incoming = s.accept();
            System.out.println("Spawning " + i);
            Runnable r = new ThreadedEchoHandler(incoming);
            Thread t = new Thread(r);
            t.start();
            i++;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.blogspot.devsk.l2j.geoconv.GeoGonv.java

public static void main(String[] args) {

    if (args == null || args.length == 0) {
        System.out.println("File name was not specified, [\\d]{1,2}_[\\d]{1,2}.txt will be used");
        args = new String[] { "[\\d]{1,2}_[\\d]{1,2}.txt" };
    }//  ww w . ja  v  a  2 s  .  co m

    File dir = new File(".");
    File[] files = dir.listFiles((FileFilter) new RegexFileFilter(args[0]));

    ArrayList<File> checked = new ArrayList<File>();
    for (File file : files) {
        if (file.isDirectory() || file.isHidden() || !file.exists()) {
            System.out.println(file.getAbsoluteFile() + " was ignored.");
        } else {
            checked.add(file);
        }
    }

    if (OUT_DIR.exists() && OUT_DIR.isDirectory() && OUT_DIR.listFiles().length > 0) {
        try {
            System.out.println("Directory with generated files allready exists, making backup...");
            FileUtils.moveDirectory(OUT_DIR, new File("generated-backup-" + System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!OUT_DIR.exists()) {
        OUT_DIR.mkdir();
    }

    for (File file : checked) {
        GeoConvThreadFactory.startThread(new ParseTask(file));
    }
}

From source file:edu.harvard.mcz.imagecapture.BarcodeReadTest.java

/**
 * Launches the application, checking one image file for a barcode.
 * //w  w w. j  a  va2s  .  co m
 * @param args takes filename to read as the first argument.
 */
public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println("java BarcodeReadTest filename");
    } else {
        String filename = args[0];
        File file = new File(filename);
        try {
            log.debug(file.getCanonicalPath());
            BufferedImage image = ImageIO.read(file);
            System.out.println(checkForBarcode(image));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.apache.streams.facebook.example.FacebookHistoryElasticsearch.java

public static void main(String[] args) {
    LOGGER.info(StreamsConfigurator.config.toString());

    Config facebook = StreamsConfigurator.config.getConfig("facebook");
    Config elasticsearch = StreamsConfigurator.config.getConfig("elasticsearch");

    FacebookUserInformationConfiguration facebookUserInformationConfiguration;
    try {/*from   w w  w.ja  v a  2s.  com*/
        facebookUserInformationConfiguration = MAPPER.readValue(
                facebook.root().render(ConfigRenderOptions.concise()),
                FacebookUserInformationConfiguration.class);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    FacebookUserInformationProvider provider = new FacebookUserInformationProvider(
            facebookUserInformationConfiguration, String.class);

    ElasticsearchWriterConfiguration elasticsearchWriterConfiguration = ElasticsearchConfigurator
            .detectWriterConfiguration(elasticsearch);

    ElasticsearchPersistWriter writer = new ElasticsearchPersistWriter(elasticsearchWriterConfiguration);

    StreamBuilder builder = new LocalStreamBuilder();

    builder.newReadCurrentStream("provider", provider);
    builder.addStreamsPersistWriter("writer", writer, 1, "provider");
    builder.start();

}

From source file:org.apache.streams.facebook.example.FacebookUserstreamElasticsearch.java

public static void main(String[] args) {
    LOGGER.info(StreamsConfigurator.config.toString());

    Config facebook = StreamsConfigurator.config.getConfig("facebook");
    Config elasticsearch = StreamsConfigurator.config.getConfig("elasticsearch");

    FacebookUserstreamConfiguration facebookUserstreamConfiguration;
    try {//from  w ww  .  j  a  v a2 s  .  c  o  m
        facebookUserstreamConfiguration = MAPPER.readValue(
                facebook.root().render(ConfigRenderOptions.concise()), FacebookUserstreamConfiguration.class);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    FacebookUserstreamProvider provider = new FacebookUserstreamProvider(facebookUserstreamConfiguration,
            ObjectNode.class);
    FacebookTypeConverter converter = new FacebookTypeConverter(ObjectNode.class, Activity.class);
    ElasticsearchWriterConfiguration elasticsearchWriterConfiguration = ElasticsearchConfigurator
            .detectWriterConfiguration(elasticsearch);
    ElasticsearchPersistWriter writer = new ElasticsearchPersistWriter(elasticsearchWriterConfiguration);

    StreamBuilder builder = new LocalStreamBuilder();

    builder.newPerpetualStream(FacebookUserstreamProvider.STREAMS_ID, provider);
    builder.addStreamsProcessor("converter", converter, 2, FacebookUserstreamProvider.STREAMS_ID);
    builder.addStreamsPersistWriter(ElasticsearchPersistWriter.STREAMS_ID, writer, 1, "converter");
    builder.start();

}

From source file:com.javaquery.apache.httpclient.HttpPutExample.java

public static void main(String[] args) {
    /* Create object of CloseableHttpClient */
    CloseableHttpClient httpClient = HttpClients.createDefault();

    /* Prepare put request */
    HttpPut httpPut = new HttpPut("http://www.example.com/api/customer");
    /* Add headers to get request */
    httpPut.addHeader("Authorization", "value");

    /* Prepare StringEntity from JSON */
    StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8");
    /* Body of request */
    httpPut.setEntity(jsonData);//from   w  w w  .ja va 2 s.c o m

    /* Response handler for after request execution */
    ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

        @Override
        public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
            /* Get status code */
            int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
            System.out.println("Response code: " + httpResponseCode);
            if (httpResponseCode >= 200 && httpResponseCode < 300) {
                /* Convert response to String */
                HttpEntity entity = httpResponse.getEntity();
                return entity != null ? EntityUtils.toString(entity) : null;
            } else {
                return null;
                /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
            }
        }
    };

    try {
        /* Execute URL and attach after execution response handler */
        String strResponse = httpClient.execute(httpPut, responseHandler);
        /* Print the response */
        System.out.println("Response: " + strResponse);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:beans.TimeClient.java

public static void main(String[] args) {
    args = new String[] { "pool.ntp.org" };

    if (args.length == 1) {
        try {//from   ww  w.jav a 2  s. c  om
            timeTCP(args[0]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else if (args.length == 2 && args[0].equals("-udp")) {
        try {
            timeUDP(args[1]);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        System.err.println("Usage: TimeClient [-udp] <hostname>");
        System.exit(1);
    }

}

From source file:org.apache.streams.facebook.example.FacebookFriendUpdatesElasticsearch.java

public static void main(String[] args) {
    LOGGER.info(StreamsConfigurator.config.toString());

    Config facebook = StreamsConfigurator.config.getConfig("facebook");
    Config elasticsearch = StreamsConfigurator.config.getConfig("elasticsearch");

    FacebookUserstreamConfiguration facebookUserstreamConfiguration;
    try {/*from   ww w.  ja v a  2 s.  c om*/
        facebookUserstreamConfiguration = MAPPER.readValue(
                facebook.root().render(ConfigRenderOptions.concise()), FacebookUserstreamConfiguration.class);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    FacebookFriendUpdatesProvider provider = new FacebookFriendUpdatesProvider(facebookUserstreamConfiguration,
            ObjectNode.class);
    FacebookTypeConverter converter = new FacebookTypeConverter(ObjectNode.class, Activity.class);
    ElasticsearchWriterConfiguration elasticsearchWriterConfiguration = ElasticsearchConfigurator
            .detectWriterConfiguration(elasticsearch);
    ElasticsearchPersistWriter writer = new ElasticsearchPersistWriter(elasticsearchWriterConfiguration);

    StreamBuilder builder = new LocalStreamBuilder();

    builder.newPerpetualStream(FacebookUserstreamProvider.STREAMS_ID, provider);
    builder.addStreamsProcessor("converter", converter, 2, FacebookUserstreamProvider.STREAMS_ID);
    builder.addStreamsPersistWriter("console", writer, 1, "converter");
    builder.start();

}

From source file:com.javaquery.apache.httpclient.HttpPostExample.java

public static void main(String[] args) throws UnsupportedEncodingException {
    /* Create object of CloseableHttpClient */
    CloseableHttpClient httpClient = HttpClients.createDefault();

    /* Prepare POST request */
    HttpPost httpPost = new HttpPost("http://www.example.com/api/customer");
    /* Add headers to POST request */
    httpPost.addHeader("Authorization", "value");
    httpPost.addHeader("Content-Type", "application/json");

    /* Prepare StringEntity from JSON */
    StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8");
    /* Body of request */
    httpPost.setEntity(jsonData);/*from  w w w. j  a  v  a2s .com*/

    /* Response handler for after request execution */
    ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

        @Override
        public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
            /* Get status code */
            int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
            System.out.println("Response code: " + httpResponseCode);
            if (httpResponseCode >= 200 && httpResponseCode < 300) {
                /* Convert response to String */
                HttpEntity entity = httpResponse.getEntity();
                return entity != null ? EntityUtils.toString(entity) : null;
            } else {
                return null;
                /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
            }
        }
    };

    try {
        /* Execute URL and attach after execution response handler */
        String strResponse = httpClient.execute(httpPost, responseHandler);
        /* Print the response */
        System.out.println("Response: " + strResponse);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}