backport to support java 1.4 and implement ImageIO.Write function