* @return content of the file as a byte array
* @throws Exception
*/
public static byte[] readFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(is);
long length = file.length();
if (length > Integer.MAX_VALUE)
throw new IOException("File is too large to read " + file.getName());
byte[] bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=bis.read(bytes, offset, bytes.length-offset)) >= 0)
offset += numRead;
// Ensure all the bytes have been read in
if (offset < bytes.length)
throw new IOException("Could not completely read file " + file.getName());
bis.close();
is.close();
return bytes;
}