package ve.gob.cnti.receiver.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.logging.Logger;

public class ConverFile implements IConverFile{
	
	private File fileSender;
	private long systemCurrentTime;
	PropertiesReader propertiesReader=new PropertiesReader();
	private final String EMAIL_FILE_TEMP=propertiesReader.getProperty("EMAIL_FILE_TEMP");	
	private static final Logger log = Logger.getLogger(ConverFile.class.getName());
	
	public File converterBytesToFile(byte[] fileReceive){
		 
		 log.info("convirtiendo el archivo de tipo byte[] a file");
		 FileOutputStream fileOuputStream;		 
		 String file=EMAIL_FILE_TEMP;
		 systemCurrentTime=System.currentTimeMillis() / 1000L;
		 file+=String.valueOf(systemCurrentTime);
		 log.info("convirtiendo el archivo de tipo byte[] a file");
		 log.info("ruta del archivo a enviar"+file);
		 try {
			fileOuputStream = new FileOutputStream(file);
			fileOuputStream.write(fileReceive);
			fileOuputStream.close();
		 }catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		 }
		
		fileSender=new File(file);
	    return fileSender;		
	}
}
