in src/main/java/com/intellij/util/ui/UIUtilities.java [1291:1357]
public static Object makeIcon(final Class<?> baseClass,
final Class<?> rootClass,
final String imageFile) {
return new UIDefaults.LazyValue() {
public Object createValue(UIDefaults table) {
/* Copy resource into a byte array. This is
* necessary because several browsers consider
* Class.getResource a security risk because it
* can be used to load additional classes.
* Class.getResourceAsStream just returns raw
* bytes, which we can convert to an image.
*/
byte[] buffer =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<byte[]>() {
public byte[] run() {
try {
InputStream resource = null;
Class<?> srchClass = baseClass;
while (srchClass != null) {
resource = srchClass.getResourceAsStream(imageFile);
if (resource != null || srchClass == rootClass) {
break;
}
srchClass = srchClass.getSuperclass();
}
if (resource == null) {
return null;
}
BufferedInputStream in =
new BufferedInputStream(resource);
ByteArrayOutputStream out =
new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int n;
while ((n = in.read(buffer)) > 0) {
out.write(buffer, 0, n);
}
in.close();
out.flush();
return out.toByteArray();
} catch (IOException ioe) {
System.err.println(ioe.toString());
}
return null;
}
});
if (buffer == null) {
return null;
}
if (buffer.length == 0) {
System.err.println("warning: " + imageFile +
" is zero-length");
return null;
}
return new ImageIconUIResource(buffer);
}
};
}