OutputStream out = new FileOutputStream(file);
xmlDoc.write(out);
out.close();
// Add thumbnail data for the browser:
RenderedImage thumb = engine.getRendering(new Dimension(320, 320));
// divorce the preview from the document
thumb = new CachedImage((PlanarImage) thumb, JAIContext.fileCache);
ImageInfo info = ImageInfo.getInstanceFor(file);
LZNImageType.INSTANCE.putImage(info, thumb);
// Cache a high resolution preview:
int size = PreviewUpdater.PreviewSize;
RenderedImage preview = engine.getRendering(new Dimension(size, size));
// divorce the preview from the document
preview = new CachedImage((PlanarImage) preview, JAIContext.fileCache);
PreviewUpdater.cachePreviewForImage(file, preview);
}