// Path: bpg-generator/src/main/java/org/bellard/bpg/exception/TechnicalException.java
// public class TechnicalException extends RuntimeException implements ExceptionDataHolder, ProcessDataHolder {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private ExceptionData data;
// 	private ProcessData processData;
// 	private String message;
// 
// 	public TechnicalException(ExceptionData data, String message) {
// 		super();
// 		this.data = data;
// 		this.message = message;
// 	}
// 
// 	public TechnicalException(ExceptionData data) {
// 		super();
// 		this.data = data;
// 	}
// 
// 	public TechnicalException(ExceptionData data, Exception cause) {
// 		super(cause);
// 		this.data = data;
// 	}
// 
// 	public TechnicalException(ExceptionData data, ProcessData processData) {
// 		super();
// 		this.data = data;
// 		this.processData = processData;
// 	}
// 
// 	public TechnicalException(ExceptionData data, ProcessData processData, Exception cause) {
// 		super(cause);
// 		this.data = data;
// 		this.processData = processData;
// 	}
// 
// 	public ExceptionData getData() {
// 		return data;
// 	}
// 
// 	public void setData(ExceptionData data) {
// 		this.data = data;
// 	}
// 
// 	public ProcessData getProcessData() {
// 		return processData;
// 	}
// 
// 	public void setProcessData(ProcessData processData) {
// 		this.processData = processData;
// 	}
// 
// 	public String getMessage() {
// 		return message;
// 	}
// 
// 	public void setMessage(String message) {
// 		this.message = message;
// 	}
// 
// }
// 
// Path: bpg-generator/src/main/java/org/bellard/bpg/model/ExceptionData.java
// public enum ExceptionData implements Serializable {
// 
// 	RESOURCE_CREATE("T100", "Problem when creating a resource"), 
// 	RESOURCE_DELETE("T101", "Problem when deleting a resource"), 
// 	RESOURCE_DOWNLOAD("T102", "Problem when downloading a resource"), 
// 	RESOURCE_NO_DOWNLOAD("T102", "No resource to download"), 
// 	RESOURCE_UPLOAD("T103", "Problem when uploading a resource"), 
// 	SPRING_BATCH_ISE("T200", "Spring batch illegal state exception"), 
// 	JSON_MAPPING_ERROR("T300", "Problem during json2Objec or object2Json transformation"), 
// 	THREAD_ENCODING_ERROR("T300", "Problem with thread during encoding"), 
// 	BPG_COMMAND_PARAMETER_ERROR("400", "Problem with the encoding command parameter"), 
// 
// 	BPGENC_ERROR("F100", "Problem with the bpegenc encoding process"),
// 	INPUT_IMAGE_CHECK_ERROR("F200", "Problem with the input message"),
// 	MAX_FILE_PER_SESSION_EXCEED("F300", "The maximum file upload for this session has been reached. Please update the web page and identify a new captcha."),
// 	NO_SESSION("F301", "The session does not exist."),
// 	NO_PROCESS_DATA("F301", "The process data does not exist.");
// 
// 	private String code;
// 	private String message;
// 
// 	private ExceptionData(String code, String message) {
// 		this.code = code;
// 		this.message = message;
// 	}
// 
// 	public String getCode() {
// 		return code;
// 	}
// 
// 	public String getMessage() {
// 		return message;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "ExceptionData[code=" + code + ",message=" + message + "]";
// 	}
// 
// }


import java.io.IOException;
import javax.annotation.PostConstruct;
import org.bellard.bpg.exception.TechnicalException;
import org.bellard.bpg.model.ExceptionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
	public long getBpgFileSize(String filename) {
		long l;
		try {
			l = createBpg(filename).getFile().length();
		} catch (IOException e) {
			logger.warn("Problem when retrieving the file size");
			l = -1;
		}
		return l;
	}

	public Resource createUpload(String filename) {
		return createRelative(uploadDir, filename);
	}

	public void deleteUpload(String id) {
		delete(createUpload(id));
	}

	public void deleteOutput(String id) {
		delete(createBpg(id));
	}

	protected void delete(Resource resource) {
		try {
			if (resource.exists()) {
				resource.getFile().delete();
			}
		} catch (IOException e) {
			logger.warn("" + ExceptionData.RESOURCE_DELETE);
// Path: bpg-generator/src/main/java/org/bellard/bpg/exception/TechnicalException.java
// public class TechnicalException extends RuntimeException implements ExceptionDataHolder, ProcessDataHolder {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private ExceptionData data;
// 	private ProcessData processData;
// 	private String message;
// 
// 	public TechnicalException(ExceptionData data, String message) {
// 		super();
// 		this.data = data;
// 		this.message = message;
// 	}
// 
// 	public TechnicalException(ExceptionData data) {
// 		super();
// 		this.data = data;
// 	}
// 
// 	public TechnicalException(ExceptionData data, Exception cause) {
// 		super(cause);
// 		this.data = data;
// 	}
// 
// 	public TechnicalException(ExceptionData data, ProcessData processData) {
// 		super();
// 		this.data = data;
// 		this.processData = processData;
// 	}
// 
// 	public TechnicalException(ExceptionData data, ProcessData processData, Exception cause) {
// 		super(cause);
// 		this.data = data;
// 		this.processData = processData;
// 	}
// 
// 	public ExceptionData getData() {
// 		return data;
// 	}
// 
// 	public void setData(ExceptionData data) {
// 		this.data = data;
// 	}
// 
// 	public ProcessData getProcessData() {
// 		return processData;
// 	}
// 
// 	public void setProcessData(ProcessData processData) {
// 		this.processData = processData;
// 	}
// 
// 	public String getMessage() {
// 		return message;
// 	}
// 
// 	public void setMessage(String message) {
// 		this.message = message;
// 	}
// 
// }
// 
// Path: bpg-generator/src/main/java/org/bellard/bpg/model/ExceptionData.java
// public enum ExceptionData implements Serializable {
// 
// 	RESOURCE_CREATE("T100", "Problem when creating a resource"), 
// 	RESOURCE_DELETE("T101", "Problem when deleting a resource"), 
// 	RESOURCE_DOWNLOAD("T102", "Problem when downloading a resource"), 
// 	RESOURCE_NO_DOWNLOAD("T102", "No resource to download"), 
// 	RESOURCE_UPLOAD("T103", "Problem when uploading a resource"), 
// 	SPRING_BATCH_ISE("T200", "Spring batch illegal state exception"), 
// 	JSON_MAPPING_ERROR("T300", "Problem during json2Objec or object2Json transformation"), 
// 	THREAD_ENCODING_ERROR("T300", "Problem with thread during encoding"), 
// 	BPG_COMMAND_PARAMETER_ERROR("400", "Problem with the encoding command parameter"), 
// 
// 	BPGENC_ERROR("F100", "Problem with the bpegenc encoding process"),
// 	INPUT_IMAGE_CHECK_ERROR("F200", "Problem with the input message"),
// 	MAX_FILE_PER_SESSION_EXCEED("F300", "The maximum file upload for this session has been reached. Please update the web page and identify a new captcha."),
// 	NO_SESSION("F301", "The session does not exist."),
// 	NO_PROCESS_DATA("F301", "The process data does not exist.");
// 
// 	private String code;
// 	private String message;
// 
// 	private ExceptionData(String code, String message) {
// 		this.code = code;
// 		this.message = message;
// 	}
// 
// 	public String getCode() {
// 		return code;
// 	}
// 
// 	public String getMessage() {
// 		return message;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "ExceptionData[code=" + code + ",message=" + message + "]";
// 	}
// 
// }


// Path: bpg-generator/src/main/java/org/bellard/bpg/service/FileResourceService.java
import java.io.IOException;
import javax.annotation.PostConstruct;
import org.bellard.bpg.exception.TechnicalException;
import org.bellard.bpg.model.ExceptionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

	public long getBpgFileSize(String filename) {
		long l;
		try {
			l = createBpg(filename).getFile().length();
		} catch (IOException e) {
			logger.warn("Problem when retrieving the file size");
			l = -1;
		}
		return l;
	}

	public Resource createUpload(String filename) {
		return createRelative(uploadDir, filename);
	}

	public void deleteUpload(String id) {
		delete(createUpload(id));
	}

	public void deleteOutput(String id) {
		delete(createBpg(id));
	}

	protected void delete(Resource resource) {
		try {
			if (resource.exists()) {
				resource.getFile().delete();
			}
		} catch (IOException e) {
			logger.warn("" + ExceptionData.RESOURCE_DELETE);
			throw new TechnicalException(ExceptionData.RESOURCE_DELETE, e);