code: protected static int readInt(InputStream input, int bytesNumber, boolean bigEndian) throws IOException
      {
          final int oneByte = 8;
          int ret = 0;
          int sv;
          if (bigEndian)
          {
              sv = (bytesNumber - 1) * oneByte;
          }
          else
          {
              sv = 0;
          }
          final int cnt;
          if (bigEndian)
          {
              cnt = -oneByte;
          }
          else
          {
              cnt = oneByte;
          }
          for (int i = 0; i < bytesNumber; i++)
          {
              ret |= input.read() << sv;
              sv += cnt;
          }
          return ret;
      }
docs: Read integer in image data.
  
  @param input The stream.
  @param bytesNumber The number of bytes to read.
  @param bigEndian The big endian flag.
  @return The integer read.
  @throws IOException if error on reading.