private void loadIcon() { icon = new CraftIconCache(null); try { final File file = new File(new File("."), "server-icon.png"); if (file.isFile()) { icon = loadServerIcon0(file); } } catch (Exception ex) { getLogger().log(Level.WARNING, "Couldn't load server icon", ex); } }
@Override public CraftIconCache loadServerIcon(File file) throws Exception { Validate.notNull(file, "File cannot be null"); if (!file.isFile()) { throw new IllegalArgumentException(file + " is not a file"); } return loadServerIcon0(file); }
static CraftIconCache loadServerIcon0(BufferedImage image) throws Exception { ByteBuf bytebuf = Unpooled.buffer(); Validate.isTrue(image.getWidth() == 64, "Must be 64 pixels wide"); Validate.isTrue(image.getHeight() == 64, "Must be 64 pixels high"); ImageIO.write(image, "PNG", new ByteBufOutputStream(bytebuf)); ByteBuf bytebuf1 = Base64.encode(bytebuf); return new CraftIconCache("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8)); }