java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java
changeset 15 93fa6ce675e5
parent 14 dec0dd934a64
child 17 505031965440
     1.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java	Mon Nov 17 20:23:58 2014 +0100
     1.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java	Mon Nov 17 20:38:38 2014 +0100
     1.3 @@ -18,18 +18,15 @@
     1.4  package cz.frantovo.copyImageResizer;
     1.5  
     1.6  import cz.frantovo.copyImageResizer.SingleImageResizer.ImageFormat;
     1.7 -import java.awt.image.BufferedImage;
     1.8  import java.io.File;
     1.9  import java.io.FileInputStream;
    1.10  import java.io.FileNotFoundException;
    1.11  import java.io.FileOutputStream;
    1.12  import java.io.IOException;
    1.13 -import java.io.InputStream;
    1.14  import java.nio.channels.FileChannel;
    1.15  import java.util.logging.Level;
    1.16  import java.util.logging.LogRecord;
    1.17  import java.util.logging.Logger;
    1.18 -import javax.imageio.ImageIO;
    1.19  
    1.20  /**
    1.21   *
    1.22 @@ -70,16 +67,16 @@
    1.23  					File sizeRoot = new File(options.getOutput(), size.getDirectory());
    1.24  					File outputFile = new File(sizeRoot, inputFileRelative.getPath());
    1.25  					try (FileInputStream input = new FileInputStream(inputFile)) {
    1.26 -						BufferedImage image = readImage(input);
    1.27 -						if (shouldResize(image, size)) {
    1.28 -							try (FileOutputStream output = new FileOutputStream(outputFile)) {
    1.29 -								resizer.resize(image, output, size, format);
    1.30 +
    1.31 +						try (FileOutputStream output = new FileOutputStream(outputFile)) {
    1.32 +							boolean wasResized = resizer.resize(input, output, size, format);
    1.33 +							if (wasResized) {
    1.34  								counters.increment(Counters.COUNTER_TYPE.RESIZED);
    1.35 +							} else {
    1.36 +								log.log(Level.FINER, "File: {0} has already required (or smaller) size → just copy", inputFileRelative);
    1.37 +								justCopy(inputFile, outputFile);
    1.38 +								counters.increment(Counters.COUNTER_TYPE.JUST_COPIED);
    1.39  							}
    1.40 -						} else {
    1.41 -							log.log(Level.FINER, "File: {0} has already required (or smaller) size → just copy", inputFileRelative);
    1.42 -							justCopy(inputFile, outputFile);
    1.43 -							counters.increment(Counters.COUNTER_TYPE.JUST_COPIED);
    1.44  						}
    1.45  					}
    1.46  				}
    1.47 @@ -91,22 +88,6 @@
    1.48  		}
    1.49  	}
    1.50  
    1.51 -	private static boolean shouldResize(BufferedImage input, SizeSpecification requested) {
    1.52 -		if (requested.isResizeSmaller()) {
    1.53 -			return input.getHeight() != requested.getHeight() || input.getWidth() != requested.getWidth();
    1.54 -		} else {
    1.55 -			return input.getHeight() > requested.getHeight() || input.getWidth() > requested.getWidth();
    1.56 -		}
    1.57 -	}
    1.58 -
    1.59 -	private static BufferedImage readImage(InputStream input) throws ResizeException {
    1.60 -		try {
    1.61 -			return ImageIO.read(input);
    1.62 -		} catch (IOException e) {
    1.63 -			throw new ResizeException("Unable to read image from stream", e);
    1.64 -		}
    1.65 -	}
    1.66 -
    1.67  	private static void justCopy(File inputFile, File outputFile) throws ResizeException {
    1.68  		try {
    1.69