Migrating from JDK 1.5.0_06 to 1.8.0_66 - Replacing the deprecated Java JPEG classes
<p>I am currently migrating an application from JDK 1.5.0_06 to 1.8.0_66. In the application, there are multiple files that use com.sun.image.codec.jpeg classes. When I try to create a JAR I'm getting the below error.</p>

<pre><code>error: package com.sun.image.codec.jpeg does not exist import com.sun.image.codec.jpeg.*;
</code></pre>

<p>I referred the blog on <a href="https://blog.idrsolutions.com/2012/05/replacing-the-deprecated-java-jpeg-classes-for-java-7/#comment-185733" rel="nofollow">Replacing the deprecated Java JPEG classes for Java 7</a> and my errors were cleared. But now I'm getting the warning below:</p>

<pre><code>warning: JPEGImageWriter is internal proprietary API and may be removed in a future release import com.sun.imageio.plugins.jpeg.JPEGImageWriter;
</code></pre>

<p>The problematic code from the blog:</p>

<pre><code>public static void saveAsJPEG(String jpgFlag, BufferedImage image_to_save, float JPEGcompression, FileOutputStream fos) throws IOException {
    // Image writer
    JPEGImageWriter imageWriter = (JPEGImageWriter) ImageIO.getImageWritersBySuffix("jpeg").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
    imageWriter.setOutput(ios);

    //and metadata
    IIOMetadata imageMetaData = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(image_to_save), null);

    if (jpgFlag != null) {
        int dpi = 96;

        try {
            dpi = Integer.parseInt(jpgFlag);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        //new metadata
        Element tree = (Element) imageMetaData.getAsTree("javax_imageio_jpeg_image_1.0");
        Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);
        jfif.setAttribute("Xdensity", Integer.toString(dpi));
        jfif.setAttribute("Ydensity", Integer.toString(dpi));
    }

    if (JPEGcompression &gt;= 0 &amp;&amp; JPEGcompression &lt;= 1f) {
        // new Compression
        JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam();
        jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
        jpegParams.setCompressionQuality(JPEGcompression);
    }

    //new Write and clean up
    imageWriter.write(imageMetaData, new IIOImage(image_to_save, null, null), null);
    ios.close();
    imageWriter.dispose();
}
</code></pre>