recursive resizer classes
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 16 Nov 2014 23:47:28 +0100
changeset 55019e3e93a4e
parent 4 f3b4caf1d05d
child 6 b329573c76d7
recursive resizer classes
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveException.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveOptions.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/ResizeException.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIOptions.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveException.java	Sun Nov 16 23:47:28 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/**
     1.5 + * copy-image-resizer
     1.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, either version 3 of the License, or
    1.11 + * (at your option) any later version.
    1.12 + *
    1.13 + * This program is distributed in the hope that it will be useful,
    1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 + * GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License
    1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +package cz.frantovo.copyImageResizer;
    1.22 +
    1.23 +/**
    1.24 + * Some problem with recursive directory/files processing.
    1.25 + *
    1.26 + * @author Ing. František Kučera (frantovo.cz)
    1.27 + */
    1.28 +public class RecursiveException extends CopyImageResizerException {
    1.29 +
    1.30 +	public RecursiveException() {
    1.31 +	}
    1.32 +
    1.33 +	public RecursiveException(String message) {
    1.34 +		super(message);
    1.35 +	}
    1.36 +
    1.37 +	public RecursiveException(Throwable cause) {
    1.38 +		super(cause);
    1.39 +	}
    1.40 +
    1.41 +	public RecursiveException(String message, Throwable cause) {
    1.42 +		super(message, cause);
    1.43 +	}
    1.44 +
    1.45 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveImageResizer.java	Sun Nov 16 23:47:28 2014 +0100
     2.3 @@ -0,0 +1,29 @@
     2.4 +/**
     2.5 + * copy-image-resizer
     2.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package cz.frantovo.copyImageResizer;
    2.22 +
    2.23 +/**
    2.24 + *
    2.25 + * @author Ing. František Kučera (frantovo.cz)
    2.26 + */
    2.27 +public class RecursiveImageResizer {
    2.28 +
    2.29 +	public void resize(RecursiveOptions options) throws RecursiveException, ResizeException {
    2.30 +	}
    2.31 +
    2.32 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/RecursiveOptions.java	Sun Nov 16 23:47:28 2014 +0100
     3.3 @@ -0,0 +1,91 @@
     3.4 +/**
     3.5 + * copy-image-resizer
     3.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, either version 3 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    3.16 + * GNU General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    3.20 + */
    3.21 +package cz.frantovo.copyImageResizer;
    3.22 +
    3.23 +import java.io.File;
    3.24 +import java.util.ArrayList;
    3.25 +import java.util.Collection;
    3.26 +
    3.27 +/**
    3.28 + * 
    3.29 + * @author Ing. František Kučera (frantovo.cz)
    3.30 + */
    3.31 +public class RecursiveOptions {
    3.32 +
    3.33 +	/**
    3.34 +	 * Source directory
    3.35 +	 */
    3.36 +	private File input;
    3.37 +	/**
    3.38 +	 * Output directory
    3.39 +	 */
    3.40 +	private File output;
    3.41 +	/**
    3.42 +	 * Image resolutions to create
    3.43 +	 */
    3.44 +	private final Collection<SizeSpecification> sizes = new ArrayList<>();
    3.45 +
    3.46 +	public File getSourceDir() {
    3.47 +		return input;
    3.48 +	}
    3.49 +
    3.50 +	public void setInput(File input) {
    3.51 +		this.input = input;
    3.52 +	}
    3.53 +
    3.54 +	public File getDestinationDir() {
    3.55 +		return output;
    3.56 +	}
    3.57 +
    3.58 +	public void setOutput(File output) {
    3.59 +		this.output = output;
    3.60 +	}
    3.61 +
    3.62 +	public Collection<SizeSpecification> getSizes() {
    3.63 +		return sizes;
    3.64 +	}
    3.65 +
    3.66 +	public void addSize(SizeSpecification size) {
    3.67 +		sizes.add(size);
    3.68 +	}
    3.69 +
    3.70 +	public static class SizeSpecification {
    3.71 +
    3.72 +		private final int width;
    3.73 +		private final int height;
    3.74 +		private final String directory;
    3.75 +
    3.76 +		public SizeSpecification(int width, int height, String directory) {
    3.77 +			this.width = width;
    3.78 +			this.height = height;
    3.79 +			this.directory = directory;
    3.80 +		}
    3.81 +
    3.82 +		public int getWidth() {
    3.83 +			return width;
    3.84 +		}
    3.85 +
    3.86 +		public int getHeight() {
    3.87 +			return height;
    3.88 +		}
    3.89 +
    3.90 +		public String getDirectory() {
    3.91 +			return directory;
    3.92 +		}
    3.93 +	}
    3.94 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/ResizeException.java	Sun Nov 16 23:47:28 2014 +0100
     4.3 @@ -0,0 +1,42 @@
     4.4 +/**
     4.5 + * copy-image-resizer
     4.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, either version 3 of the License, or
    4.11 + * (at your option) any later version.
    4.12 + *
    4.13 + * This program is distributed in the hope that it will be useful,
    4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    4.16 + * GNU General Public License for more details.
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License
    4.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    4.20 + */
    4.21 +package cz.frantovo.copyImageResizer;
    4.22 +
    4.23 +/**
    4.24 + * Some problem with resizing particular image.
    4.25 + *
    4.26 + * @author Ing. František Kučera (frantovo.cz)
    4.27 + */
    4.28 +public class ResizeException extends CopyImageResizerException {
    4.29 +
    4.30 +	public ResizeException() {
    4.31 +	}
    4.32 +
    4.33 +	public ResizeException(String message) {
    4.34 +		super(message);
    4.35 +	}
    4.36 +
    4.37 +	public ResizeException(Throwable cause) {
    4.38 +		super(cause);
    4.39 +	}
    4.40 +
    4.41 +	public ResizeException(String message, Throwable cause) {
    4.42 +		super(message, cause);
    4.43 +	}
    4.44 +
    4.45 +}
     5.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIOptions.java	Sun Nov 16 21:59:13 2014 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,91 +0,0 @@
     5.4 -/**
     5.5 - * copy-image-resizer
     5.6 - * Copyright © 2014 František Kučera (frantovo.cz)
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License as published by
    5.10 - * the Free Software Foundation, either version 3 of the License, or
    5.11 - * (at your option) any later version.
    5.12 - *
    5.13 - * This program is distributed in the hope that it will be useful,
    5.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    5.16 - * GNU General Public License for more details.
    5.17 - *
    5.18 - * You should have received a copy of the GNU General Public License
    5.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    5.20 - */
    5.21 -package cz.frantovo.copyImageResizer.cli;
    5.22 -
    5.23 -import java.io.File;
    5.24 -import java.util.ArrayList;
    5.25 -import java.util.Collection;
    5.26 -
    5.27 -/**
    5.28 - *
    5.29 - * @author Ing. František Kučera (frantovo.cz)
    5.30 - */
    5.31 -public class CLIOptions {
    5.32 -
    5.33 -	/**
    5.34 -	 * Source directory
    5.35 -	 */
    5.36 -	private File input;
    5.37 -	/**
    5.38 -	 * Output directory
    5.39 -	 */
    5.40 -	private File output;
    5.41 -	/**
    5.42 -	 * Image resolutions to create
    5.43 -	 */
    5.44 -	private final Collection<SizeSpecification> sizes = new ArrayList<>();
    5.45 -
    5.46 -	public File getSourceDir() {
    5.47 -		return input;
    5.48 -	}
    5.49 -
    5.50 -	public void setInput(File input) {
    5.51 -		this.input = input;
    5.52 -	}
    5.53 -
    5.54 -	public File getDestinationDir() {
    5.55 -		return output;
    5.56 -	}
    5.57 -
    5.58 -	public void setOutput(File output) {
    5.59 -		this.output = output;
    5.60 -	}
    5.61 -
    5.62 -	public Collection<SizeSpecification> getSizes() {
    5.63 -		return sizes;
    5.64 -	}
    5.65 -
    5.66 -	public void addSize(SizeSpecification size) {
    5.67 -		sizes.add(size);
    5.68 -	}
    5.69 -
    5.70 -	public static class SizeSpecification {
    5.71 -
    5.72 -		private final int width;
    5.73 -		private final int height;
    5.74 -		private final String directory;
    5.75 -
    5.76 -		public SizeSpecification(int width, int height, String directory) {
    5.77 -			this.width = width;
    5.78 -			this.height = height;
    5.79 -			this.directory = directory;
    5.80 -		}
    5.81 -
    5.82 -		public int getWidth() {
    5.83 -			return width;
    5.84 -		}
    5.85 -
    5.86 -		public int getHeight() {
    5.87 -			return height;
    5.88 -		}
    5.89 -
    5.90 -		public String getDirectory() {
    5.91 -			return directory;
    5.92 -		}
    5.93 -	}
    5.94 -}
     6.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java	Sun Nov 16 21:59:13 2014 +0100
     6.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIParser.java	Sun Nov 16 23:47:28 2014 +0100
     6.3 @@ -17,6 +17,7 @@
     6.4   */
     6.5  package cz.frantovo.copyImageResizer.cli;
     6.6  
     6.7 +import cz.frantovo.copyImageResizer.RecursiveOptions;
     6.8  import java.io.File;
     6.9  import java.util.Arrays;
    6.10  import java.util.Collection;
    6.11 @@ -27,8 +28,8 @@
    6.12   */
    6.13  public class CLIParser {
    6.14  
    6.15 -	public CLIOptions parseOptions(String[] args) throws CLIParserException {
    6.16 -		CLIOptions options = new CLIOptions();
    6.17 +	public RecursiveOptions parseOptions(String[] args) throws CLIParserException {
    6.18 +		RecursiveOptions options = new RecursiveOptions();
    6.19  
    6.20  		for (int i = 0; i < args.length; i++) {
    6.21  			String arg = args[i];
    6.22 @@ -63,7 +64,7 @@
    6.23  
    6.24  		INPUT_DIR("--input-dir") { // bash-completion: option
    6.25  					@Override
    6.26 -					public int parse(String[] args, int index, CLIOptions options) throws CLIParserException {
    6.27 +					public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException {
    6.28  						int originalIndex = index;
    6.29  						String name = fetchNext(args, ++index);
    6.30  						options.setInput(new File(name));
    6.31 @@ -72,7 +73,7 @@
    6.32  				},
    6.33  		OUTPUT_DIR("--output-dir") { // bash-completion: option
    6.34  					@Override
    6.35 -					public int parse(String[] args, int index, CLIOptions options) throws CLIParserException {
    6.36 +					public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException {
    6.37  						int originalIndex = index;
    6.38  						String name = fetchNext(args, ++index);
    6.39  						options.setOutput(new File(name));
    6.40 @@ -81,23 +82,23 @@
    6.41  				},
    6.42  		SIZE("--size") { // bash-completion: option
    6.43  					@Override
    6.44 -					public int parse(String[] args, int index, CLIOptions options) throws CLIParserException {
    6.45 +					public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException {
    6.46  						int originalIndex = index;
    6.47  						int width = parseInt(fetchNext(args, ++index));
    6.48  						int height = parseInt(fetchNext(args, ++index));
    6.49  						String directory = width + "x" + height;
    6.50 -						options.addSize(new CLIOptions.SizeSpecification(width, height, directory));
    6.51 +						options.addSize(new RecursiveOptions.SizeSpecification(width, height, directory));
    6.52  						return index - originalIndex;
    6.53  					}
    6.54  				},
    6.55  		SIZE_NAMED("--size-named") { // bash-completion: option
    6.56  					@Override
    6.57 -					public int parse(String[] args, int index, CLIOptions options) throws CLIParserException {
    6.58 +					public int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException {
    6.59  						int originalIndex = index;
    6.60  						int width = parseInt(fetchNext(args, ++index));
    6.61  						int height = parseInt(fetchNext(args, ++index));
    6.62  						String directory = fetchNext(args, ++index);
    6.63 -						options.addSize(new CLIOptions.SizeSpecification(width, height, directory));
    6.64 +						options.addSize(new RecursiveOptions.SizeSpecification(width, height, directory));
    6.65  						return index - originalIndex;
    6.66  					}
    6.67  				};
    6.68 @@ -134,6 +135,6 @@
    6.69  		 * return 0, otherwise return positive integer: number of eaten arguments.
    6.70  		 * @throws CLIParserException
    6.71  		 */
    6.72 -		public abstract int parse(String[] args, int index, CLIOptions options) throws CLIParserException;
    6.73 +		public abstract int parse(String[] args, int index, RecursiveOptions options) throws CLIParserException;
    6.74  	}
    6.75  }
     7.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java	Sun Nov 16 21:59:13 2014 +0100
     7.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/cli/CLIStarter.java	Sun Nov 16 23:47:28 2014 +0100
     7.3 @@ -17,18 +17,35 @@
     7.4   */
     7.5  package cz.frantovo.copyImageResizer.cli;
     7.6  
     7.7 +import cz.frantovo.copyImageResizer.RecursiveException;
     7.8 +import cz.frantovo.copyImageResizer.RecursiveImageResizer;
     7.9 +import cz.frantovo.copyImageResizer.RecursiveOptions;
    7.10 +import cz.frantovo.copyImageResizer.ResizeException;
    7.11 +import java.util.logging.Level;
    7.12 +import java.util.logging.Logger;
    7.13 +
    7.14  /**
    7.15   *
    7.16   * @author Ing. František Kučera (frantovo.cz)
    7.17   */
    7.18  public class CLIStarter {
    7.19  
    7.20 -	/**
    7.21 -	 * @param args the command line arguments
    7.22 -	 */
    7.23 +	private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
    7.24 +
    7.25  	public static void main(String[] args) {
    7.26 -		// TODO code application logic here
    7.27 -		System.out.println("TODO");
    7.28 +
    7.29 +		try {
    7.30 +			CLIParser parser = new CLIParser();
    7.31 +			RecursiveOptions options = parser.parseOptions(args);
    7.32 +			RecursiveImageResizer resizer = new RecursiveImageResizer();
    7.33 +			resizer.resize(options);
    7.34 +		} catch (CLIParserException e) {
    7.35 +			log.log(Level.SEVERE, "Unable to parse CLI options", e);
    7.36 +		} catch (RecursiveException e) {
    7.37 +			log.log(Level.SEVERE, "Error while processing filesystem hierarchy", e);
    7.38 +		} catch (ResizeException e) {
    7.39 +			log.log(Level.SEVERE, "Error while resizing image", e);
    7.40 +		}
    7.41  	}
    7.42 -	
    7.43 +
    7.44  }