PNGFileUtils { public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { Dimensions dimensions = null; final FileInputStream is = new FileInputStream(outFile); try { if (is.read() == 137 && is.read() == 80 && is.read() == 78) { is.skip(15); final int width = readIntBigEndianOnTwoBytes(is); is.skip(2); final int height = readIntBigEndianOnTwoBytes(is); dimensions = new Dimensions(height, width); } } finally { IOUtils.closeQuietly(is); } return dimensions; }  static Dimensions getDimensions(final File outFile);  }
@Test public void getDimensions_validPNGFile() throws Exception { Assertions.assertThat(PNGFileUtils.getDimensions(new File("src/test/resources/utils/png512x512.png"))) .isEqualTo(new Dimensions(512)); }
@Test public void getDimensions_invalidFile() throws Exception { Assertions.assertThat(PNGFileUtils.getDimensions(new File("src/test/resources/utils/jpg500x500.jpg"))).isNull(); }