Example usage for javax.imageio IIOException getCause

List of usage examples for javax.imageio IIOException getCause

Introduction

In this page you can find the example usage for javax.imageio IIOException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:edu.harvard.iq.dvn.core.web.ExploreDataPage.java

private void writeImageFile(File fileIn, File pdfFileIn) {

    File imagePngFile = null;/*from w  w  w  .j  a va 2s . c  o m*/

    try {
        String decoded = URLDecoder.decode(imageURL, "UTF-8");

        if (!decoded.isEmpty()) {
            URL imageURLnew = new URL(imageURL);

            try {
                BufferedImage image = ImageIO.read(imageURLnew);

                BufferedImage combinedImage = getCompositeImage(image);

                if (fileIn != null) {
                    ImageIO.write(combinedImage, "png", fileIn);
                }

                if (pdfFileIn != null) {
                    imagePngFile = File.createTempFile("pdfDownload", "png");
                    ImageIO.write(combinedImage, "png", imagePngFile);
                    Document convertPngToPdf = new Document();
                    PdfWriter.getInstance(convertPngToPdf, new FileOutputStream(pdfFileIn, true));
                    convertPngToPdf.open();
                    Image convertBmp = PngImage.getImage(imagePngFile.getAbsolutePath());
                    convertBmp.scaleToFit(530f, 500f);
                    convertPngToPdf.add(convertBmp);
                    convertPngToPdf.close();
                }
            } catch (IIOException io) {
                System.out.println(io.getMessage().toString());
                System.out.println(io.getCause().toString());
                System.out.println("IIOException " + imageURLnew);

            } catch (FontFormatException ff) {
                System.out.println("FontFormatException " + imageURLnew);

                System.out.println("FontFormatException " + ff.toString());
            }
        }

    } catch (UnsupportedEncodingException uee) {
        System.out.println("UnsupportedEncodingException ");
    } catch (MalformedURLException mue) {
        System.out.println("MalformedURLException ");
    } catch (IOException io) {
        System.out.println("IOException - outer ");
    } catch (DocumentException io) {
        System.out.println("IOException - document ");
        System.out.println(io.getMessage());
    } finally {
        if (imagePngFile != null && imagePngFile.exists()) {
            if (!FileUtil.keepTempFiles("core.web.ExploreDataPage")) {
                imagePngFile.delete();
            }
        }
    }
}