20060626 Monday June 26, 2006

ImageIO: output == null!

Here is an interesting error:

java.lang.IllegalArgumentException: output == null!
 javax.imageio.ImageIO.write(ImageIO.java:1435)
 javax.imageio.ImageIO.write(ImageIO.java:1488)

Got this while trying to write an image. The error is actually due to a permissions problem (no write permission on the directory I was trying to save it to), but the exception gives you no clue about that.

Here is a link to the bug:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6247985

 

Posted by rickg ( Jun 26 2006, 06:16:14 AM PDT ) Permalink Comments [1]
20060613 Tuesday June 13, 2006

Serializing a DOM Document to a File

Here is a simple way to write a DOM document to an XML file:

Document document = ...
String filename = ...

Source source = new DOMSource(document);
File file = new File(filename);
Result result = new StreamResult(file);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);

This approach actually works for writing XML to just about any type of stream. Just pass it to the constructor for the StreamResult object.

 

Posted by rickg ( Jun 13 2006, 12:06:17 AM PDT ) Permalink Comments [0]