// Path: src/main/java/com/lumata/lib/lupa/HttpService.java
// @Service
// public interface HttpService {
// 
// 	ReadableResource getRawResource(URL url);
// 
// 	TextReadableResource getTextResource(URL url);
// 
// 	TextReadableResource getTextResource(ReadableResource resource);
// 
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/ImageService.java
// public interface ImageService {
// 
// 	/**
// 	 * Extracts image metadata from the specified URL. If it is unable to determine that the given URL contains an image
// 	 * this methods returns <strong>null</strong>.
// 	 * 
// 	 * @param imageUrl
// 	 * @return an Image object or null if no image found at the given URL.
// 	 * @throws IOException
// 	 *             if something goes wrong connecting to the image source.
// 	 * @throws HttpException
// 	 */
// 	Image getImageFromUrl(URL imageUrl) throws IOException;
// 
// 	/**
// 	 * Extracts image metadata from the specified resource. If it is unable to determine that the given URL contains an
// 	 * image this methods returns <strong>null</strong>.
// 	 * 
// 	 * @param resource
// 	 * @return an Image object or null if no image found at the given URL.
// 	 * @throws IOException
// 	 *             if something goes wrong connecting to the image source.
// 	 * @throws HttpException
// 	 */
// 	Image getImageFromResource(ReadableResource resource) throws IOException;
// 
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/ReadableResource.java
// public interface ReadableResource {
// 
// 	URL getUrl();
// 
// 	/**
// 	 * Move the current URL to the redirection path and set the specified url as the actual resource url.
// 	 * 
// 	 * @param url
// 	 *            the redirectionUrl
// 	 */
// 	void makeRedirection(URL url);
// 
// 	Optional<URL[]> getRedirectionPath();
// 
// 	Optional<MediaType> getContentType();
// 
// 	InputStream read() throws IOException;
// 
// 	void discard();
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/content/Image.java
// public class Image extends WebContent {
// 
// 	private Integer width, height;
// 
// 	public Image(String url, String... aliasUrls) {
// 		super(url, aliasUrls);
// 	}
// 
// 	/**
// 	 * @return the width in pixels
// 	 */
// 	public Integer getWidth() {
// 		return width;
// 	}
// 
// 	/**
// 	 * @param width
// 	 *            the width in pixels to set
// 	 */
// 	public void setWidth(Integer width) {
// 		this.width = width;
// 	}
// 
// 	/**
// 	 * @return the height in pixels
// 	 */
// 	public Integer getHeight() {
// 		return height;
// 	}
// 
// 	/**
// 	 * @param height
// 	 *            the height in pixels to set
// 	 */
// 	public void setHeight(Integer height) {
// 		this.height = height;
// 	}
// 
// 	@Override
// 	public Type getType() {
// 		return Type.IMAGE;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return toStringHelper(this).add("with", width).add("height", height).toString();
// 	}
// }


import com.lumata.lib.lupa.HttpService;
import com.lumata.lib.lupa.ImageService;
import com.lumata.lib.lupa.ReadableResource;
import com.lumata.lib.lupa.content.Image;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import com.google.common.net.MediaType;
/**
 * Copyright (c) 2013 Lumata
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.lumata.lib.lupa.internal;




/**
 * @author Alexander De Leon - alexander.leon@lumatagroup.com
 * 
 */
public class ImageServiceImpl implements ImageService {

	private final HttpService httpService;

	public ImageServiceImpl(HttpService httpService) {
		super();
		this.httpService = httpService;
	}

	@Override
// Path: src/main/java/com/lumata/lib/lupa/HttpService.java
// @Service
// public interface HttpService {
// 
// 	ReadableResource getRawResource(URL url);
// 
// 	TextReadableResource getTextResource(URL url);
// 
// 	TextReadableResource getTextResource(ReadableResource resource);
// 
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/ImageService.java
// public interface ImageService {
// 
// 	/**
// 	 * Extracts image metadata from the specified URL. If it is unable to determine that the given URL contains an image
// 	 * this methods returns <strong>null</strong>.
// 	 * 
// 	 * @param imageUrl
// 	 * @return an Image object or null if no image found at the given URL.
// 	 * @throws IOException
// 	 *             if something goes wrong connecting to the image source.
// 	 * @throws HttpException
// 	 */
// 	Image getImageFromUrl(URL imageUrl) throws IOException;
// 
// 	/**
// 	 * Extracts image metadata from the specified resource. If it is unable to determine that the given URL contains an
// 	 * image this methods returns <strong>null</strong>.
// 	 * 
// 	 * @param resource
// 	 * @return an Image object or null if no image found at the given URL.
// 	 * @throws IOException
// 	 *             if something goes wrong connecting to the image source.
// 	 * @throws HttpException
// 	 */
// 	Image getImageFromResource(ReadableResource resource) throws IOException;
// 
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/ReadableResource.java
// public interface ReadableResource {
// 
// 	URL getUrl();
// 
// 	/**
// 	 * Move the current URL to the redirection path and set the specified url as the actual resource url.
// 	 * 
// 	 * @param url
// 	 *            the redirectionUrl
// 	 */
// 	void makeRedirection(URL url);
// 
// 	Optional<URL[]> getRedirectionPath();
// 
// 	Optional<MediaType> getContentType();
// 
// 	InputStream read() throws IOException;
// 
// 	void discard();
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/content/Image.java
// public class Image extends WebContent {
// 
// 	private Integer width, height;
// 
// 	public Image(String url, String... aliasUrls) {
// 		super(url, aliasUrls);
// 	}
// 
// 	/**
// 	 * @return the width in pixels
// 	 */
// 	public Integer getWidth() {
// 		return width;
// 	}
// 
// 	/**
// 	 * @param width
// 	 *            the width in pixels to set
// 	 */
// 	public void setWidth(Integer width) {
// 		this.width = width;
// 	}
// 
// 	/**
// 	 * @return the height in pixels
// 	 */
// 	public Integer getHeight() {
// 		return height;
// 	}
// 
// 	/**
// 	 * @param height
// 	 *            the height in pixels to set
// 	 */
// 	public void setHeight(Integer height) {
// 		this.height = height;
// 	}
// 
// 	@Override
// 	public Type getType() {
// 		return Type.IMAGE;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return toStringHelper(this).add("with", width).add("height", height).toString();
// 	}
// }


// Path: src/main/java/com/lumata/lib/lupa/internal/ImageServiceImpl.java
import com.lumata.lib.lupa.HttpService;
import com.lumata.lib.lupa.ImageService;
import com.lumata.lib.lupa.ReadableResource;
import com.lumata.lib.lupa.content.Image;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import com.google.common.net.MediaType;

/**
 * Copyright (c) 2013 Lumata
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.lumata.lib.lupa.internal;




/**
 * @author Alexander De Leon - alexander.leon@lumatagroup.com
 * 
 */
public class ImageServiceImpl implements ImageService {

	private final HttpService httpService;

	public ImageServiceImpl(HttpService httpService) {
		super();
		this.httpService = httpService;
	}

	@Override
	public Image getImageFromUrl(URL imageUrl) throws IOException {