List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:com.jeffy.hdfs.HDFSReadFile.java
/** * @param args/*from w w w.j ava 2 s . c o m*/ */ public static void main(String[] args) { String path = "hdfs://master:8020/tmp/user.csv"; //HDFSReadFile.readDataUseURL(path); try { HDFSReadFile.readDataUseFileSystem(path); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.spring.resource.FileSourceExample.java
public static void main(String[] args) { try {// www. j av a 2 s .c om String filePath = "E:\\JEELearning\\ideaworlplace\\springdream\\springdream.ioc\\src\\main\\resources\\FileSource.txt"; // ? Resource res1 = new FileSystemResource(filePath); // ? Resource res2 = new ClassPathResource("FileSource.txt"); System.out.println("?:" + res1.getFilename()); System.out.println("?:" + res2.getFilename()); InputStream in1 = res1.getInputStream(); InputStream in2 = res2.getInputStream(); // System.out.println("?:" + read(in1)); // System.out.println("?:" + read(in2)); System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in1))); System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in2))); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.run.FtpClientExample.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileOutputStream fos = null;//from w w w . j a v a 2s . c o m try { client.connect(ARDroneConstants.IP_ADDRESS, ARDroneConstants.FTP_PORT); if (!client.login("anonymous", "")) System.err.println("login failed"); client.setFileType(FTP.BINARY_FILE_TYPE); String filename = "version.txt"; fos = new FileOutputStream(filename); if (!client.retrieveFile("/" + filename, fos)) System.err.println("cannot find file"); System.out.println("done"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) { fos.flush(); fos.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.javaquery.apache.httpclient.HttpDeleteExample.java
public static void main(String[] args) { /* Create object of CloseableHttpClient */ CloseableHttpClient httpClient = HttpClients.createDefault(); /* Prepare delete request */ HttpDelete httpDelete = new HttpDelete("http://www.example.com/api/customer"); /* Add headers to get request */ httpDelete.addHeader("Authorization", "value"); /* Response handler for after request execution */ ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override// w w w .ja v a 2 s .c om 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(httpDelete, responseHandler); /* Print the response */ System.out.println("Response: " + strResponse); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.vuphone.vandyupon.test.ImagePostTester.java
public static void main(String[] args) { try {//w w w . j a va 2 s .c o m File image = new File("2008-05-8 ChrisMikeNinaGrad.jpg"); byte[] bytes = new byte[(int) image.length()]; FileInputStream fis = new FileInputStream(image); int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } fis.close(); HttpClient c = new DefaultHttpClient(); HttpPost post = new HttpPost( "http://afrl-gift.dre.vanderbilt.edu:8080/vandyupon/events/?type=eventimagepost&eventid=2" + "&time=" + System.currentTimeMillis() + "&resp=xml"); post.addHeader("Content-Type", "image/jpeg"); ByteArrayEntity bae = new ByteArrayEntity(bytes); post.setEntity(bae); try { HttpResponse resp = c.execute(post); resp.getEntity().writeTo(System.out); } catch (IOException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:FTP.FTPUploadFileDemo.java
public static void main(String[] args) { String server = "plutao.telemar"; int port = 21; String user = "usrcorj"; String pass = "usr341!tg"; ftpClient = new FTPClient(); Conect(server, port, user, pass);//w w w . ja v a2s . c o m UploadFile("C:\\Users\\fernando.m.souza\\Desktop\\Teste.txt", "\\UsrCoRJ\\Automacoes\\Teste.txt"); try { if (ftpClient.isConnected()) { ftpClient.logout(); ftpClient.disconnect(); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:PipedCharacters.java
public static void main(String[] args) { try {/* w w w .j a v a2s .co m*/ final PipedWriter out = new PipedWriter(); final PipedReader in = new PipedReader(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:com.javaquery.apache.httpclient.HttpGetExample.java
public static void main(String[] args) { /* Create object of CloseableHttpClient */ CloseableHttpClient httpClient = HttpClients.createDefault(); /* Prepare get request */ HttpGet httpGet = new HttpGet("http://www.example.com/api/customer"); /* Add headers to get request */ httpGet.addHeader("Authorization", "value"); httpGet.addHeader("Content-Type", "application/json"); /* Response handler for after request execution */ ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override//from w w w. j a v a 2s . co m 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(httpGet, responseHandler); /* Print the response */ System.out.println("Response: " + strResponse); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.BncCheckDocuments.java
public static void main(String[] args) throws IOException { boolean enabled = false; for (File f : FileUtils.listFiles(new File(BASE), new String[] { "xml" }, true)) { BufferedInputStream bis = null; try {/*from w ww . j av a2 s . c o m*/ bis = new BufferedInputStream(new FileInputStream(f)); int c; StringBuilder sb = new StringBuilder(); while ((c = bis.read()) != '>') { if (enabled) { if (c == '"') { enabled = false; break; } else { sb.append((char) c); } } if (c == '"') { enabled = true; } } String name = f.getName().substring(0, 3); String id = sb.toString(); if (!name.equals(id)) { System.out.println("Name is [" + name + "], but ID is [" + id + "]."); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(bis); } } }
From source file:com.web.server.ShutDownServer.java
/** * @param args/*w w w. j ava2 s . c om*/ * @throws SAXException * @throws IOException */ public static void main(String[] args) throws IOException, SAXException { DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); ServerConfig serverconfig = (ServerConfig) serverdigester .parse(new InputSource(new FileInputStream("./config/serverconfig.xml"))); try { Socket socket = new Socket("localhost", Integer.parseInt(serverconfig.getShutdownport())); OutputStream outputStream = socket.getOutputStream(); outputStream.write("shutdown WebServer\r\n\r\n".getBytes()); outputStream.close(); } catch (IOException e1) { e1.printStackTrace(); } }