package com.kennycason.kumo;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
*Class to process image with a required size.
*
* the static method {@link #readImage(String fileName, int width, int height, String imageType)}
* can read the path of the file and resize the image
 */
public final class ImageProcessor {

    private ImageProcessor(){}
    private static ImageProcessor imageProcessor = new ImageProcessor();
    public static ImageProcessor getInstance(){
        return imageProcessor;
    }
    /**
    *@param fileName is the path of the file
     * @param imageType can define the type of image
     * @param width is the resized image's width
     * @param height is the resized image's height
     * @return the resized image in ByteArrayInputStream form
     */
    public static InputStream readImage(String fileName, int width, int height, String imageType) throws IOException, InterruptedException {
        BufferedImage originImage;
        originImage = ImageIO.read(getInputStream(fileName));

        Image scaledImage = originImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        BufferedImage bufferedImage;

        bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);


        Graphics graphics = bufferedImage.getGraphics();
        graphics.drawImage(scaledImage, 0, 0, null);


        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, imageType, outputStream);
        return new ByteArrayInputStream(outputStream.toByteArray());
    }
    private static InputStream getInputStream(final String path) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
    }

}

@@ -1069,30 +1069,8 @@
 tion
-, InterruptedException
  %7B%0A 
@@ -1068,32 +1068,38 @@
 ption %7B%0A        
+final 
 BufferedImage or
@@ -1100,29 +1100,8 @@
 age 
-originImage;%0A        
 orig
@@ -1150,24 +1150,29 @@
 Name));%0A
-%0A
+ 
        
+final
  Image s
@@ -1262,23 +1262,15 @@
     
-BufferedImage b
+final B
 uffe
@@ -1281,18 +1281,8 @@
 mage
-;%0A%0A       
  buf
@@ -1369,16 +1369,22 @@
         
+final 
 Graphics
@@ -1487,16 +1487,22 @@
         
+final 
 ByteArra
@@ -1693,24 +1693,29 @@
 y());%0A    %7D%0A
+    %0A
     private 

Update ImageProcessor.java