List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out)
From source file:SecureServer.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(98999); Socket sock = ss.accept();/*from w ww . ja v a 2s. c om*/ ss.close(); OutputStream rawOut = sock.getOutputStream(); PrintWriter out = new PrintWriter(new OutputStreamWriter(rawOut)); out.println(new java.util.Date().toString()); out.flush(); sock.close(); }
From source file:Main.java
License:asdf
public static void main(String[] arges) throws Exception { InetAddress addr = InetAddress.getByName(null); Socket sk = new Socket(addr, 8888); BufferedReader in = new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sk.getOutputStream())), true); out.println("asdf"); System.out.println(in.readLine()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Socket socket = new Socket("localhost", 12900); System.out.println("Started client socket at " + socket.getLocalSocketAddress()); BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); String promptMsg = "Please enter a message (Bye to quit):"; String outMsg = null;// w w w . ja v a 2 s. c om System.out.print(promptMsg); while ((outMsg = consoleReader.readLine()) != null) { if (outMsg.equalsIgnoreCase("bye")) { break; } // Add a new line to the message to the server, // because the server reads one line at a time. socketWriter.write(outMsg); socketWriter.write("\n"); socketWriter.flush(); // Read and display the message from the server String inMsg = socketReader.readLine(); System.out.println("Server: " + inMsg); System.out.println(); // Print a blank line System.out.print(promptMsg); } socket.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];//from w w w.j a va2 s . co m URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoInput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];/*from www. j a v a 2 s . c om*/ URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoOutput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { OutputStream stream = System.out; XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(stream); xsw.writeStartDocument();/*from w w w .j a v a 2 s . c om*/ xsw.writeStartElement("foo"); xsw.writeStartElement("bar"); xsw.writeCharacters(""); xsw.flush(); OutputStreamWriter osw = new OutputStreamWriter(stream); osw.write("<baz>Hello World<baz>"); osw.flush(); xsw.writeEndElement(); xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8"); URL url = new URL("http://server.com:80/cgi"); URLConnection conn = url.openConnection(); conn.setDoOutput(true);/*w w w . j a va 2 s . com*/ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String pageAddr = "http://www.google.com/index.htm"; URL url = new URL(pageAddr); String websiteAddress = url.getHost(); String file = url.getFile();/* www.j a v a 2 s .c o m*/ Socket clientSocket = new Socket(websiteAddress, 80); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); OutputStreamWriter outWriter = new OutputStreamWriter(clientSocket.getOutputStream()); outWriter.write("GET " + file + " HTTP/1.0\r\n\n"); outWriter.flush(); BufferedWriter out = new BufferedWriter(new FileWriter(file)); boolean more = true; String input; while (more) { input = inFromServer.readLine(); if (input == null) more = false; else { out.write(input); } } out.close(); clientSocket.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false);// ww w.jav a 2s .co m DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new FileInputStream(new File("input.xml"))); File OutputDOM = new File("out.txt"); FileOutputStream fostream = new FileOutputStream(OutputDOM); OutputStreamWriter oswriter = new OutputStreamWriter(fostream); BufferedWriter bwriter = new BufferedWriter(oswriter); if (!OutputDOM.exists()) { OutputDOM.createNewFile(); } visitRecursively(doc, bwriter); bwriter.close(); oswriter.close(); fostream.close(); }
From source file:Who.java
public static void main(String[] v) { Socket s = null;/*w w w. j a v a 2s. c om*/ PrintWriter out = null; BufferedReader in = null; try { // Connect to port 79 (the standard finger port) on the host. String hostname = "www.java2s.com"; s = new Socket(hostname, 79); // Set up the streams out = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); in = new BufferedReader(new InputStreamReader(s.getInputStream())); // Send a blank line to the finger server, telling it that we want // a listing of everyone logged on instead of information about an // individual user. out.print("\n"); out.flush(); // Send it out // Now read the server's response // The server should send lines terminated with \n or \r. String line; while ((line = in.readLine()) != null) { System.out.println(line); } System.out.println("Who's Logged On: " + hostname); } catch (IOException e) { System.out.println("Who's Logged On: Error"); } // Close the streams! finally { try { in.close(); out.close(); s.close(); } catch (Exception e) { } } }