Man, I wish it were this easy in all languages and platforms!
Where source would be either a filename or URL.
*same day edit*
Wow, that's a first I've had to update a post a few hours after putting it up.
There was a bug with filenames containing spaces, causing getFileExtensionsFromUrl() to return null.