/** * Convert a source to a BufferedImage. Source supported: * File,BufferedImage,InputStream,URL,ImageInputStream, byte[] * * @param imageType the ImageType to use * @param source source to generate BufferedImage from * @return Enhanced BufferedImage * @throws NullPointerException _ * @throws IOException _ * @throws UnsupportedOperationException throws this is the source is of unsupported type */ public static <T> BufferedImage convertImageType(final ImageType imageType, final T source) throws NullPointerException, IOException, UnsupportedOperationException { if (verifyNotNull(imageType, source)) { BufferedImage target = null; if (source instanceof File) { target = convert(ImageIO.read((File) source), imageType); } else if (source instanceof BufferedImage) { target = convert((BufferedImage) source, imageType); } else if (source instanceof InputStream) { target = convert(ImageIO.read((InputStream) source), imageType); } else if (source instanceof URL) { target = convert(ImageIO.read((URL) source), imageType); } else if (source instanceof ImageInputStream) { target = convert(ImageIO.read((ImageInputStream) source), imageType); } else if (source instanceof byte[]) { final InputStream streamOfInput = new ByteArrayInputStream((byte[]) source); target = convert(ImageIO.read(streamOfInput), imageType); } else { throw new UnsupportedOperationException("%s is not supported. Read JavaDoc."); } if (verifyNotNull(target)) { LOGGER.info( String.format( "Returning requested converted object<%s> as target", target.getClass().getName())); return target; } throw new NullPointerException("Return value was null."); } throw new NullPointerException("Nilled param detected. Please verify your params!"); }