code: public static boolean write(RenderedImage im, String formatName, ImageOutputStream output) throws IOException {
  		if (im == null) {
  			throw new IllegalArgumentException("im == null!");
  		}
  		if (formatName == null) {
  			throw new IllegalArgumentException("formatName == null!");
  		}
  		if (output == null) {
  			throw new IllegalArgumentException("output == null!");
  		}
  
  		ImageWriter writer = null;
  		ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(im);
  		Iterator iter = getImageWriters(type, formatName);
  		if (iter.hasNext()) {
  			writer = (ImageWriter) iter.next();
  		}
  		if (writer == null) {
  			return false;
  		}
  
  		writer.setOutput(output);
  		try {
  			writer.write(im);
  		} finally {
  			writer.dispose();
  			output.flush();
  		}
  
  		return true;
  	}
docs: Writes an image using the an arbitrary <code>ImageWriter</code> that supports the given format to an
  <code>ImageOutputStream</code>. The image is written to the <code>ImageOutputStream</code> starting at
  the current stream pointer, overwriting existing stream data from that point forward, if present.
  
  <p>
  This method <em>does not</em> close the provided <code>ImageOutputStream</code> after the write
  operation has completed; it is the responsibility of the caller to close the stream, if desired.
  
  @param im
  a <code>RenderedImage</code> to be written.
  @param formatName
  a <code>String</code> containg the informal name of the format.
  @param output
  an <code>ImageOutputStream</code> to be written to.
  
  @return <code>false</code> if no appropriate writer is found.
  
  @exception IllegalArgumentException
  if any parameter is <code>null</code>.
  @exception IOException
  if an error occurs during writing.