A function to safely cast a long to an int without relying on any external libraries.

From the brilliant Jon Skeet @ http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java