public static void storeImage(long id, byte[] bytes, ImageDescriptor defaultImage, int wHint, int hHint) {
Assert.isNotNull(defaultImage);
Assert.isLegal(wHint > 0);
Assert.isLegal(hHint > 0);
ImageData imgData = null;
/* Bytes Provided */
if (bytes != null && bytes.length > 0) {
ByteArrayInputStream inS = null;
try {
inS = new ByteArrayInputStream(bytes);
ImageLoader loader = new ImageLoader();
ImageData[] imageDatas = loader.load(inS);
/* Look for the Icon with the best quality */
if (imageDatas != null)
imgData = getBestQuality(imageDatas, wHint, hHint);
} catch (SWTException e) {
/* Ignore any Image-Format exceptions */
} finally {
if (inS != null) {
try {
inS.close();
} catch (IOException e) {
if (!(e instanceof MonitorCanceledException))
Activator.getDefault().logError(e.getMessage(), e);
}
}
}
}
/* Use default Image if img-data is null */
if (imgData == null)
imgData = defaultImage.getImageData();
/* Save Image into Cache-Area on File-System */
if (imgData != null) {
File imageFile = getImageFile(id);
if (imageFile == null)
return;
/* Scale if required */
if (imgData.width != 16 || imgData.height != 16)
imgData = imgData.scaledTo(16, 16);
/* Try using native Image Format */
try {
if (storeImage(imgData, imageFile, imgData.type))
return;