private void write(File destination) throws IOException { try (InputStream input = content().openStream(); FileOutputStream output = new FileOutputStream(destination)) { byte[] buffer = new byte[1024 * 4]; int n; while ((n = input.read(buffer)) != -1) { output.write(buffer, 0, n); } } } }
private void write(File destination) throws IOException { try (InputStream input = content().openStream(); FileOutputStream output = new FileOutputStream(destination)) { byte[] buffer = new byte[1024 * 4]; int n; while ((n = input.read(buffer)) != -1) { output.write(buffer, 0, n); } } } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Icon) { Icon that = (Icon) o; return (this.id.equals(that.id())) && (this.content.equals(that.content())); } return false; }
public BufferedImage toImage() { try { return ImageIO.read(content()); } catch (IOException e) { throw new SendNotificationException("Error while reading status icon.", e); } }
public BufferedImage toImage() { try { return ImageIO.read(content()); } catch (IOException e) { throw new SendNotificationException("Error while reading status icon.", e); } }
public byte[] toByteArray() { try (InputStream is = content().openStream()) { return ByteStreams.toByteArray(is); } catch (IOException e) { throw new SendNotificationException("Error while reading status icon.", e); } }
public byte[] toByteArray() { try (InputStream is = content().openStream()) { return ByteStreams.toByteArray(is); } catch (IOException e) { throw new SendNotificationException("Error while reading status icon.", e); } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Icon) { Icon that = (Icon) o; return (this.id.equals(that.id())) && (this.content.equals(that.content())); } return false; }
@Override public void write(Icon icon) { for (Dimension dimension : Dimension.values()) { File resizedIcon = new File(destination + icon.id() + dimension.fileNameSuffix + "." + icon.extension()); if (!resizedIcon.exists()) { new File(destination).mkdirs(); try (InputStream input = icon.content().openStream(); FileOutputStream output = new FileOutputStream(resizedIcon)) { Thumbnailator.createThumbnail(input, output, dimension.width, dimension.height); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon: " + resizedIcon.getPath(), e); } } } }
@Override public void write(Icon icon) { for (Dimension dimension : Dimension.values()) { File resizedIcon = new File(destination + icon.id() + dimension.fileNameSuffix + "." + icon.extension()); if (!resizedIcon.exists()) { new File(destination).mkdirs(); try (InputStream input = icon.content().openStream(); FileOutputStream output = new FileOutputStream(resizedIcon)) { Thumbnailator.createThumbnail(input, output, dimension.width, dimension.height); } catch (IOException e) { throw new SendNotificationException("Can't write notification icon: " + resizedIcon.getPath(), e); } } } }