// Path: src/main/java/info/interactivesystems/gamificationengine/api/exeption/ApiError.java
// @ApplicationException
// public class ApiError extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	/**
// 	 * 
// 	 * @param status
// 	 *            a HTTP status code.
// 	 * @param message
// 	 *            a description of the error cause.
// 	 */
// 	public ApiError(Response.Status status, String message) {
// 		this(status, message, new Object[] {});
// 	}
// 
// 	/**
// 	 * @param status
// 	 *            a HTTP status code
// 	 * @param message
// 	 *            a description of the error cause, may be a formatted string.
// 	 * @param args
// 	 *            for format string, may be zero, see {@link String#format test}
// 	 *            .
// 	 */
// 	public ApiError(Response.Status status, String message, Object... args) {
// 		super(ResponseSurrogate.of(status, null, Notification.of(String.format(message, args))));
// 	}
// }


import info.interactivesystems.gamificationengine.api.exeption.ApiError;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package info.interactivesystems.gamificationengine.utils;





public class ImageUtils {

	private static final Logger LOGGER = LoggerFactory.getLogger(ImageUtils.class);
	
	/**
	 * The passed String represents an URL. With this URL a byte[] is created from the image file that was passed as a String that
	 * represents an URL. The format of the image has to be .jpg or .png. Otherwise 
	 * an exception is thrown with the hint, that the URL was not valid.
	 * 
	 * @param fileLocation
	 * 			The path an image can be located. This is an URL.
	 * @return byte[] of the image content.
	 */
	public static byte[] imageToByte(String fileLocation) {
		BufferedImage originalImage;
		byte[] byteImage = null;

		String format = fileLocation.substring(fileLocation.lastIndexOf(".") + 1);

		if (format.equals("png") || format.equals("jpg")) {
			try {
				URL fileImage = new URL(fileLocation);
				originalImage = ImageIO.read(fileImage);
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				ImageIO.write(originalImage, format, baos);
				byteImage = baos.toByteArray();
				 
			} catch (IOException e) {
// Path: src/main/java/info/interactivesystems/gamificationengine/api/exeption/ApiError.java
// @ApplicationException
// public class ApiError extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	/**
// 	 * 
// 	 * @param status
// 	 *            a HTTP status code.
// 	 * @param message
// 	 *            a description of the error cause.
// 	 */
// 	public ApiError(Response.Status status, String message) {
// 		this(status, message, new Object[] {});
// 	}
// 
// 	/**
// 	 * @param status
// 	 *            a HTTP status code
// 	 * @param message
// 	 *            a description of the error cause, may be a formatted string.
// 	 * @param args
// 	 *            for format string, may be zero, see {@link String#format test}
// 	 *            .
// 	 */
// 	public ApiError(Response.Status status, String message, Object... args) {
// 		super(ResponseSurrogate.of(status, null, Notification.of(String.format(message, args))));
// 	}
// }


// Path: src/main/java/info/interactivesystems/gamificationengine/utils/ImageUtils.java
import info.interactivesystems.gamificationengine.api.exeption.ApiError;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package info.interactivesystems.gamificationengine.utils;





public class ImageUtils {

	private static final Logger LOGGER = LoggerFactory.getLogger(ImageUtils.class);
	
	/**
	 * The passed String represents an URL. With this URL a byte[] is created from the image file that was passed as a String that
	 * represents an URL. The format of the image has to be .jpg or .png. Otherwise 
	 * an exception is thrown with the hint, that the URL was not valid.
	 * 
	 * @param fileLocation
	 * 			The path an image can be located. This is an URL.
	 * @return byte[] of the image content.
	 */
	public static byte[] imageToByte(String fileLocation) {
		BufferedImage originalImage;
		byte[] byteImage = null;

		String format = fileLocation.substring(fileLocation.lastIndexOf(".") + 1);

		if (format.equals("png") || format.equals("jpg")) {
			try {
				URL fileImage = new URL(fileLocation);
				originalImage = ImageIO.read(fileImage);
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				ImageIO.write(originalImage, format, baos);
				byteImage = baos.toByteArray();
				 
			} catch (IOException e) {
				throw new ApiError(Response.Status.FORBIDDEN, "No valid url was transferred");