Example usage for java.io DataOutputStream DataOutputStream

List of usage examples for java.io DataOutputStream DataOutputStream

Introduction

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

Prototype

public DataOutputStream(OutputStream out) 

Source Link

Document

Creates a new data output stream to write data to the specified underlying output stream.

Usage

From source file:ServerSocketDemo.java

public static void main(String args[]) throws Exception {
    int port = Integer.parseInt(args[0]);

    ServerSocket ss = new ServerSocket(port);

    while (true) {
        Socket s = ss.accept();//from ww w  . j  ava2 s.c o m

        OutputStream os = s.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeInt(1);

        s.close();
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    double[] dbuf = { 12.34, 34.45, 67.78, 88.88, 66.66, 77.33 };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (double d : dbuf) {
        dos.writeDouble(d);//from  ww  w . jav  a 2s  .  c om
    }
    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        double c = dis.readDouble();
        System.out.print(c);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    float[] fbuf = { 12.34f, 23.34f, 45.56f, 67.78f, 12.55f, 77.88f };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (float f : fbuf) {
        dos.writeFloat(f);/*from w w w  . ja v  a2 s.c o m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        float c = dis.readFloat();
        System.out.print(c);
    }
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    int howMany = 20;
    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);/* w  w w .j  a v  a  2s. c  o  m*/
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}

From source file:Main.java

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

    double[] dbuf = { 65.56, 66.89, 67.98, 68.82, 69.55, 70.37 };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    for (double d : dbuf) {
        dos.writeDouble(d);//from w w  w .  java  2s  . c o m
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        double c = dis.readDouble();
        System.out.print(c + " ");
    }

}

From source file:MainClass.java

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

    int howMany = 20;

    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);// ww w .j a va 2  s.com
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}

From source file:Main.java

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

    float[] fbuf = { 123.345f, 234.567f, 123.123f, 123.123f, 123.123f, 123.345f };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (float f : fbuf) {
        dos.writeFloat(f);//from  w ww .  j  av  a 2 s . c  o m
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        float c = dis.readFloat();
        System.out.print(c + " ");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String host = "host";
    int port = 25;
    String from = "from@from.net";
    String toAddr = "to@to.net";

    Socket servSocket = new Socket(host, port);
    DataOutputStream os = new DataOutputStream(servSocket.getOutputStream());
    DataInputStream is = new DataInputStream(servSocket.getInputStream());

    if (servSocket != null && os != null && is != null) {
        os.writeBytes("HELO\r\n");
        os.writeBytes("MAIL From:" + from + " \r\n");
        os.writeBytes("RCPT To:" + toAddr + "\r\n");
        os.writeBytes("DATA\r\n");
        os.writeBytes("X-Mailer: Java\r\n");
        os.writeBytes(//from  w ww . ja  v a2  s .c  om
                "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n");
        os.writeBytes("From:" + from + "\r\n");
        os.writeBytes("To:" + toAddr + "\r\n");
    }

    os.writeBytes("Subject:\r\n");
    os.writeBytes("body\r\n");
    os.writeBytes("\r\n.\r\n");
    os.writeBytes("QUIT\r\n");
    String responseline;
    while ((responseline = is.readUTF()) != null) {
        if (responseline.indexOf("Ok") != -1)
            break;
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String query = "name=yourname&email=youremail@yourserver.com";

    URLConnection uc = new URL("http:// your form ").openConnection();
    uc.setDoOutput(true);/*w  w  w  .j  a  v a  2  s . c  om*/
    uc.setDoInput(true);
    uc.setAllowUserInteraction(false);
    DataOutputStream dos = new DataOutputStream(uc.getOutputStream());

    // The POST line, the Accept line, and
    // the content-type headers are sent by the URLConnection.
    // We just need to send the data
    dos.writeBytes(query);
    dos.close();

    // Read the response
    DataInputStream dis = new DataInputStream(uc.getInputStream());
    String nextline;
    while ((nextline = dis.readLine()) != null) {
        System.out.println(nextline);
    }
    dis.close();
}

From source file:Main.java

public static void main(String args[]) {
    try {//w  w  w . j a va2  s.  c o m

        int port = 5555;
        ServerSocket ss = new ServerSocket(port);

        while (true) {
            // Accept incoming requests
            Socket s = ss.accept();

            // Write result to client
            OutputStream os = s.getOutputStream();
            DataOutputStream dos = new DataOutputStream(os);
            dos.writeInt(100);

            s.close();
        }
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}