ImageMetadataUtils { public static ImageMetadata extractMetadata(File img) { BufferedInputStream is = null; try { is = new BufferedInputStream(new FileInputStream(img)); return extractMetadata(is); } catch (FileNotFoundException e) { logger.warn("Tried to extract image metadata from none existing file '{}'", img.getName()); return null; } finally { IOUtils.closeQuietly(is); } } private  ImageMetadataUtils(); static ImageMetadata extractMetadata(File img); static ImageMetadata extractMetadata(BufferedInputStream img);  }
@Test public void testExtractMetadata() { File iptcImg = new File(ImageMetadataUtilsTest.class.getResource(iptcImage).getPath()); ImageMetadata iptcMeta = ImageMetadataUtils.extractMetadata(iptcImg); assertNull(iptcMeta.getCaption()); assertEquals(photographer, iptcMeta.getPhotographer()); assertEquals(2.8, iptcMeta.getFNumber(), 0.1f); assertEquals(200, iptcMeta.getFocalWidth()); assertEquals(1250, iptcMeta.getFilmspeed()); assertEquals(0.002, iptcMeta.getExposureTime(), 0.1f); File gpsImg = new File(ImageMetadataUtilsTest.class.getResource(gpsImage).getPath()); ImageMetadata gpsMeta = ImageMetadataUtils.extractMetadata(gpsImg); assertEquals(46.9338333333, gpsMeta.getGpsLat(), 0.1f); assertEquals(9.1316666667, gpsMeta.getGpsLong(), 0.1f); }