List of usage examples for java.io InputStream read
public abstract int read() throws IOException;
From source file:com.lxf.spider.client.ClientConnectionRelease.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from ww w . ja v a 2s. c o m HttpGet httpget = new HttpGet("http://localhost/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); 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 bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.zhch.example.commons.http.v4_5.ClientConnectionRelease.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {/* ww w. ja v a 2s. co m*/ HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); 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 bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.ccreservoirs.RSSReader.ClientConnectionRelease.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from www .j a v a 2 s . com HttpGet httpget = new HttpGet("http://blog.csdn.net/rss.html?type=Home&channel="); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); 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 bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be // released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection // release instream.close(); } } } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.http.ClientConnectionRelease.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {/* ww w.ja va 2 s . co m*/ HttpGet httpget = new HttpGet("http://www.apache.org/"); // Execute HTTP request System.out.println("executing request " + httpget.getURI()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println("----------------------------------------"); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); } } finally { httpclient.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream fin = new FileInputStream("a.dat"); OutputStream fout = new FileOutputStream("a.dat.gz"); GZIPOutputStream gzout = new GZIPOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { gzout.write(c);//from w w w .ja va 2s . c o m } gzout.close(); }
From source file:com.caucho.hessian.client.ClientConnectionRelease.java
public final static void main(String[] args) throws Exception { HttpClient httpclient = new DefaultHttpClient(); try {//from www . j a v a 2 s. c o m HttpGet httpget = new HttpGet("http://www.apache.org/"); // Execute HTTP request System.out.println("executing request " + httpget.getURI()); HttpResponse response = httpclient.execute(httpget); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println("----------------------------------------"); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection immediately. httpget.abort(); throw ex; } finally { // Closing the input stream will trigger connection release try { instream.close(); } catch (Exception ignore) { } } } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from ww w. j av a2 s .c o m*/ OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); os.write(70); os.write(71); for (int i = 0; i < 2; i++) { System.out.print((char) is.read()); } os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream in = new FileInputStream("test.txt"); OutputStream out = System.out; PrintableOutputStream pout = new PrintableOutputStream(out); for (int c = in.read(); c != -1; c = in.read()) { pout.write(c);//from w w w. j av a 2 s . c om } out.close(); }
From source file:Whois.java
License:asdf
public static void main(String args[]) throws Exception { int c;/*from w ww . j a va 2 s . c om*/ Socket s = new Socket("internic.net", 43); InputStream in = s.getInputStream(); OutputStream out = s.getOutputStream(); String str = "asdfasdfasdf\n"; byte buf[] = str.getBytes(); out.write(buf); while ((c = in.read()) != -1) { System.out.print((char) c); } s.close(); }
From source file:com.maverick.ssl.SSLSocket.java
public static void main(String[] args) { try {/*from www . java 2s .co m*/ HttpsURLStreamHandlerFactory.addHTTPSSupport(); URL url = new URL("https://localhost"); //$NON-NLS-1$ URLConnection con = url.openConnection(); con.setDoInput(true); con.setDoOutput(false); con.setAllowUserInteraction(false); con.setRequestProperty("Accept", //$NON-NLS-1$ "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*"); //$NON-NLS-1$ con.setRequestProperty("Accept-Encoding", "gzip, deflate"); //$NON-NLS-1$ //$NON-NLS-2$ con.setRequestProperty("Accept-Language", "en-gb"); //$NON-NLS-1$ //$NON-NLS-2$ con.setRequestProperty("Connection", "Keep-Alive"); //$NON-NLS-1$ //$NON-NLS-2$ con.setRequestProperty("User-Agent", //$NON-NLS-1$ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"); //$NON-NLS-1$ con.connect(); InputStream in = con.getInputStream(); int read; while ((read = in.read()) > -1) { System.out.write(read); } } catch (SSLIOException ex) { ex.getRealException().printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }