List of usage examples for java.io BufferedReader readLine
public String readLine() throws IOException
From source file:Main.java
public static void main(String args[]) throws IOException { Process process = new ProcessBuilder(args).start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line;/* www . ja v a 2s.c o m*/ System.out.printf("Output of running %s is:", Arrays.toString(args)); while ((line = br.readLine()) != null) { System.out.println(line); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); String hostName = "hostName"; String fileName = "fileName"; SSLSocket sslsock = (SSLSocket) factory.createSocket(hostName, 443); SSLSession session = sslsock.getSession(); X509Certificate cert;//from w w w . j a v a2 s. c om try { cert = (X509Certificate) session.getPeerCertificates()[0]; } catch (SSLPeerUnverifiedException e) { System.err.println(session.getPeerHost() + " did not present a valid certificate."); return; } System.out.println(session.getPeerHost() + " has presented a certificate belonging to:"); Principal p = cert.getSubjectDN(); System.out.println("\t[" + p.getName() + "]"); System.out.println("The certificate bears the valid signature of:"); System.out.println("\t[" + cert.getIssuerDN().getName() + "]"); System.out.print("Do you trust this certificate (y/n)? "); System.out.flush(); BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); if (Character.toLowerCase(console.readLine().charAt(0)) != 'y') return; PrintWriter out = new PrintWriter(sslsock.getOutputStream()); out.print("GET " + fileName + " HTTP/1.0\r\n\r\n"); out.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(sslsock.getInputStream())); String line; while ((line = in.readLine()) != null) System.out.println(line); sslsock.close(); }
From source file:Main.java
public static void main(String args[]) throws IOException { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(args); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line;/*from w w w . j a va 2s . c om*/ System.out.printf("Output of running %s is:", Arrays.toString(args)); while ((line = br.readLine()) != null) { System.out.println(line); } }
From source file:com.linkedin.pinot.broker.broker.BrokerServerBuilderTest.java
public static void main(String[] args) throws Exception { PropertiesConfiguration config = new PropertiesConfiguration( new File(BrokerServerBuilderTest.class.getClassLoader().getResource("broker.properties").toURI())); final BrokerServerBuilder bld = new BrokerServerBuilder(config, null, null, null); bld.buildNetwork();// ww w .j a v a2 s . c om bld.buildHTTP(); bld.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { bld.stop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { String command = br.readLine(); if (command.equals("exit")) { bld.stop(); } } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from w ww . ja v a 2 s . c om PdfContentByte cb = writer.getDirectContent(); BufferedReader reader = new BufferedReader(new FileReader("a.txt")); String line; Paragraph p; float pos; while ((line = reader.readLine()) != null) { p = new Paragraph(" " + line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); pos = writer.getVerticalPosition(false); cb.moveTo(0, pos); cb.lineTo(PageSize.A4.width(), pos); cb.stroke(); if (pos < 90) document.newPage(); } reader.close(); document.close(); }
From source file:Finger.java
public static void main(String[] arguments) throws Exception { StringTokenizer split = new StringTokenizer(arguments[0], "@"); String user = split.nextToken(); String host = split.nextToken(); Socket digit = new Socket(host, 79); digit.setSoTimeout(20000);/*from w w w . j a v a 2 s . co m*/ PrintStream out = new PrintStream(digit.getOutputStream()); out.print(user + "\015\012"); BufferedReader in = new BufferedReader(new InputStreamReader(digit.getInputStream())); boolean eof = false; while (!eof) { String line = in.readLine(); if (line != null) System.out.println(line); else eof = true; } digit.close(); }
From source file:Standard.java
public static void main(String args[]) throws IOException { BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); String number;/* www . j av a 2 s. c o m*/ int total = 0; while ((number = cin.readLine()) != null) { try { total += Integer.parseInt(number); } catch (NumberFormatException e) { System.err.println("Invalid number in input"); System.exit(1); } } System.out.println(total); }
From source file:TestRESTPost12.java
public static void main(String[] p) throws Exception { String strurl = "http://localhost:8080/testnewmaven8/webresources/service/post"; //StringEntity str=new StringEntity("<a>hello post</a>",ContentType.create("application/xml" , Consts.UTF_8)); ///*from ww w . j a v a 2 s. c om*/ StringEntity str = new StringEntity("hello post"); str.setContentType("APPLICATION/xml"); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(strurl); httppost.addHeader("Accept", "application/xml charset=UTF-8"); //httppost.addHeader("content_type", "application/xml, multipart/related"); httppost.setEntity(str); CloseableHttpResponse response = httpclient.execute(httppost); // try //{ int statuscode = response.getStatusLine().getStatusCode(); if (statuscode != 200) { System.out.println("http error occured=" + statuscode); } BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); while (br.readLine() != null) { System.out.println(br.readLine()); } // } /*catch(Exception e) { System.out.println("exception :"+e); }*/ //httpclient.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://www.java.com"); URLConnection urlConnection = url.openConnection(); HttpURLConnection connection = null; if (urlConnection instanceof HttpURLConnection) { connection = (HttpURLConnection) urlConnection; } else {//w ww . java2s. c o m System.out.println("Please enter an HTTP URL."); return; } BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String urlString = ""; String current; while ((current = in.readLine()) != null) { urlString += current; } System.out.println(urlString); }
From source file:an.dpr.cyclingresultsapi.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); StringBuilder ret = new StringBuilder(); try {/*from w ww .ja v a2 s . c om*/ //http://cyclingresults-dprsoft.rhcloud.com/rest/competitions/query/20140101,20140601,1,1,UWT // HttpHost target = new HttpHost("cyclingresults-dprsoft.rhcloud.com", 80, "http"); HttpHost proxy = null;// = new HttpHost("proxy.sdc.hp.com", 8080, "http"); HttpHost target = new HttpHost("localhost", 8282, "http"); RequestConfig config = RequestConfig.custom() // .setProxy(proxy) .build(); HttpGet request = new HttpGet("/rest/competitions/query/20130801,20130901,1,1,UWT"); request.setConfig(config); System.out.println("Executing request " + request.getRequestLine() + " to " + target + " via " + proxy); CloseableHttpResponse response = httpclient.execute(target, request); InputStreamReader isr = new InputStreamReader(response.getEntity().getContent(), "cp1252"); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { ret.append(line); } try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } System.out.println(ret.toString()); }