List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:PipedBytes.java
public static void main(String[] args) { try {/*from www . ja v a 2s . com*/ final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out); Runnable runA = new Runnable() { public void run() { writeStuff(out); } }; Thread threadA = new Thread(runA, "threadA"); threadA.start(); Runnable runB = new Runnable() { public void run() { readStuff(in); } }; Thread threadB = new Thread(runB, "threadB"); threadB.start(); } catch (IOException x) { x.printStackTrace(); } }
From source file:HrefMatch.java
public static void main(String[] args) { try {//from w ww . ja v a2 s . com // get URL string from command line or use default String urlString; if (args.length > 0) urlString = args[0]; else urlString = "http://java.sun.com"; // open reader for URL InputStreamReader in = new InputStreamReader(new URL(urlString).openStream()); // read contents into string builder StringBuilder input = new StringBuilder(); int ch; while ((ch = in.read()) != -1) input.append((char) ch); // search for all occurrences of pattern String patternString = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>]*)\\s*>"; Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); String match = input.substring(start, end); System.out.println(match); } } catch (IOException e) { e.printStackTrace(); } catch (PatternSyntaxException e) { e.printStackTrace(); } }
From source file:Base64Decode.java
/** * A test method of questionable utility. *///from w ww. ja v a 2 s .co m public static void main(String args[]) { try { FileOutputStream fos = new FileOutputStream("out.dat"); fos.write(decode(System.in)); fos.close(); } catch (IOException ie) { ie.printStackTrace(); } }
From source file:examples.daytime.java
public static final void main(String[] args) { if (args.length == 1) { try {/* w ww. j a va 2 s . co m*/ daytimeTCP(args[0]); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else if (args.length == 2 && args[0].equals("-udp")) { try { daytimeUDP(args[1]); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else { System.err.println("Usage: daytime [-udp] <hostname>"); System.exit(1); } }
From source file:postenergy.TestHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin"); try {// w w w .j a v a2 s. com List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("Email", "youremail")); nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword")); nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example")); nameValuePairs.add(new BasicNameValuePair("service", "ac2dm")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Auth=")) { String key = line.substring(5); // do something with the key } } } catch (IOException e) { e.printStackTrace(); } }
From source file:examples.rdate.java
public static final void main(String[] args) { if (args.length == 1) { try {/*w w w . j a v a 2 s . 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: rdate [-udp] <hostname>"); System.exit(1); } }
From source file:examples.unix.daytime.java
public static void main(String[] args) { if (args.length == 1) { try {//from www. ja va 2 s .c o m daytimeTCP(args[0]); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else if (args.length == 2 && args[0].equals("-udp")) { try { daytimeUDP(args[1]); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } else { System.err.println("Usage: daytime [-udp] <hostname>"); System.exit(1); } }
From source file:examples.nntp.newsgroups.java
public final static void main(String[] args) { NNTPClient client;/*from w w w . j ava2 s. c o m*/ NewsgroupInfo[] list; if (args.length < 1) { System.err.println("Usage: newsgroups newsserver"); System.exit(1); } client = new NNTPClient(); try { client.connect(args[0]); list = client.listNewsgroups(); if (list != null) { for (int i = 0; i < list.length; i++) System.out.println(list[i].getNewsgroup()); } else { System.err.println("LIST command failed."); System.err.println("Server reply: " + client.getReplyString()); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (client.isConnected()) client.disconnect(); } catch (IOException e) { System.err.println("Error disconnecting from server."); e.printStackTrace(); System.exit(1); } } }
From source file:examples.unix.rdate.java
public static void main(String[] args) { if (args.length == 1) { try {// ww w .j av a 2 s .com 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: rdate [-udp] <hostname>"); System.exit(1); } }
From source file:Resource.java
/** * @param args/*from w w w.j av a2s .com*/ */ public static void main(String[] args) { // TODO Auto-generated method stub ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream is = cl.getResourceAsStream("com/sap/ca/aspose/license/Aspose.Total.Java.lic"); //InputStream is = cl.getResourceAsStream("com/sap/ca/aspose/license/a.txt"); if (is == null) { System.err.println("Error is is null"); System.exit(1); } String s; try { s = IOUtils.toString(is); System.out.println(s); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }