package com.eactive.eai.batch.running;

import java.util.HashMap;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.BufferedInputStream;

public class BatchOpenFileManager {

    private static BatchOpenFileManager instance = new BatchOpenFileManager();

    public static BatchOpenFileManager getInstance() {
        return instance;
    }
    private HashMap<String, String>              mapFileName;     //File 이름 ( full path )
    private HashMap<String, FileInputStream>     mapFin;          //FileInputStream 객체
    private HashMap<String, BufferedReader>      mapFbr;          //BufferedReader 객체
    private HashMap<String, BufferedInputStream> mapBis;

    private BatchOpenFileManager(){
        mapFileName = new HashMap<String, String>();
        mapFin      = new HashMap<String, FileInputStream>();
        mapFbr      = new HashMap<String, BufferedReader>();
        mapBis      = new HashMap<String, BufferedInputStream>();
    }

    public void addFile(String strUUID, String fileName, FileInputStream fin) {
        mapFileName.put( strUUID, fileName );
        mapFin.put( strUUID, fin );
    }

    public void addFbr(String strUUID, String fileName, BufferedReader fbr) {
        mapFileName.put( strUUID, fileName );
        mapFbr.put( strUUID, fbr );
    }

    public void removeFile(String strUUID) {
        mapFileName.remove( strUUID );
        mapFin.remove( strUUID );
        mapFbr.remove( strUUID );
        mapBis.remove( strUUID );
    }

    public FileInputStream getFile(String strUUID) {
        return mapFin.get(strUUID);
    }

    public BufferedReader getFbr(String strUUID) {
        return mapFbr.get(strUUID);
    }

    public void addBis(String strUUID, String fileName, BufferedInputStream fbr) {
        mapFileName.put( strUUID, fileName );
        mapBis.put( strUUID, fbr );
    }

    public void removeBis(String strUUID) {
    	mapFileName.remove( strUUID );
    	mapBis.remove( strUUID );
    }
    
    public BufferedInputStream getBis(String strUUID) {
        return mapBis.get(strUUID);
    }
}