package com.github.aureliano.achmed.server.service;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import com.github.aureliano.achmed.common.exception.AchmedException;
import com.github.aureliano.achmed.common.helper.FileHelper;
import com.github.aureliano.achmed.common.helper.StringHelper;
import com.github.aureliano.achmed.server.AchmedServerHandler;

public class ReadFileService implements IService {

	public ReadFileService() {}
	
	@Override
	public byte[] consume(Map<String, String> parameters) {
		String resourcePath = parameters.get("resource");
		if (StringHelper.isEmpty(resourcePath)) {
			throw new AchmedException("Empty resource path.");
		}
		
		File requestedFile = FileHelper.buildFile(AchmedServerHandler.instance().getFileRepository(), resourcePath);
		if (!(requestedFile.exists() && requestedFile.isFile())) {
			try {
				return (" >>> Resource path: " + resourcePath).getBytes("UTF-8");
			} catch (UnsupportedEncodingException ex) {
				throw new AchmedException(ex);
			}
		}
		
		return new byte[0];
	}
}
@@ -83,39 +83,16 @@
 ava.
-io.UnsupportedEncodingException
+util.Map
 ;%0Aim
@@ -106,19 +106,30 @@
 va.util.
-Map
+logging.Logger
 ;%0A%0Aimpor
@@ -308,32 +308,98 @@
 r.StringHelper;%0A
+import com.github.aureliano.achmed.common.logging.LoggingFactory;%0A
 import com.githu
@@ -498,16 +498,108 @@
 vice %7B%0A%0A
+%09private static final Logger logger = LoggingFactory.createLogger(ReadFileService.class);%0A%09%0A
 %09public 
@@ -1025,33 +1025,35 @@
 %0A%09%09%09
-try %7B%0A%09%09%09%09return (%22 %3E%3E%3E R
+logger.warning(%22Requested r
 esou
@@ -1064,133 +1064,76 @@
 path
-:
+ %5B
  %22 + re
-sourcePath).getBytes(%22UTF-8%22);%0A%09%09%09%7D catch (UnsupportedEncodingException ex) %7B%0A%09%09%09%09throw new AchmedException(ex);%0A%09%09%09%7D
+questedFile + %22 %5D does not exist.%22);%0A%09%09%09return new byte%5B0%5D;
 %0A%09%09%7D

Return empty array if requested file does not exist.