resize image to fixed size, add border if needed
===

I need to make images I downloaded from flickr to fit into a 500x500 shape. If the aspect ratio is not 1:1 than black bars should be added to top / bottom or left / right to fill empty space. Transparent background could also work. Important is 500x500 and resizing without cropping. how can I do it in java? 