package kr.gmtc.gw.dev.packetsend.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Queue;

public class TextReader {
    Queue<String> fileQ1;
	Queue<String> fileQ2;
	
	private String sfilepath1;
	private String sfilepath2;
	
	public TextReader(Queue<String> fileQ1, Queue<String> fileQ2, String sFilePath1, String sFilePath2) {
		super();
		
		this.fileQ1 = fileQ1;
		this.fileQ2 = fileQ2;
		this.sfilepath1 = sFilePath1;
		this.sfilepath2 = sFilePath2;
	}

	public void readFile() {
		try{
	        //파일 객체 생성
	        File file1 = new File(sfilepath1);
	        File file2 = new File(sfilepath2);
	       
            BufferedReader inFiles = new BufferedReader(new InputStreamReader(new FileInputStream(file1), StandardCharsets.UTF_8));
            
            String line = "";
	        while((line = inFiles.readLine()) != null){	
	        	//if((char)singleCh == '\r')
	        	
	        	fileQ1.offer(line);
	        	//System.out.print("n\r" + line);
	        		
	        }
	        inFiles.close();
	        
	        inFiles = new BufferedReader(new InputStreamReader(new FileInputStream(file2), StandardCharsets.UTF_8));
	        line = "";
	        while((line = inFiles.readLine()) != null){	
	        	//if((char)singleCh == '\r')
	        	
	        	fileQ2.offer(line);
	        	//System.out.print("n\r" + line);
	        		
	        }
	        inFiles.close();
	        
	    }catch (FileNotFoundException e) {
	        // TODO: handle exception
	    }catch(IOException e){
	        System.out.println(e);
	    }
	}
}
