docs: public void flush() throws IOException {
          String outputType = getOutputContentType();
  
          // Force transcoding, if no other filtering is done
          if (outputType != null && !outputType.equals(originalContentType)) {
              getImage();
          }
  
          if (image != null) {
              Iterator writers = ImageIO.getImageWritersByMIMEType(outputType);
              if (writers.hasNext()) {
                  super.setContentType(outputType);
                  OutputStream out = super.getOutputStream();
                  try {
                      ImageWriter writer = (ImageWriter) writers.next();
                      try {
                          ImageWriteParam param = writer.getDefaultWriteParam();
      ///////////////////
      // POST-PROCESS
                          // For known formats that don't support transparency, convert to opaque
                          if (isNonAlphaFormat(outputType) && image.getColorModel().getTransparency() != Transparency.OPAQUE) {
                              image = ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_RGB);
                          }
  
                          Float requestQuality = (Float) originalRequest.getAttribute(ImageServletResponse.ATTRIB_OUTPUT_QUALITY);
  
                          // The default JPEG quality is not good enough, so always adjust compression/quality
                          if ((requestQuality != null || "jpeg".equalsIgnoreCase(getFormatNameSafe(writer))) && param.canWriteCompressed()) {
                              // TODO: See http://blog.apokalyptik.com/2009/09/16/quality-time-with-your-jpegs/ for better adjusting the (default) JPEG quality
                              // OR: Use the metadata of the original image
  
                              param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  
                              // WORKAROUND: Known bug in GIFImageWriter in certain JDK versions, compression type is not set by default
                              if (param.getCompressionTypes() != null && param.getCompressionType() == null) {
                                  param.setCompressionType(param.getCompressionTypes()[0]); // Just choose any, to keep param happy
                              }
  
                              param.setCompressionQuality(requestQuality != null ? requestQuality : 0.8f);
                          }
  
                          if ("gif".equalsIgnoreCase(getFormatNameSafe(writer)) && !(image.getColorModel() instanceof IndexColorModel) 
                                  /*&& image.getColorModel().getTransparency() != Transparency.OPAQUE*/) {
                              // WORKAROUND: Bug in GIFImageWriter may throw NPE if transparent pixels
                              // See: http://bugs.sun.com/view_bug.do?bug_id=6287936
                              image = ImageUtil.createIndexed(
                                      ImageUtil.toBuffered(image), 256, null,
                                      (image.getColorModel().getTransparency() == Transparency.OPAQUE ? ImageUtil.TRANSPARENCY_OPAQUE : ImageUtil.TRANSPARENCY_BITMASK) | ImageUtil.DITHER_DIFFUSION_ALTSCANS
                              );
                          }
      //////////////////
                          ImageOutputStream stream = ImageIO.createImageOutputStream(out);
  
                          writer.setOutput(stream);
                          try {
                              writer.write(null, new IIOImage(image, null, null), param);
                          }
                          finally {
                              stream.close();
                          }
                      }
                      finally {
                          writer.dispose();
                      }
                  }
                  finally {
                      out.flush();
                  }
              }
              else {
                  context.log("ERROR: No writer for content-type: " + outputType);
                  throw new IIOException("Unable to transcode image: No suitable image writer found (content-type: " + outputType + ").");
              }
          }
          else {
              super.setContentType(originalContentType);
  
              ServletOutputStream out = super.getOutputStream();
  
              try {
                  if (bufferedOut != null) {
                      bufferedOut.writeTo(out);
                  }
              }
              finally {
                  out.flush();
              }
          }
      }