Example usage for java.io DataInputStream available

List of usage examples for java.io DataInputStream available

Introduction

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

Prototype

public int available() throws IOException 

Source Link

Document

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    byte[] buf = { 1, 2, 3, 4, 5 };

    InputStream is = new ByteArrayInputStream(buf);

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        byte b = dis.readByte();
        System.out.print(b);//from  ww  w .  ja v a2 s. c  o  m
    }

}

From source file:Main.java

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

    byte[] buf = { 1, 2, 3, 4, 5 };

    InputStream is = new ByteArrayInputStream(buf);

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        System.out.println(dis.readBoolean());
    }/*w ww .  jav  a 2 s . c o m*/

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    short[] s = { -5, 32767 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (short j : s) {
        dos.writeShort(j);//w w w .  j  a v a2s . c  o m
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        int k = dis.readUnsignedShort();
        System.out.print(k);
    }
}

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69, 70 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (byte b : buf) {
        dos.writeChar(b);/*from  www  . j  ava2s . c  o  m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        char c = dis.readChar();
        System.out.print(c);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String[] s = { "Hello", "tutorial from java2s.com!!" };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (String j : s) {
        dos.writeUTF(j);//from   w  w w . ja  v a 2  s . c om
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }

}

From source file:Main.java

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

    long[] l = { 1234567890L, 987654321L };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (long j : l) {
        dos.writeLong(j);/*from  w  w  w. j a  v a  2s . c om*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        long k = dis.readLong();
        System.out.print(k);
    }
}

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 .  j  a v a  2s .  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[] i = { 123, 234, 454, 567, 789 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (int j : i) {
        dos.writeInt(j);/*from   w  ww.j  av a 2s.  c  o  m*/
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        int k = dis.readInt();
        System.out.print(k);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    int length = dis.available();

    byte[] buf = new byte[length];

    dis.readFully(buf);//from  w ww  .  ja  v  a2  s .  c  om

    for (byte b : buf) {
        char c = (char) b;
        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    short[] s = { 12345, 12345 };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (short j : s) {
        dos.writeShort(j);//from  www .  j  a v  a 2 s  .  c  o m
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        short k = dis.readShort();
        System.out.print(k);
    }

}