/** * Returns the bit length of the specified byte length, preventing * integer overflow. * * @param byteLength The byte length. * * @return The bit length. * * @throws IntegerOverflowException On a integer overflow. */ public static int safeBitLength(final int byteLength) throws IntegerOverflowException { long longResult = (long)byteLength * (long)8; if((long)((int)longResult) != longResult) { throw new IntegerOverflowException(); } else { return (int)longResult; } }