List of usage examples for java.io OutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this output stream. From source file:Main.java
public static void main(String[] argv) throws Exception { String command = "cat"; Process child = Runtime.getRuntime().exec(command); OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close();// w w w . j av a 2s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { String command = "cat"; Process child = Runtime.getRuntime().exec(command); OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close();//from w w w . j a v a 2 s .c o m }
From source file:Main.java
public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8888), 0); server.createContext("/foo", new HttpHandler() { public void handle(HttpExchange t) throws IOException { t.sendResponseHeaders(200, 0); OutputStream out = t.getResponseBody(); out.write("hello world".getBytes()); out.close();//from w ww .ja v a 2s .c om } }); server.start(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); out.flush();/*w w w.ja va 2 s . c om*/ int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 37; ServerSocket server = new ServerSocket(port); while (true) { Socket connection = null; connection = server.accept();//from w w w . j a v a2 s . c o m OutputStream out = connection.getOutputStream(); out.write(123); out.flush(); connection.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { int port = 2345; ServerSocket ss = new ServerSocket(port); while (true) { try {/*from w w w . j a v a2s .c om*/ Socket s = ss.accept(); String response = "Hello " + s.getInetAddress() + " on port " + s.getPort() + "\r\n"; response += "This is " + s.getLocalAddress() + " on port " + s.getLocalPort() + "\r\n"; OutputStream out = s.getOutputStream(); out.write(response.getBytes("US-ASCII")); out.flush(); s.close(); } catch (IOException ex) { } } }
From source file:Main.java
public static void main(String[] args) throws IOException { URL url = new URL("http://www.java2s.com/style/download.png"); InputStream inputStream = url.openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n = 0;//www. j a va 2 s . co m while (-1 != (n = inputStream.read(buffer))) { output.write(buffer, 0, n); } inputStream.close(); byte[] data = output.toByteArray(); OutputStream out = new FileOutputStream("data.png"); out.write(data); out.close(); for (byte b : data) { System.out.printf("0x%x ", b); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { char[] passphrase = "sasquatch".toCharArray(); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(".keystore"), passphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(keystore);/*from w w w.j a v a2 s . com*/ SSLContext context = SSLContext.getInstance("TLS"); TrustManager[] trustManagers = tmf.getTrustManagers(); context.init(null, trustManagers, null); SSLSocketFactory sf = context.getSocketFactory(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:Whois.java
License:asdf
public static void main(String args[]) throws Exception { int c;//from ww w.jav a 2s .co m 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:Main.java
License:asdf
public static void main(String args[]) throws Exception { 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); int c;// w w w .ja v a 2 s. co m while ((c = in.read()) != -1) { System.out.print((char) c); } s.setReceiveBufferSize(1); s.close(); }