List of usage examples for java.io BufferedReader readLine
public String readLine() throws IOException
From source file:MainClass.java
public static void main(String[] args) throws IOException { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(8080); while (true) { try {/*from w ww .j ava2s . c om*/ Socket s = ss.accept(); OutputStream out = s.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null) && (!("".equals(line)))) { System.out.println(line); } StringBuffer buffer = new StringBuffer(); buffer.append("<HTML><HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n"); buffer.append("<BODY>\n<H1>Success!</H1></BODY></HTML>\n"); String string = buffer.toString(); byte[] data = string.getBytes(); out.write("HTTP/1.0 200 OK\n".getBytes()); out.write(new String("Content-Length: " + data.length + "\n").getBytes()); out.write("Content-Type: text/html\n\n".getBytes()); out.write(data); out.flush(); out.close(); in.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { InetAddress server = InetAddress.getByName("localhost"); BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket theSocket = new DatagramSocket(); while (true) { String theLine = userInput.readLine(); if (theLine.equals(".")) break; byte[] data = theLine.getBytes(); DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999); theSocket.send(theOutput);// www .j a va2s . c o m } }
From source file:BufferedSocketClient.java
public static void main(String args[]) throws Exception { int cTosPortNumber = 1777; String str;//from w w w. ja v a2 s . co m ServerSocket servSocket = new ServerSocket(cTosPortNumber); System.out.println("Waiting for a connection on " + cTosPortNumber); Socket fromClientSocket = servSocket.accept(); PrintWriter pw = new PrintWriter(fromClientSocket.getOutputStream(), true); BufferedReader br = new BufferedReader(new InputStreamReader(fromClientSocket.getInputStream())); while ((str = br.readLine()) != null) { System.out.println("The message: " + str); if (str.equals("bye")) { pw.println("bye"); break; } else { str = "Server returns " + str; pw.println(str); } } pw.close(); br.close(); fromClientSocket.close(); }
From source file:com.wordnik.swaggersocket.samples.NettoSphere.java
public static void main(String[] args) throws IOException { ReflectorServletProcessor rsp = new ReflectorServletProcessor(); rsp.setServletClassName(CXFNonSpringJaxrsServlet.class.getName()); int p = getHttpPort(); Config.Builder b = new Config.Builder(); b.resource("./app").initParam(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json") .initParam(ApplicationConfig.WEBSOCKET_METHOD, "POST") .initParam("jaxrs.serviceClasses", SwaggerSocketResource.class.getName() + "," + FileServiceResource.class.getName()) .initParam("jaxrs.providers", JacksonJsonProvider.class.getName()) .initParam("com.wordnik.swaggersocket.protocol.lazywrite", "true") .initParam("com.wordnik.swaggersocket.protocol.emptyentity", "true") .interceptor(new SwaggerSocketProtocolInterceptor()).resource("/*", rsp).port(p).host("127.0.0.1") .build();/* ww w .java 2 s . c o m*/ Nettosphere s = new Nettosphere.Builder().config(b.build()).build(); s.start(); String a = ""; logger.info("NettoSphere SwaggerSocket Server started on port {}", p); logger.info("Type quit to stop the server"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (!(a.equals("quit"))) { a = br.readLine(); } System.exit(-1); }
From source file:com.npower.dm.util.ConvertMailProfile.java
/** * @param args/*from w w w. ja v a2 s . co m*/ */ public static void main(String[] args) throws Exception { File outputFile = new File("c:/temp/mail.xml"); FileWriter writer = new FileWriter(outputFile); File csvFile = new File("c:/temp/mail.csv"); BufferedReader reader = new BufferedReader(new FileReader(csvFile)); String line = reader.readLine(); while (line != null) { line = reader.readLine(); if (StringUtils.isEmpty(line)) { continue; } String[] cols = StringUtils.split(line, ','); Map<String, String> values = new HashMap<String, String>(); values.put("name", cols[0]); values.put("smtp.host", cols[1]); values.put("pop.host", cols[2]); writeXML(writer, values); } writer.close(); reader.close(); }
From source file:com.trendmicro.hdfs.webdav.tool.Get.java
public static void main(String[] args) throws Exception { // Process command line Options options = new Options(); options.addOption("d", "debug", false, "Enable debug logging"); CommandLine cmd = null;//from ww w . j a va 2 s . c o m try { cmd = new PosixParser().parse(options, args); } catch (ParseException e) { printUsageAndExit(options, -1); } boolean debug = cmd.hasOption('d'); args = cmd.getArgs(); if (args.length < 1) { printUsageAndExit(options, -1); } // Do the fetch AuthenticatedURL.Token token = new AuthenticatedURL.Token(); AuthenticatedURL url = new AuthenticatedURL(); HttpURLConnection conn = url.openConnection(new URL(args[0]), token); if (debug) { System.out.println("Token value: " + token); System.out.println("Status code: " + conn.getResponseCode() + " " + conn.getResponseMessage()); } if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = reader.readLine(); while (line != null) { System.out.println(line); line = reader.readLine(); } reader.close(); } System.out.println(); }
From source file:GZIPcompress.java
public static void main(String[] args) throws IOException { if (args.length == 0) { System.out.println("Usage: \nGZIPcompress file\n" + "\tUses GZIP compression to compress " + "the file to test.gz"); System.exit(1);/*from w w w . j a v a2 s .co m*/ } BufferedReader in = new BufferedReader(new FileReader(args[0])); BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("test.gz"))); System.out.println("Writing file"); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); System.out.println("Reading file"); BufferedReader in2 = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream("test.gz")))); String s; while ((s = in2.readLine()) != null) System.out.println(s); }
From source file:Main.java
public static void main(String[] args) throws Exception { DatagramSocket udpSocket = new DatagramSocket(); String msg = null;//from w w w. j a va2 s . c om BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter a message (Bye to quit):"); while ((msg = br.readLine()) != null) { if (msg.equalsIgnoreCase("bye")) { break; } DatagramPacket packet = Main.getPacket(msg); udpSocket.send(packet); udpSocket.receive(packet); displayPacketDetails(packet); System.out.print("Please enter a message (Bye to quit):"); } udpSocket.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.trustStore", "clienttrust"); SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = ssf.createSocket("127.0.0.1", 8888); OutputStream outs = s.getOutputStream(); PrintStream out = new PrintStream(outs); InputStream ins = s.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(ins)); out.println("Hi,How are u!"); out.println(""); String line = null;/*from w w w. j a va 2 s .com*/ while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); out.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(8080); ss.setNeedClientAuth(true);/*from www .j a v a 2 s. co m*/ while (true) { try { Socket s = ss.accept(); OutputStream out = s.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null) && (!("".equals(line)))) { System.out.println(line); } System.out.println(""); StringBuffer buffer = new StringBuffer(); buffer.append("<HTML>\n"); buffer.append("<HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n"); buffer.append("<BODY>\n"); buffer.append("<H1>Success!</H1>\n"); buffer.append("</BODY>\n"); buffer.append("</HTML>\n"); String string = buffer.toString(); byte[] data = string.getBytes(); out.write("HTTP/1.0 200 OK\n".getBytes()); out.write(new String("Content-Length: " + data.length + "\n").getBytes()); out.write("Content-Type: text/html\n\n".getBytes()); out.write(data); out.flush(); out.close(); in.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } } }