public static byte[] toByteArray(File file) throws IOException {
    FileInputStream in = null;
    try {
      in = new FileInputStream(file);
      return readFile(in, in.getChannel().size());
    } finally {
      if (in != null) {
        in.close();
      }
    }
  }
Reads all bytes from a file into a byte array.

@param file the file to read from
@return a byte array containing all the bytes from file
@throws IllegalArgumentException if the file is bigger than the largest possible byte array
    (2^31 - 1)
@throws IOException if an I/O error occurs
fbcore/src/main/java/com/facebook/common/internal/Files.java