} catch (IOException e) {
// could not download, ignore this error
return null;
}
Image img = null;
try {
ICOFile ico = new ICOFile(new FileInputStream(temp));
img = getBestIcon(ico, 16, 16);
} catch (Exception e) {
// Couldn't parse Icon-File. Maybe it's an Image
img = ImageIO.read(temp);
}
if (img != null) {
StringBuilder filename = new StringBuilder(Plugin.getPluginManager()
.getTvBrowserSettings().getTvBrowserUserHome());
filename.append(File.separator).append("WebFavIcons").append(
File.separator).append(urlString.substring(pos + 2)).append(".png");
File file = new File(filename.toString());
if (!file.getParentFile().exists()) {
try {
file.getParentFile().mkdirs();
} catch (Exception e) {
e.printStackTrace();
}
}
if ((img.getWidth(null) != 16) || (img.getHeight(null) != 16)) {
img = ((ImageIcon) UiUtilities.scaleIcon(new ImageIcon(img), 16, 16))
.getImage();
}
ImageIO.write(renderImage(img), "png", file);