/**
* Accept a precomputed in-memory image to cache as the preview for
* an image file.
*/
public static void cachePreviewForImage(File file, RenderedImage image) {
final FileCache cache = FileCacheFactory.get(file);
if (cache == null) {
return;
}
// Write the given preview to the cache
final String key = getImageKey(file);
try {
final OutputStream out = cache.putToStream(key);
final OutputStreamImageDataReceiver receiver =
new OutputStreamImageDataReceiver(out);
try {
final LCJPEGWriter writer = new LCJPEGWriter(
receiver, 32 * 1024,
image.getWidth(), image.getHeight(),
image.getColorModel().getNumComponents(),
CS_RGB, 90
);
writer.putImage(image);
writer.dispose();
}
catch (LCImageLibException e) {
logNonFatalStatic(file, e, "caching preview");
cache.remove(key);
}
out.close();
receiver.dispose();
}
catch (IOException e) {