title: Fast reading of little endian integers from file
body: <p>I need to read a binary file consisting of 4 byte integers (little endian) into a 2D array for my Android application. My current solution is the following:</p>
  
  <pre><code>DataInputStream inp = null;
  try {
      inp = new DataInputStream(new BufferedInputStream(new FileInputStream(procData), 32768));
  }
  catch (FileNotFoundException e) {
      Log.e(TAG, "File not found");
  }
  
  int[][] test_data = new int[SIZE_X][SIZE_Y];
  byte[] buffer = new byte[4];
  ByteBuffer byteBuffer = ByteBuffer.allocate(4);
  for (int i=0; i &lt; SIZE_Y; i++) {
      for (int j=0; j &lt; SIZE_X; j++) {
          inp.read(buffer);
          byteBuffer = ByteBuffer.wrap(buffer);
          test_data[j][SIZE_Y - i - 1] = byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getInt();
      }
  }
  </code></pre>
  
  <p>This is pretty slow for a 2k*2k array, it takes about 25 seconds.  I can see in the DDMS that the garbage collector is working overtime, so that is probably one reason for the slowness.</p>
  
  <p>There has to be a more efficient way of using the ByteBuffer to read that file into the array, but I'm not seeing it at the moment. Any idea on how to speed this up?</p>