List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:MainClass.java
public static void main(String[] args) { try {/*from w w w . j ava 2 s . c om*/ URL u = new URL("http://www.java2s.com"); OutputStream out = new FileOutputStream("test.htm"); InputStream in = u.openStream(); DTD html = DTD.getDTD("html"); System.out.println(html.getName()); in.close(); out.flush(); out.close(); } catch (Exception e) { System.err.println("Usage: java PageSaver url local_file"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { URL webSvcGetURL = new URL("http://www.server.net/Webservices"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(webSvcGetURL.openStream())); SAXSource saxSource = new SAXSource(new InputSource(bufferedReader)); String curDir = new File(".").getCanonicalPath(); StreamSource xlstStreamSource = new StreamSource(new File(curDir + File.separator + "style.xsl")); File resultHTMLFile = new File(curDir + File.separator + "output.html"); StreamResult streamResult = new StreamResult(resultHTMLFile); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(xlstStreamSource); transformer.transform((Source) saxSource, streamResult); }
From source file:net.infstudio.inflauncher.Main.java
public static void main(String[] args) { //TODO Test// ww w .j a v a2 s . c o m InfinityDownloader.logger.info("Hello world!"); try { URL mcURL = new URL("http://s3.amazonaws.com/Minecraft.Download/versions/1.10.2/1.10.2.json"); FileUtils.copyInputStreamToFile(mcURL.openStream(), new File("1.10.2.json")); InfinityDownloader.logger.info("Ping to http://stackoverflow.com: time=" + URLConnectionTimer.testTime("http://stackoverflow.com")); } catch (IOException e) { LogManager.getLogger("InfinityLauncher").error(e); } }
From source file:sample.jetty.SampleJettyApplication.java
public static void main(String[] args) throws Exception { InputStream inputstream = null; try {/*w w w.j a v a 2 s. c o m*/ Properties pro = new Properties(); //????? URL url = org.springframework.util.ResourceUtils.getURL("classpath:MySql_general.properties"); inputstream = url.openStream(); pro.load(inputstream); //new EmbedMySqlServer(pro).startup(); String dbPath = (new File("")).getAbsolutePath() + "/db/"; dbPath = dbPath.replaceAll("\\\\", "/"); //??? EmbedMySqlServer mysqldbServer = new EmbedMySqlServer(pro, dbPath /*"C:\\gfworklog\\db\\"*/); SampleJettyApplication.MAIN_THREAD_LOCAL.put("embedMysqlServer", mysqldbServer); mysqldbServer.startup(); } catch (Exception e) { e.printStackTrace(); } finally { try { inputstream.close(); } catch (Exception ex) { } } System.out.println(Thread.currentThread().getName() + " ========================= " + 1 + " ========================="); ConfigurableApplicationContext cac = SpringApplication.run(SampleJettyApplication.class, args); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ParserGetter kit = new ParserGetter(); HTMLEditorKit.Parser parser = kit.getParser(); String encoding = "ISO-8859-1"; URL url = new URL("http://www.java2s.com"); InputStream in = url.openStream(); InputStreamReader r = new InputStreamReader(in, encoding); // parse once just to detect the encoding HTMLEditorKit.ParserCallback doNothing = new HTMLEditorKit.ParserCallback(); parser.parse(r, doNothing, false);/* ww w . jav a2 s . co m*/ parse(url, encoding); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ParserGetter kit = new ParserGetter(); HTMLEditorKit.Parser parser = kit.getParser(); URL u = new URL("http://www.java2s.com"); InputStream in = u.openStream(); InputStreamReader r = new InputStreamReader(in); String remoteFileName = u.getFile(); if (remoteFileName.endsWith("/")) { remoteFileName += "index.html"; }//from ww w. ja v a 2 s . c om if (remoteFileName.startsWith("/")) { remoteFileName = remoteFileName.substring(1); } File localDirectory = new File(u.getHost()); while (remoteFileName.indexOf('/') > -1) { String part = remoteFileName.substring(0, remoteFileName.indexOf('/')); remoteFileName = remoteFileName.substring(remoteFileName.indexOf('/') + 1); localDirectory = new File(localDirectory, part); } if (localDirectory.mkdirs()) { File output = new File(localDirectory, remoteFileName); FileWriter out = new FileWriter(output); HTMLEditorKit.ParserCallback callback = new PageSaver(out, u); parser.parse(r, callback, false); } }
From source file:com.mycompany.jaxrsexample.client.Client.java
public static void main(String args[]) throws Exception { // Sent HTTP GET request to query all students info System.out.println("Invoking server through HTTP GET to query all students info"); URL url = new URL("http://localhost:9000/studentservice/students"); InputStream in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP GET request to query student info System.out.println("Sent HTTP GET request to query customer info"); url = new URL("http://localhost:9000/studentservice/students/1"); in = url.openStream();//from ww w. j a v a 2s. co m System.out.println(getStringFromInputStream(in)); // Sent HTTP PUT request to update student info System.out.println("\n"); System.out.println("Sent HTTP PUT request to update student info"); Client client = new Client(); String inputFile = client.getClass().getResource("/update_student.xml").getFile(); URIResolver resolver = new URIResolver(inputFile); File input = new File(resolver.getURI()); PutMethod put = new PutMethod("http://localhost:9000/studentservice/students"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(put); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(put.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } // Sent HTTP POST request to add student System.out.println("\n"); System.out.println("Sent HTTP POST request to add student"); inputFile = client.getClass().getResource("/add_student.xml").getFile(); resolver = new URIResolver(inputFile); input = new File(resolver.getURI()); PostMethod post = new PostMethod("http://localhost:9000/studentservice/students"); post.addRequestHeader("Accept", "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } System.out.println("\n"); System.exit(0); }
From source file:com.zxm.servicemix.examples.cxf.jaxrs.client.Client.java
public static void main(String args[]) throws Exception { // Sent HTTP GET request to query all customer info // Sent HTTP GET request to query customer info System.out.println("Sent HTTP GET request to query customer info"); URL url = new URL("http://localhost:8181/cxf/crm/customerservice/customers/123"); InputStream in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP GET request to query sub resource product info System.out.println("\n"); System.out.println("Sent HTTP GET request to query sub resource product info"); url = new URL("http://localhost:8181/cxf/crm/customerservice/orders/223/products/323"); in = url.openStream();/* ww w. ja v a2 s .c o m*/ System.out.println(getStringFromInputStream(in)); // Sent HTTP PUT request to update customer info System.out.println("\n"); System.out.println("Sent HTTP PUT request to update customer info"); Client client = new Client(); String inputFile = client.getClass().getResource("update_customer.xml").getFile(); File input = new File(inputFile); PutMethod put = new PutMethod("http://localhost:8181/cxf/crm/customerservice/customers"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(put); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(put.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } // Sent HTTP POST request to add customer System.out.println("\n"); System.out.println("Sent HTTP POST request to add customer"); inputFile = client.getClass().getResource("add_customer.xml").getFile(); input = new File(inputFile); PostMethod post = new PostMethod("http://localhost:8181/cxf/crm/customerservice/customers"); post.addRequestHeader("Accept", "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } System.out.println("\n"); System.exit(0); }
From source file:net.semanticmetadata.lire.solr.SearchImages.java
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException { // http://localhost:8080/solr/lire/query?q=hashes%3A1152++hashes%3A605++hashes%3A96++hashes%3A275++&wt=xml String hashes = "1152 605 96 275 2057 3579 3950 2831 2367 3169 3292 974 2465 1573 2933 3125 314 2158 3532 974 2198 2315 3013 3302 3316 1467 2213 818 3 1083 18 2604 327 1370 593 3677 464 79 256 984 2496 1124 855 2091 780 1941 1887 1145 1396 4016 2406 2227 1532 2598 215 1375 171 2516 1698 368 2350 3799 223 1471 2083 1051 3015 3789 3374 1442 3991 3575 1452 751 428 3103 1182 2241 474 275 3678 3970 559 3394 2662 2361 2048 1083 181 1483 3903 3331 2363 756 558 2838 3984 1878 2667 3333 1473 2136 3499 3873 1437 3091 1287 948 46 3660 3003 1572 1185 2231 2622 257 3538 3632 3989 1180 3928 3144 1492 3941 3253 3498 2721 1036 22 1020 725 1431 3821 2248 2542 3659 2849 524 2967 1 2493 3620 2951 3584 1641 3873 2087 1506 1489 3064"; String[] split = hashes.split(" "); String query = ""; for (int i = 0; i < split.length; i++) { String s = split[i];/* ww w . j ava 2s.c o m*/ if (s.trim().length() > 0) query += " cl_ha:" + s.trim(); } URL u = new URL(baseURL + "?q=" + URLEncoder.encode(query, "utf-8") + "&wt=xml&rows=500"); InputStream in = u.openStream(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); SolrResponseHandler dh = new SolrResponseHandler(); saxParser.parse(in, dh); ArrayList<ResultItem> results = dh.getResults(); // re-rank: }
From source file:edu.techseekers.training.client.Client.java
public static void main(String args[]) throws Exception { // Sent HTTP GET request to query all customer info /*/* w w w.ja v a 2 s .c o m*/ * URL url = new URL("http://localhost:9000/customers"); * System.out.println("Invoking server through HTTP GET to query all * customer info"); InputStream in = url.openStream(); StreamSource * source = new StreamSource(in); printSource(source); */ // Sent HTTP GET request to query customer info System.out.println("Sent HTTP GET request to query customer info"); URL url = new URL("http://localhost:9000/customerservice/customers/123"); InputStream in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP GET request to query sub resource product info System.out.println("\n"); System.out.println("Sent HTTP GET request to query sub resource product info"); url = new URL("http://localhost:9000/customerservice/orders/223/products/323"); in = url.openStream(); System.out.println(getStringFromInputStream(in)); // Sent HTTP PUT request to update customer info System.out.println("\n"); System.out.println("Sent HTTP PUT request to update customer info"); Client client = new Client(); String inputFile = client.getClass().getResource("/update_customer.xml").getFile(); URIResolver resolver = new URIResolver(inputFile); File input = new File(resolver.getURI()); PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); try { int result = httpclient.executeMethod(put); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(put.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } // Sent HTTP POST request to add customer System.out.println("\n"); System.out.println("Sent HTTP POST request to add customer"); inputFile = client.getClass().getResource("/add_customer.xml").getFile(); resolver = new URIResolver(inputFile); input = new File(resolver.getURI()); PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers"); post.addRequestHeader("Accept", "text/xml"); entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); httpclient = new HttpClient(); try { int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } System.out.println("\n"); System.exit(0); }