Example usage for java.io DataInputStream readByte

List of usage examples for java.io DataInputStream readByte

Introduction

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

Prototype

public final byte readByte() throws IOException 

Source Link

Document

See the general contract of the readByte method of DataInput.

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);/*w  w  w  .  j  a v  a 2  s  .  c o  m*/
    }

}

From source file:Main.java

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

    DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes()));
    System.out.print((char) in3.readByte());
    in3.close();//from  w w w .  ja va  2s  .  c om
}

From source file:MainClass.java

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

    try {/*  w w w .  jav a  2 s. c  o  m*/
        DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes()));
        while (true)
            System.out.print((char) in3.readByte());
    } catch (EOFException e) {
        System.err.println("End of stream");
    }

}

From source file:TestEOF.java

public static void main(String[] args) throws IOException {
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("TestEOF.java")));
    while (in.available() != 0)
        System.out.print((char) in.readByte());
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/* w  ww .j  a  va2s .  com*/

        FileInputStream fis = new FileInputStream("fileName.dat");

        // Create a data input stream
        DataInputStream dis = new DataInputStream(fis);

        // Read and display data
        System.out.println(dis.readBoolean());
        System.out.println(dis.readByte());
        System.out.println(dis.readChar());
        System.out.println(dis.readDouble());
        System.out.println(dis.readFloat());
        System.out.println(dis.readInt());
        System.out.println(dis.readLong());
        System.out.println(dis.readShort());

        // Close file input stream
        fis.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:EOF.java

public static void main(String args[]) {
    DataInputStream is = null;
    byte ch;/* w  ww  .  j a va  2 s  . c o m*/
    try {
        is = new DataInputStream(new FileInputStream("EOF.java"));
        while (true) { // exception deals catches EOF
            ch = is.readByte();
            System.out.print((char) ch);
            System.out.flush();
        }
    } catch (EOFException eof) {
        System.out.println(" >> Normal program termination.");
    } catch (FileNotFoundException noFile) {
        System.err.println("File not found! " + noFile);
    } catch (IOException io) {
        System.err.println("I/O error occurred: " + io);
    } catch (Throwable anything) {
        System.err.println("Abnormal exception caught !: " + anything);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("myfile.dat");

    DataInputStream din = new DataInputStream(fin);
    while (true) {
        int theNumber = din.readInt();
        //double theNumber = din.readDouble();
        //System.out.println(din.readUTF());
        //boolean b = din.readBoolean();
        byte b = din.readByte();
        System.out.println("byte : " + b);
        System.out.println(theNumber);

        char ch = din.readChar();
        System.out.println("Char : " + ch);
        float f = din.readFloat();
        System.out.println("float : " + f);
        long l = din.readLong();
        System.out.println("long : " + l);

    }/*w  w w .  j  a  v  a  2  s  .  c  om*/
}

From source file:Main.java

protected static int deserialiseLength(DataInputStream is, int max_length)

        throws IOException {
    int len;//from   w ww .j av  a  2  s. co  m

    if (max_length < 256) {

        len = is.readByte() & 0xff;

    } else if (max_length < 65536) {

        len = is.readShort() & 0xffff;

    } else {

        len = is.readInt();
    }

    if (len > max_length) {

        throw (new IOException("Invalid DHT data length: max=" + max_length + ",actual=" + len));
    }

    return (len);
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

public static Object getObject(DataInputStream data) throws IOException {
    // TODO Auto-generated method stub
    byte objID = data.readByte();

    if (objID == JSONKafkaSerializer.StringID)
        return getString(data);

    if (objID == JSONKafkaSerializer.JSONObjectID)
        return getJSON(data);

    if (objID == JSONKafkaSerializer.NumberID)
        return getNumber(data);

    if (objID == JSONKafkaSerializer.BooleanID)
        return getBoolean(data);

    if (objID == JSONKafkaSerializer.NULLID)
        return null;

    if (objID == JSONKafkaSerializer.JSONArrayID)
        return getArray(data);

    return null;//from  w  w w  .  j av  a2  s . c  o m
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

public static Number getNumber(DataInputStream data) throws IOException {
    // Treating all ints,shorts, long as long.
    // Everything else as Double
    int flag = data.readByte();
    if (flag == 0)
        return data.readDouble();

    return data.readLong();
}