List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:com.sinosoft.dtphone.vehicle.findCar.main.Main.java
/** * @param args/* w w w . j a v a2s. c o m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub objectMapper = new ObjectMapper(); String body = null; Domain 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:test.node.TestUnboudedJobRunner.java
public static void main(String[] args) { // Test Job/*from ww w . j a v a2 s. co m*/ TestUnboundedJob testJob = new TestUnboundedJob(); try { log.info("GridNode Starting..."); StopWatch sw = new StopWatch(); sw.start(); GridNode node = Grid.startGridNode(); log.info("GridNode ID : " + node.getId()); sw.stop(); log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]"); // Submit Job log.debug("Submitting Job"); sw.start(); GridJobFuture future = node.getJobSubmissionService().submitJob(testJob, new ResultCallback() { public void onResult(Serializable result) { System.err.println(result); } }); while (!future.isJobFinished()) { Thread.sleep(1000); } sw.stop(); log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms"); log.debug("Press any key to unregister GridNode and terminate"); System.in.read(); node.getNodeRegistrationService().unregister(); log.info("Unregistered, Terminating..."); System.exit(0); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:RegExpExample.java
public static void main(String args[]) { String fileName = "RETestSource.java"; String unadornedClassRE = "^\\s*class (\\w+)"; String doubleIdentifierRE = "\\b(\\w+)\\s+\\1\\b"; Pattern classPattern = Pattern.compile(unadornedClassRE); Pattern doublePattern = Pattern.compile(doubleIdentifierRE); Matcher classMatcher, doubleMatcher; int lineNumber = 0; try {// w ww.j a va 2 s .c o m BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { lineNumber++; classMatcher = classPattern.matcher(line); doubleMatcher = doublePattern.matcher(line); if (classMatcher.find()) { System.out.println("The class [" + classMatcher.group(1) + "] is not public"); } while (doubleMatcher.find()) { System.out.println("The word \"" + doubleMatcher.group(1) + "\" occurs twice at position " + doubleMatcher.start() + " on line " + lineNumber); } } } catch (IOException ioe) { System.out.println("IOException: " + ioe); ioe.printStackTrace(); } }
From source file:PinotThroughput.java
@SuppressWarnings("InfiniteLoopStatement") public static void main(String[] args) throws Exception { final int numQueries = QUERIES.length; final Random random = new Random(RANDOM_SEED); final AtomicInteger counter = new AtomicInteger(0); final AtomicLong totalResponseTime = new AtomicLong(0L); final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS); for (int i = 0; i < NUM_CLIENTS; i++) { executorService.submit(new Runnable() { @Override/* w w w.j a va 2 s.c o m*/ public void run() { try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost post = new HttpPost("http://localhost:8099/query"); CloseableHttpResponse res; while (true) { String query = QUERIES[random.nextInt(numQueries)]; post.setEntity(new StringEntity("{\"pql\":\"" + query + "\"}")); long start = System.currentTimeMillis(); res = client.execute(post); res.close(); counter.getAndIncrement(); totalResponseTime.getAndAdd(System.currentTimeMillis() - start); } } catch (IOException e) { e.printStackTrace(); } } }); } long startTime = System.currentTimeMillis(); while (true) { Thread.sleep(REPORT_INTERVAL_MILLIS); double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND; int count = counter.get(); double avgResponseTime = ((double) totalResponseTime.get()) / count; System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: " + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms"); } }
From source file:Correct.java
public static void main(String[] args) { String URLL = ""; HttpClient client = new HttpClient(); HttpMethod method = new PostMethod(URLL); method.setDoAuthentication(true);//w ww . ja va 2s .c o m HostConfiguration hostConfig = client.getHostConfiguration(); hostConfig.setHost("172.29.38.8"); hostConfig.setProxy("172.29.90.4", 8); // NTCredentials proxyCredentials = new NTCredentials("", "", "", ""); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", "")); //// try { //// URL url = new URL(""); //// HttpURLConnection urls = (HttpURLConnection) url.openConnection(); //// //// //// } catch (MalformedURLException ex) { //// Logger.getLogger(Correct.class.getName()).log(Level.SEVERE, null, ex); //// } catch (IOException ex) { //// Logger.getLogger(Correct.class.getName()).log(Level.SEVERE, null, ex); //// } try { // send the transaction client.executeMethod(hostConfig, method); StatusLine status = method.getStatusLine(); if (status != null && method.getStatusCode() == 200) { System.out.println(method.getResponseBodyAsString() + "\n Status code : " + status); } else { System.err.println(method.getStatusLine() + "\n: Posting Failed !"); } } catch (IOException ioe) { ioe.printStackTrace(); } method.releaseConnection(); }
From source file:com.anteam.demo.httpclient.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://127.0.0.1:9000"); post.setEntity(stringEntity);// w w w . ja v a 2 s .c om HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:com.anteam.demo.logback.PostDemo.java
public static void main(String[] args) { StringEntity stringEntity = new StringEntity("this is the log2.", ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost("http://10.16.0.207:9000"); post.setEntity(stringEntity);/*from ww w. j av a 2s. c o m*/ HttpClient httpclient = new DefaultHttpClient(); // Execute the request HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } httpclient.getConnectionManager().shutdown(); } }
From source file:CharsetDetector.java
public static void main(String[] args) { File f = new File("example.txt"); String[] charsetsToBeTested = { "UTF-8", "windows-1253", "ISO-8859-7" }; CharsetDetector cd = new CharsetDetector(); Charset charset = cd.detectCharset(f, charsetsToBeTested); if (charset != null) { try {/*from ww w . j a va 2 s. c o m*/ InputStreamReader reader = new InputStreamReader(new FileInputStream(f), charset); int c = 0; while ((c = reader.read()) != -1) { System.out.print((char) c); } reader.close(); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } else { System.out.println("Unrecognized charset."); } }
From source file:com.reddit.RedditScraperBot.java
public static void main(String[] args) throws IOException, JSONException, InterruptedException { ApiUtil apiUtil = new ApiUtil(MINIMUM_TIME_BETWEEN_REQUESTS_IN_MS); List<String> subreddits = Arrays.asList("pics", "AskReddit", "funny"); for (String subreddit : subreddits) { System.out.println("########################################"); System.out.println("####### Begin parsing for: " + subreddit); System.out.println("########################################"); // Return 50 threads from the front page of this subreddit JSONObject redditObject = new JSONObject( apiUtil.getPage("http://www.reddit.com/r/" + subreddit + ".json?limit=50")); JSONArray children = redditObject.getJSONObject("data").getJSONArray("children"); for (int i = 0; i < children.length(); i++) { try { String threadId = children.getJSONObject(i).getJSONObject("data").getString("id"); // Request up to 500 comments for this thread JSONArray jsonArray = new JSONArray( apiUtil.getPage("http://www.reddit.com/comments/" + threadId + ".json?limit=500")); // Change 2nd argument to RETRIEVE_ALL_COMMENTS if you want to fully construct this // commentThread object. Warning: it can take some time since we respect the 3 seconds // between requests API rule and a large thread requires many requests. CommentThread commentThread = apiUtil.parseJSON(jsonArray, DO_NOT_RECURSE_COMMENT_TREE); // Do something with the comment thread object // Displaying meta data for lack of a better objective System.out.println("Author: " + commentThread.getAuthor() + ", Title: " + commentThread.getTitle() + ", Upvotes: " + commentThread.getUpvotes() + ", Downvotes: " + commentThread.getDownvotes() + ", comments retrieved: " + commentThread.getComments().size()); } catch (IOException ioException) { ioException.printStackTrace(); } catch (JSONException jsonException) { jsonException.printStackTrace(); }//from w w w . j ava 2s.co m } } apiUtil.getTimer().cancel(); }
From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.RandomListGenerator.java
/** * @param args//from w ww . ja v a 2 s . c om */ public static void main(String[] args) { System.out.println("Have started list generator."); File outFile = new File("/tmp/randomList.txt"); RandomDataGenerator generator = new RandomDataGenerator(); int listSize = 503; // The size of the array / list to be generated // The Strings to be randomized String[] strings = { "0DE968C9-7309-C481-58F7-AB6CDB1011EF", "5C1D9939-136A-55DE-FD0E-61D8204E17C9", "B936DA83-8A45-E9F0-2EAE-D75F5C232E78" }; try { for (int j = 0; j < listSize; j++) { FileUtils.write(outFile, strings[generator.nextInt(0, strings.length - 1)] + "\n", true); // Append to file } } catch (IOException e) { System.err.println("IOException in main."); e.printStackTrace(); } System.out.println("Have finished list generator."); }