package eu.dnetlib.enabling.manager.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;

import java.io.InputStreamReader;

import org.apache.velocity.exception.ResourceNotFoundException;

public class FileUtils {

	
	/**
	 * Read file.
	 * 
	 * @param sourceFilePath the source file path
	 * 
	 * @return the string
	 * 
	 * @throws ResourceNotFoundException the resource not found exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	public String readFile(String filePath) throws ResourceNotFoundException, IOException{
		
		BufferedReader input = new BufferedReader(new InputStreamReader(
				new FileInputStream(filePath), "UTF8"));

		String line = null;
		StringBuffer contents = new StringBuffer("UTF-8");

		while ((line = input.readLine()) != null) {
			contents.append(line);
			contents.append(System.getProperty("line.separator"));
		}
		input.close();

		byte[] utf8 = contents.toString().getBytes("UTF-8");
		String record = new String(utf8);
		return record;
	}

}
