read Int from InputStream - Java java.io

Java examples for java.io:InputStream Read

Description

read Int from InputStream

Demo Code


//package com.java2s;

import java.io.EOFException;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static int readInt(InputStream in) throws IOException {
        int ch1 = in.read();
        int ch2 = in.read();
        int ch3 = in.read();
        int ch4 = in.read();
        if ((ch1 | ch2 | ch3 | ch4) < 0)
            throw new EOFException();
        return ((ch1 << 24) | (ch2 << 16) | (ch3 << 8) | ch4);
    }/*from w  ww.  j av a  2s .com*/
}

Related Tutorials