Example usage for java.io OutputStream write

List of usage examples for java.io OutputStream write

Introduction

In this page you can find the example usage for java.io OutputStream write.

Prototype

public void write(byte b[]) throws IOException 

Source Link

Document

Writes b.length bytes from the specified byte array to this output stream.

Usage

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;/*from   ww  w . j ava  2 s. co  m*/
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.sendUrgentData(1);

    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;/*from w  w  w .  ja  va2 s .  c o  m*/
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    System.out.println(s.toString());

    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;//from  w  w w  .  j av  a2s . com
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.setTrafficClass(1);
    System.out.println(s.getTrafficClass());

    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;// ww  w.j a  v  a  2 s  .c  o  m
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.setOOBInline(true);
    System.out.println(s.getOOBInline());

    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;/*from w  w w . j a v a 2s  .  com*/
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    s.shutdownInput();
    s.shutdownOutput();

    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. java2  s  . c om
    while ((c = in.read()) != -1) {
        System.out.print((char) c);
    }

    SocketChannel socketChannel = s.getChannel();
    System.out.println(socketChannel.getLocalAddress());

    s.close();
}

From source file:com.web.server.ShutDownServer.java

/**
 * @param args// w ww  .j a  va2  s.com
 * @throws SAXException 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException, SAXException {
    DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml")));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    Digester serverdigester = serverdigesterLoader.newDigester();
    ServerConfig serverconfig = (ServerConfig) serverdigester
            .parse(new InputSource(new FileInputStream("./config/serverconfig.xml")));
    try {
        Socket socket = new Socket("localhost", Integer.parseInt(serverconfig.getShutdownport()));
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("shutdown WebServer\r\n\r\n".getBytes());
        outputStream.close();
    } catch (IOException e1) {

        e1.printStackTrace();
    }

}

From source file:com.app.server.ShutDownServer.java

/**
 * @param args//w  w  w . j  a va2  s  .com
 * @throws SAXException 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException, SAXException {
    DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml")));
            } catch (FileNotFoundException e) {
                log.error("Could not load rules xml serverconfig-rules.xml", e);
                // TODO Auto-generated catch block
                //e.printStackTrace();
            }

        }
    });
    Digester serverdigester = serverdigesterLoader.newDigester();
    ServerConfig serverconfig = (ServerConfig) serverdigester
            .parse(new InputSource(new FileInputStream("./config/serverconfig.xml")));
    try {
        Socket socket = new Socket("localhost", Integer.parseInt(serverconfig.getShutdownport()));
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("shutdown WebServer\r\n\r\n".getBytes());
        outputStream.close();
    } catch (Exception ex) {
        log.error("Could not able to create socket and write shutdown bytes", ex);
        //e1.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  w w w . j  a  v a  2 s.  co 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:FileInputOutputExample.java

public static void main(String[] args) throws Exception {

    InputStream is = new FileInputStream("in.txt");
    OutputStream os = new FileOutputStream("out.txt");
    int c;//from  w w w . j av a2  s.  c o  m
    while ((c = is.read()) != -1) {
        System.out.print((char) c);
        os.write(c);
    }
    is.close();
    os.close();

}