title: How to handle unsigned shorts/ints/longs in Java
body: <p>I'm reading a file format that specifies some types are unsigned integers and shorts. When I read the values, I get them as a byte array. The best route to turning them into shorts/ints/longs I've seen is something like this:</p>
  
  <pre><code>ByteBuffer wrapped = ByteBuffer.wrap(byteArray);
  int x = wrapped.getInt();
  </code></pre>
  
  <p>That looks like it could easily overflow for unsigned ints. Is there a better way to handle this scenario?</p>
  
  <p><strong>Update</strong>: I should mention that I'm using Groovy, so I absolutely don't care if I have to use a <code>BigInteger</code> or something like that. I just want the maximum safety on keeping the value intact.</p>