// Path: send-notification/src/main/java/fr/jcgay/notification/Icon.java
// @AutoValue
// public abstract class Icon {
// 
//     /**
//      * A unique identifier. <br>
//      * You should ensure that this id will be unique because it can be used to temporary write file on disk.
//      *
//      * @return unique identifier.
//      */
//     public abstract String id();
// 
//     /**
//      * URL for this resource.
//      *
//      * @return URL to load icon.
//      */
//     public abstract URL content();
// 
//     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 String asPath() {
//         String folder = System.getProperty("java.io.tmpdir") + "/send-notifications-icons/";
//         String extension = extension();
//         File icon = new File(folder + id() + "." + extension);
//         if (!icon.exists()) {
//             new File(folder).mkdirs();
//             try {
//                 write(icon);
//             } catch (IOException e) {
//                 throw new SendNotificationException("Can't write notification icon : " + icon.getPath(), e);
//             }
//         }
//         return icon.getPath();
//     }
// 
//     public String extension() {
//         return content().getPath().substring(content().getPath().lastIndexOf(".") + 1);
//     }
// 
//     public static Icon create(URL content, String id) {
//         return new AutoValue_Icon(id, content);
//     }
// 
//     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);
//             }
//         }
//     }
// }
// 
// Path: send-notification/src/main/java/fr/jcgay/notification/IconFileWriter.java
// public interface IconFileWriter {
// 
//     void write(Icon icon);
// }
// 
// Path: send-notification/src/main/java/fr/jcgay/notification/SendNotificationException.java
// public class SendNotificationException extends RuntimeException {
// 
//     public SendNotificationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SendNotificationException(String message) {
//         super(message);
//     }
// }


import com.google.common.annotations.VisibleForTesting;
import fr.jcgay.notification.Icon;
import fr.jcgay.notification.IconFileWriter;
import fr.jcgay.notification.SendNotificationException;
import net.coobird.thumbnailator.Thumbnailator;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
package fr.jcgay.notification.notifier.anybar;



public class AnyBarIconWriter implements IconFileWriter {

    private final String destination;

    @VisibleForTesting
    AnyBarIconWriter(String destination) {
        this.destination = destination.endsWith("/") ? destination : destination + '/';
    }

    public AnyBarIconWriter() {
        this(System.getProperty("user.home") + "/.AnyBar/");
    }

    @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) {
// Path: send-notification/src/main/java/fr/jcgay/notification/Icon.java
// @AutoValue
// public abstract class Icon {
// 
//     /**
//      * A unique identifier. <br>
//      * You should ensure that this id will be unique because it can be used to temporary write file on disk.
//      *
//      * @return unique identifier.
//      */
//     public abstract String id();
// 
//     /**
//      * URL for this resource.
//      *
//      * @return URL to load icon.
//      */
//     public abstract URL content();
// 
//     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 String asPath() {
//         String folder = System.getProperty("java.io.tmpdir") + "/send-notifications-icons/";
//         String extension = extension();
//         File icon = new File(folder + id() + "." + extension);
//         if (!icon.exists()) {
//             new File(folder).mkdirs();
//             try {
//                 write(icon);
//             } catch (IOException e) {
//                 throw new SendNotificationException("Can't write notification icon : " + icon.getPath(), e);
//             }
//         }
//         return icon.getPath();
//     }
// 
//     public String extension() {
//         return content().getPath().substring(content().getPath().lastIndexOf(".") + 1);
//     }
// 
//     public static Icon create(URL content, String id) {
//         return new AutoValue_Icon(id, content);
//     }
// 
//     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);
//             }
//         }
//     }
// }
// 
// Path: send-notification/src/main/java/fr/jcgay/notification/IconFileWriter.java
// public interface IconFileWriter {
// 
//     void write(Icon icon);
// }
// 
// Path: send-notification/src/main/java/fr/jcgay/notification/SendNotificationException.java
// public class SendNotificationException extends RuntimeException {
// 
//     public SendNotificationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SendNotificationException(String message) {
//         super(message);
//     }
// }


// Path: send-notification/src/main/java/fr/jcgay/notification/notifier/anybar/AnyBarIconWriter.java
import com.google.common.annotations.VisibleForTesting;
import fr.jcgay.notification.Icon;
import fr.jcgay.notification.IconFileWriter;
import fr.jcgay.notification.SendNotificationException;
import net.coobird.thumbnailator.Thumbnailator;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

package fr.jcgay.notification.notifier.anybar;



public class AnyBarIconWriter implements IconFileWriter {

    private final String destination;

    @VisibleForTesting
    AnyBarIconWriter(String destination) {
        this.destination = destination.endsWith("/") ? destination : destination + '/';
    }

    public AnyBarIconWriter() {
        this(System.getProperty("user.home") + "/.AnyBar/");
    }

    @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);