package lan.dk.podcastserver.service;


import lan.dk.podcastserver.entity.Cover;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * Created by kevin on 28/06/15 for Podcast Server
 */
@Slf4j
@Service
public class ImageService {

    private final UrlService urlService;

    @Autowired
    public ImageService(UrlService urlService) {
        this.urlService = urlService;
    }

    public Cover getCoverFromURL(String url) {
        if (StringUtils.isEmpty(url))
            return null;

        try {
            return getCoverFromURL(new URL(url));
        } catch (IOException e) {
            log.error("Error during fetching Cover information for {}", url, e);
            return null;
        }
    }

    public Cover getCoverFromURL (URL url) throws IOException {
        Cover cover = new Cover(url.toString());

        try (InputStream urlInputStream = urlService.getConnectionWithTimeOut(cover.getUrl(), 5000).getInputStream() ){
            ImageInputStream imageInputStream = ImageIO.createImageInputStream(urlInputStream);
            final BufferedImage image = ImageIO.read(imageInputStream);
            cover.setWidth(image.getWidth());
            cover.setHeight(image.getHeight());
        }

        return cover;
    }
}

@@ -75,16 +75,55 @@
 .Cover;%0A
+import lombok.RequiredArgsConstructor;%0A
 import l
@@ -574,83 +574,53 @@
 ice%0A
-public class ImageService %7B%0A%0A    private final UrlService urlService;%0A%0A    
+@RequiredArgsConstructor(onConstructor = @__(
 @Aut
@@ -625,28 +625,32 @@
 utowired
-%0A    
+))%0A
 public 
+class 
 ImageSer
@@ -657,48 +657,23 @@
 vice
-(UrlService urlService) %7B%0A        this.u
+ %7B%0A%0A    final U
 rlSe
@@ -677,18 +677,16 @@
 lService
- =
  urlServ
@@ -689,22 +689,16 @@
 Service;
-%0A    %7D
 %0A%0A    pu

use annotation to define constructor