Here you can find the source of readBytes(InputStream is)
public static int readBytes(InputStream is)
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { private static final Integer SANITY_CHECK_MAX_INT = 100000; public static int readBytes(InputStream is) { try {//from w ww. j a va 2 s .c om byte[] data = new byte[4]; is.read(data); int result = byteArrayToInt(data); if (result > SANITY_CHECK_MAX_INT) { throw new RuntimeException("Too large number"); } return result; } catch (Exception e) { throw new RuntimeException(e); } } public static int byteArrayToInt(byte[] bytes) { if (bytes.length != 4) { throw new RuntimeException("Not integer"); } return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getInt(); } }