public static void writeBufferedImage(BufferedImage image, String format, 
        OutputStream outputStream, float quality) throws IOException {
        ImageEncoder imageEncoder 
            = ImageEncoderFactory.newInstance(format, quality);
        imageEncoder.encode(image, outputStream);