You could consider using mime-utils. It basically gives you the mime type for a given byte[] or stream source using the same detection that the unix file
command uses.
http://www.medsea.eu/mime-util (seems to be unavailable currently, try looking at the google cache for info).
You could also consider simply parsing every image using ImageIO.read and then rewriting them all using ImageIO.write. This will work for jpeg images too, althogh it isn't totally efficient. It would be an appropriate solution if you wanted to scale, crop or watermark your images at the same time. Since this is web submitted data, there is a certain argument for attempting to parse the file as image to make sure that it really is an image, and not a malicious file type.
ImageIO is smart so you don't have to know what type the data is to begin with. And it will through an exception if the data is malformed, so this makes sure that your image data is valid.
JPEG files apparently start with 0xFFD8, so you can just check for that in your code.
For example, to simply recode every image that doesn't look like a jpeg:
byte[] bytes = new byte[1024]; //your input
byte[] result = bytes;
if( bytes[0] != 0xFF || bytes[1] != 0xD8 )
{
BufferedImage image = ImageIO.read( new ByteArrayInputStream( bytes ) );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( image, "jpeg", baos );
result = baos.toByteArray();
}