/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ami.converter.jpeg;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;

/**
 *
 * @author Andrias
 */
public class JpegEncoder {
    public void encodeJPEG(String sourcePath, String destinationPath) throws IOException {
        File sourceFile = new File(sourcePath);
        File destinationFile = new File(destinationPath);
        
        BufferedImage bufferedImage = ImageIO.read(sourceFile);
        
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(1);
        
        FileImageOutputStream output = new FileImageOutputStream(destinationFile);
        writer.setOutput(output);
        
        IIOImage image = new IIOImage(bufferedImage, null, null);
        writer.write(null, image, iwp);
        writer.dispose();
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ami.converter.jpeg;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;

/**
 *
 * @author Andrias
 */
public class JpegEncoder {

    /**
     *
     * @param sourcePath
     * @param destinationPath
     * @throws IOException
     */
    public void encodeJPEG(String sourcePath, String destinationPath) throws IOException {
        File sourceFile = new File(sourcePath);
        File destinationFile = new File(destinationPath);
        
        BufferedImage bufferedImage = ImageIO.read(sourceFile);
        
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(1);
        
        FileImageOutputStream output = new FileImageOutputStream(destinationFile);
        writer.setOutput(output);
        
        IIOImage image = new IIOImage(bufferedImage, null, null);
        writer.write(null, image, iwp);
        writer.dispose();
    }
}

add Javadoc for encodeJPEG() function