title: Converting byte array to int array in Java, via ByteBuffer to IntBuffer, without truncating
body: <p>There are other questions posted here on this topic, most of which involve <code>ByteBuffer</code> and <code>asIntBuffer</code>. However, I have not seen any explaination on how to keep the value from truncating when converting to an <code>IntBuffer</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>byte[] plainTextBytes = "Hello World".getBytes();
  
  // Truncates the limit from 11 to 2
  IntBuffer intBuffer = ByteBuffer.wrap( plainTextBytes ).asIntBuffer();
  
  // Results in java.lang.UnsupportedOperationException
  int[] plainTextInt = intBuffer.array();
  </code></pre>
  
  <p>I have an RC4 encryption algorithm which takes a plaintext argument of type <code>int[]</code>. Hence, I need to convert the plaintext into <code>int[]</code>. The problem with <code>ByteBuffer</code> and the use of <code>asIntBuffer</code> is the plaintext is being truncated because the limit is independent (goes from 11 to 2, in my example).</p>
  
  <p>Either I'm doing something wrong or <code>ByteBuffer</code> is not the way to go here.</p>
  
  <p>Any help would be appreciated. Thank you.</p>