/*
 * IConv.java
 *
 * Created on 2004년 3월 10일 (수), 오후 3:43
 */
package com.eactive.eai.transformer.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import com.eactive.eai.common.util.Logger;
//import com.ibm.db2.jcc.a.e;

/** 
* 1. 기능 : ASCII - EBCDIC 변환 함수 Class
* 2. 처리 개요 : 
*     - 기본코드 및 확장 코드간의 변환처리
* 3. 주의사항 
*     - 반자의 경우 특정문자를 치환하는 로직이 요청에 의해 추가됨
*     - 전자(한글)의 경우 기본코드와 확장코드로 나누어 짐
* @author  : 
* @version : v 1.0.0
* @see :
* @since : 
*/
public class IConv {
    protected static Logger logger = Logger.getLogger("transformer");

    /** Conversion Table for KSC5601 to, from CodePage933 ( EBCDIC Korean  ) */

    //      TABLE LIST FOR CODE CONVERSION 
    //      ASCII_TO_EBCDIC_TABLE               FOR SINGLE BYTE ASCII CHARACTER CONVERSION         [256]
    //      EBCDIC_TO_ASCII_TABLE               FOR SINGLE BYTE EBCDIC CHARACTER CONVERSION        [256]
    //      DB_ASCII_TO_EBCDIC_TABLE            FOR HANGEUL ASCII CONVERSION                       [94][94]
    //      DB_EBCDIC_TO_ASCII_TABLE            FOR HANFEUL EBCDIC CONVERSION                      [149][190]
    
	// ASCII 0x00을 EBCDIC 0x40으로 매핑 : 2009.04.10 (정길영과장)
    // SO(0x0E), SI(0x0F) 는 그대로 변환한다. : 2009.09.16 (신광섭차장)
    /*
    private static final char[] ASCII_TO_EBCDIC_TABLE = {
		0x0040, 0x0001, 0x0002, 0x0003, 0x0037, 0x002d, 0x002e, 0x002f, 0x0016, 0x0005, 0x0025, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
		0x0010, 0x0011, 0x0012, 0x0013, 0x003c, 0x003d, 0x0032, 0x0026, 0x0018, 0x0019, 0x003f, 0x0027, 0x0007, 0x001d, 0x001e, 0x001f,
		0x0040, 0x005a, 0x007f, 0x007b, 0x005b, 0x006c, 0x0050, 0x007d, 0x004d, 0x005d, 0x005c, 0x004e, 0x006b, 0x0060, 0x004b, 0x0061,
		0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x007a, 0x005e, 0x004c, 0x007e, 0x006e, 0x006f,
		0x007c, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6,
		0x00d7, 0x00d8, 0x00d9, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x0070, 0x00e0, 0x0080, 0x00b0, 0x006d,
		0x0079, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096,
		0x0097, 0x0098, 0x0099, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00c0, 0x004f, 0x00d0, 0x00a1, 0x003f,
		0x004a, 0x005f, 0x00b2, 0x00a0, 0x006a, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f
    };
	*/
	
    //--------------------------------------------------
    // 2009년 11월 20일(금) 적용예정 - 강길수 차장 2009.11.13
    // AD, BD로 정의한 [](대괄호)를 70, 80으로 변환 - 갈길수 차장 2009.12.02
	private static final char[] ASCII_TO_EBCDIC_TABLE = {
		0x0040, 0x0001, 0x0002, 0x0003, 0x0037, 0x002d, 0x002e, 0x002f, 0x0016, 0x0005, 0x0025, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
		0x0010, 0x0011, 0x0012, 0x0013, 0x003c, 0x003d, 0x0032, 0x0026, 0x0018, 0x0019, 0x003f, 0x0027, 0x001C, 0x001d, 0x001e, 0x001f,
		0x0040, 0x005a, 0x007f, 0x007b, 0x005b, 0x006c, 0x0050, 0x007d, 0x004d, 0x005d, 0x005c, 0x004e, 0x006b, 0x0060, 0x004b, 0x0061,
		0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x007a, 0x005e, 0x004c, 0x007e, 0x006e, 0x006f,
		0x007c, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6,
		0x00d7, 0x00d8, 0x00d9, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x0070, 0x00e0, 0x0080, 0x005F, 0x006d,
		0x0079, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096,
		0x0097, 0x0098, 0x0099, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00c0, 0x004f, 0x00d0, 0x00a1, 0x003f,
		0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f,
		0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f
    };
	//--------------------------------------------------
    
//-----------------------------------------------------
// 135 라인 첫번째 0x0000 -> 0x0020 으로 변경 : 이동훈 (2007.08.30)
// HOST 0x00을 0x20으로 강제 변경 요건 : 강길수 과장 요청사항
//-----------------------------------------------------
	/*
	private static final char[] EBCDIC_TO_ASCII_TABLE = {
    	0x0020, 0x0001, 0x0002, 0x0003, 0x007F, 0x0009, 0x007F, 0x001C, 0x007F, 0x007F, 0x007F, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
    	0x0010, 0x0011, 0x0012, 0x0013, 0x007F, 0x007F, 0x0008, 0x007F, 0x0018, 0x0019, 0x007F, 0x007F, 0x001A, 0x001D, 0x001E, 0x001F,
    	0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x000A, 0x0017, 0x001B, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0005, 0x0006, 0x0007,
    	0x007F, 0x007F, 0x0016, 0x007F, 0x007F, 0x007F, 0x007F, 0x0004, 0x007F, 0x007F, 0x007F, 0x007F, 0x0014, 0x0015, 0x007F, 0x007F,
    	0x0020, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0080, 0x002E, 0x003C, 0x0028, 0x002B, 0x007C,
    	0x0026, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0021, 0x0024, 0x002A, 0x0029, 0x003B, 0x0081,
    	0x002D, 0x002F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0084, 0x002C, 0x0025, 0x005F, 0x003E, 0x003F,
    	0x005B, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0060, 0x003A, 0x0023, 0x0040, 0x0027, 0x003D, 0x0022,
    	0x005D, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007F, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x0083, 0x007E, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x005E, 0x007F, 0x0082, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007B, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007D, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x005C, 0x007F, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F
    };
    */
	//--------------------------------------------------
    //  2009년 11월 20일(금) 적용 - 강길수 차장 2009.11.13
	//  2009년 12월 14일(월) 적용 - 김기진 차장 2009.12.14 (5B -> 7F, 7C -> 7F )
	 private static final char[] EBCDIC_TO_ASCII_TABLE = {
    	0x0020, 0x0001, 0x0002, 0x0003, 0x007F, 0x0009, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
    	0x0010, 0x0011, 0x0012, 0x0013, 0x007F, 0x007F, 0x0008, 0x007F, 0x0018, 0x0019, 0x007F, 0x007F, 0x001C, 0x001D, 0x001E, 0x001F,
    	0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x000A, 0x0017, 0x001B, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0005, 0x0006, 0x0007,
    	0x007F, 0x007F, 0x0016, 0x007F, 0x007F, 0x007F, 0x007F, 0x0004, 0x007F, 0x007F, 0x007F, 0x007F, 0x0014, 0x0015, 0x007F, 0x007F,
    	0x0020, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x002E, 0x003C, 0x0028, 0x002B, 0x007C,
    	0x0026, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0021, 0x0024, 0x002A, 0x0029, 0x003B, 0x005E,
    	0x002D, 0x002F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x002C, 0x0025, 0x005F, 0x003E, 0x003F,
    	0x005B, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x0060, 0x003A, 0x0023, 0x0040, 0x0027, 0x003D, 0x0022,
    	0x005D, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007F, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x00D1, 0x007E, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x00D8, 0x007F, 0x00DA, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007B, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x007D, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x005C, 0x007F, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F,
    	0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F, 0x007F
    }; 
	//--------------------------------------------------
	 
	private static int EBC_X_MAX = 149;
	private static int EBC_Y_MAX = 190;
	private static char[][] DB_EBC_EXT_TO_ASCII_EXT_TABLE = new char[EBC_X_MAX][EBC_Y_MAX];
	private static char[][] DB_EBC_EXT_TO_ASCII_BAS_TABLE = new char[EBC_X_MAX][EBC_Y_MAX];
	
	private static int ASC_X_MAX = 127;
	private static int ASC_Y_MAX = 190;
	
	private static char[][] DB_ASCII_EXT_TO_EBC_EXT_TABLE = new char[ASC_X_MAX][ASC_Y_MAX];
	

    private static boolean initialized = false;
    private static final byte SO = 0x0E;
    private static final byte SI = 0x0F;
    
    private static final int ASC_NOSOSI          = 0;
	private static final int ASC_WITHSOSI        = 1;
	private static final int ASC_SOSISPACE       = 2;
	private static final int ASC_SI_DOUBLE_SPACE = 3;
    
    static {
        try {
            buildExtConvTable();
			buildBasicConvTable();
            initialized = true;
        } catch (Exception e) {
        	logger.error(e);
            initialized = false;
        }
        logger.error("initialized = "+initialized);
    }
	
    //---------------------------------------------------------------------
    // 2009.03.24
    // 한글도 모두 single byte 변환으로 처리한다. - 강길수차장 요청사항
    // 업무 : B2B 공동망
    //---------------------------------------------------------------------
    //  2009년 12월 14일(월) 적용 - 김기진 차장 2009.12.14
    private static final byte[] ASCIIH_TO_EBCDICH_TABLE = {
    	(byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x37, (byte)0x2d, (byte)0x2e, (byte)0x2f, (byte)0x16, (byte)0x05,
    	(byte)0x25, (byte)0x0b, (byte)0x0c, (byte)0x0d, (byte)0x0e, (byte)0x0f,
    	(byte)0x10, (byte)0x11, (byte)0x12, (byte)0x13, (byte)0x3c, (byte)0x3d, (byte)0x32, (byte)0x26, (byte)0x18, (byte)0x19,
    	(byte)0x3f, (byte)0x27, (byte)0x1c, (byte)0x1d, (byte)0x1e, (byte)0x1f,
    	(byte)0x40, (byte)0x5a, (byte)0x7f, (byte)0x7b, (byte)0x5b, (byte)0x6c, (byte)0x50, (byte)0x7d, (byte)0x4d, (byte)0x5d,
    	(byte)0x5c, (byte)0x4e, (byte)0x6b, (byte)0x60, (byte)0x4b, (byte)0x61,
    	(byte)0xf0, (byte)0xf1, (byte)0xf2, (byte)0xf3, (byte)0xf4, (byte)0xf5, (byte)0xf6, (byte)0xf7, (byte)0xf8, (byte)0xf9,
    	(byte)0x7a, (byte)0x5e, (byte)0x4c, (byte)0x7e, (byte)0x6e, (byte)0x6f,
    	(byte)0x7c, (byte)0xc1, (byte)0xc2, (byte)0xc3, (byte)0xc4, (byte)0xc5, (byte)0xc6, (byte)0xc7, (byte)0xc8, (byte)0xc9,
    	(byte)0xd1, (byte)0xd2, (byte)0xd3, (byte)0xd4, (byte)0xd5, (byte)0xd6,
    	(byte)0xd7, (byte)0xd8, (byte)0xd9, (byte)0xe2, (byte)0xe3, (byte)0xe4, (byte)0xe5, (byte)0xe6, (byte)0xe7, (byte)0xe8,
    	(byte)0xe9, (byte)0x70, (byte)0xe0, (byte)0x80, (byte)0x5f, (byte)0x6d,
    	(byte)0x79, (byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84, (byte)0x85, (byte)0x86, (byte)0x87, (byte)0x88, (byte)0x89,
    	(byte)0x91, (byte)0x92, (byte)0x93, (byte)0x94, (byte)0x95, (byte)0x96,
    	(byte)0x97, (byte)0x98, (byte)0x99, (byte)0xa2, (byte)0xa3, (byte)0xa4, (byte)0xa5, (byte)0xa6, (byte)0xa7, (byte)0xa8,
    	(byte)0xa9, (byte)0xc0, (byte)0x4f, (byte)0xd0, (byte)0xa1, (byte)0x07,
    	(byte)0x20, (byte)0x21, (byte)0x22, (byte)0x23, (byte)0x24, (byte)0x15, (byte)0x06, (byte)0x17, (byte)0x28, (byte)0x29,
    	(byte)0x2a, (byte)0x2b, (byte)0x2c, (byte)0x09, (byte)0x0a, (byte)0x1b,
    	(byte)0x30, (byte)0x31, (byte)0x1a, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x08, (byte)0x38, (byte)0x39,
    	(byte)0x3a, (byte)0x3b, (byte)0x04, (byte)0x14, (byte)0x3e, (byte)0xe1,
    	(byte)0x41, (byte)0x42, (byte)0x43, (byte)0x44, (byte)0x45, (byte)0x46, (byte)0x47, (byte)0x48, (byte)0x49, (byte)0x51,
    	(byte)0x52, (byte)0x53, (byte)0x54, (byte)0x55, (byte)0x56, (byte)0x57,
    	(byte)0x58, (byte)0x59, (byte)0x62, (byte)0x63, (byte)0x64, (byte)0x65, (byte)0x66, (byte)0x67, (byte)0x68, (byte)0x69,
    	(byte)0x6a, (byte)0x71, (byte)0x72, (byte)0x73, (byte)0x74, (byte)0x75,
    	(byte)0x76, (byte)0x77, (byte)0x78, (byte)0x4a, (byte)0x8a, (byte)0x8b, (byte)0x8c, (byte)0x8d, (byte)0x8e, (byte)0x8f,
    	(byte)0x90, (byte)0x9a, (byte)0x9b, (byte)0x9c, (byte)0x9d, (byte)0x9e,
    	(byte)0x9f, (byte)0xa0, (byte)0xaa, (byte)0xab, (byte)0xac, (byte)0xad, (byte)0xae, (byte)0xaf, (byte)0xb0, (byte)0xb1,
    	(byte)0xb2, (byte)0xb3, (byte)0xb4, (byte)0xb5, (byte)0xb6, (byte)0xb7,
    	(byte)0xb8, (byte)0xb9, (byte)0xba, (byte)0xbb, (byte)0xbc, (byte)0xbd, (byte)0xbe, (byte)0xbf, (byte)0xca, (byte)0xcb,
    	(byte)0xcc, (byte)0xcd, (byte)0xce, (byte)0xcf, (byte)0xda, (byte)0xdb,
    	(byte)0xdc, (byte)0xdd, (byte)0xde, (byte)0xdf, (byte)0xea, (byte)0xeb, (byte)0xec, (byte)0xed, (byte)0xee, (byte)0xef,
    	(byte)0xfa, (byte)0xfb, (byte)0xfc, (byte)0xfd, (byte)0xfe, (byte)0xff
    };
    
    //  2009년 12월 14일(월) 적용 - 김기진 차장 2009.12.14
    private static final byte[] EBCDICH_TO_ASCIIH_TABLE = {
    	(byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x9c, (byte)0x09, (byte)0x86, (byte)0x7f, (byte)0x97, (byte)0x8d,
    	(byte)0x8e, (byte)0x0b, (byte)0x0c, (byte)0x0d, (byte)0x0e, (byte)0x0f,
    	(byte)0x10, (byte)0x11, (byte)0x12, (byte)0x13, (byte)0x9d, (byte)0x85, (byte)0x08, (byte)0x87, (byte)0x18, (byte)0x19,
    	(byte)0x92, (byte)0x8f, (byte)0x1c, (byte)0x1d, (byte)0x1e, (byte)0x1f,
    	(byte)0x80, (byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84, (byte)0x0a, (byte)0x17, (byte)0x1b, (byte)0x88, (byte)0x89,
    	(byte)0x8a, (byte)0x8b, (byte)0x8c, (byte)0x05, (byte)0x06, (byte)0x07,
    	(byte)0x90, (byte)0x91, (byte)0x16, (byte)0x93, (byte)0x94, (byte)0x95, (byte)0x96, (byte)0x04, (byte)0x98, (byte)0x99,
    	(byte)0x9a, (byte)0x9b, (byte)0x14, (byte)0x15, (byte)0x9e, (byte)0x1a,
    	(byte)0x20, (byte)0xa0, (byte)0xa1, (byte)0xa2, (byte)0xa3, (byte)0xa4, (byte)0xa5, (byte)0xa6, (byte)0xa7, (byte)0xa8,
    	(byte)0xc3, (byte)0x2e, (byte)0x3c, (byte)0x28, (byte)0x2b, (byte)0x7c,
    	(byte)0x26, (byte)0xa9, (byte)0xaa, (byte)0xab, (byte)0xac, (byte)0xad, (byte)0xae, (byte)0xaf, (byte)0xb0, (byte)0xb1,
    	(byte)0x21, (byte)0x24, (byte)0x2a, (byte)0x29, (byte)0x3b, (byte)0x5e,
    	(byte)0x2d, (byte)0x2f, (byte)0xb2, (byte)0xb3, (byte)0xb4, (byte)0xb5, (byte)0xb6, (byte)0xb7, (byte)0xb8, (byte)0xb9,
    	(byte)0xba, (byte)0x2c, (byte)0x25, (byte)0x5f, (byte)0x3e, (byte)0x3f,
    	(byte)0x5b, (byte)0xbb, (byte)0xbc, (byte)0xbd, (byte)0xbe, (byte)0xbf, (byte)0xc0, (byte)0xc1, (byte)0xc2, (byte)0x60,
    	(byte)0x3a, (byte)0x23, (byte)0x40, (byte)0x27, (byte)0x3d, (byte)0x22,
    	(byte)0x5d, (byte)0x61, (byte)0x62, (byte)0x63, (byte)0x64, (byte)0x65, (byte)0x66, (byte)0x67, (byte)0x68, (byte)0x69,
    	(byte)0xc4, (byte)0xc5, (byte)0xc6, (byte)0xc7, (byte)0xc8, (byte)0xc9,
    	(byte)0xca, (byte)0x6a, (byte)0x6b, (byte)0x6c, (byte)0x6d, (byte)0x6e, (byte)0x6f, (byte)0x70, (byte)0x71, (byte)0x72,
    	(byte)0xcb, (byte)0xcc, (byte)0xcd, (byte)0xce, (byte)0xcf, (byte)0xd0,
    	(byte)0xd1, (byte)0x7e, (byte)0x73, (byte)0x74, (byte)0x75, (byte)0x76, (byte)0x77, (byte)0x78, (byte)0x79, (byte)0x7a,
    	(byte)0xd2, (byte)0xd3, (byte)0xd4, (byte)0xd5, (byte)0xd6, (byte)0xd7,
    	(byte)0xd8, (byte)0xd9, (byte)0xda, (byte)0xdb, (byte)0xdc, (byte)0xdd, (byte)0xde, (byte)0xdf, (byte)0xe0, (byte)0xe1,
    	(byte)0xe2, (byte)0xe3, (byte)0xe4, (byte)0xe5, (byte)0xe6, (byte)0xe7,
    	(byte)0x7b, (byte)0x41, (byte)0x42, (byte)0x43, (byte)0x44, (byte)0x45, (byte)0x46, (byte)0x47, (byte)0x48, (byte)0x49,
    	(byte)0xe8, (byte)0xe9, (byte)0xea, (byte)0xeb, (byte)0xec, (byte)0xed,
    	(byte)0x7d, (byte)0x4a, (byte)0x4b, (byte)0x4c, (byte)0x4d, (byte)0x4e, (byte)0x4f, (byte)0x50, (byte)0x51, (byte)0x52,
    	(byte)0xee, (byte)0xef, (byte)0xf0, (byte)0xf1, (byte)0xf2, (byte)0xf3,
    	(byte)0x5c, (byte)0x9f, (byte)0x53, (byte)0x54, (byte)0x55, (byte)0x56, (byte)0x57, (byte)0x58, (byte)0x59, (byte)0x5a,
    	(byte)0xf4, (byte)0xf5, (byte)0xf6, (byte)0xf7, (byte)0xf8, (byte)0xf9,
    	(byte)0x30, (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38, (byte)0x39,
    	(byte)0xfa, (byte)0xfb, (byte)0xfc, (byte)0xfd, (byte)0xfe, (byte)0xff
    };
	
    private IConv() {
    	
    }
    
    public static byte[] asciiHexaToEBCDICHexa(byte[] srcBytes) {
    	int length = srcBytes.length;
        byte[] bytes = new byte[srcBytes.length];
		
		byte[] sByte = new byte[1];
		
        for (int i = 0; i < length; i++) {
			sByte[0] = srcBytes[i];
//			bytes[i] = (byte) ASCIIH_TO_EBCDICH_TABLE[Integer.parseInt(bytes2Hex(sByte), 16)];
			bytes[i] = (byte) ASCIIH_TO_EBCDICH_TABLE[ getPosition(sByte) ];
        }
        return bytes;
    }
    
    public static byte[] ebcdicHexaToASCIIHexa(byte[] srcBytes) {
    	int length = srcBytes.length;
        byte[] bytes = new byte[length];
		byte[] sByte = new byte[1];
		
        for (int i = 0; i < length; i++) {
			sByte[0] = srcBytes[i];
//			bytes[i] = (byte) EBCDICH_TO_ASCIIH_TABLE[Integer.parseInt(bytes2Hex(sByte), 16)];
			bytes[i] = (byte) EBCDICH_TO_ASCIIH_TABLE[ getPosition(sByte) ];
        }
        
        return bytes;
    }
    //---------------------------------------------------------------------
	
    public static byte[] asciiToEBCDIC(String value) throws Exception {
    	return asciiToEBCDICBase(value, true);
    }
    
    public static byte[] asciiToEBCDICNoSOSI(String value) throws Exception  {
    	return asciiToEBCDICBase(value, false);
    }
    
	/**
     * EBCDIC을 ASCII 변환시 추가 기능처리.
     *
     * @param abytes EBCDIC byte array
 	* @param withSoSi    SOSI를 그대로 유지할지 여부
 	* @return String 숫자형식의 String
     */
	private static byte[] asciiToEBCDICBase(String value, boolean withSOSI) throws Exception {
    	    	
    	int length = value.length();
        int j = 0;
        int WORD = 0;
        boolean isDBCS = false;
        //---------------------------------------------------------
        // SO-SI 를 Apppend하는 로직을 위해 bytes를 계산하는 부분에
        // 오류가 발생
        // 2Bytes 전각일 경우 
        // Before : 3 Bytes -> 1byte 부족
        // After : 4 Bytes
        //---------------------------------------------------------
        // Before
        //byte[] bytes = new byte[(value.getBytes().length * 5) / 3];
        // After
        byte[] bytes = new byte[value.getBytes().length * 2];
        //---------------------------------------------------------
        
        byte[] dbcs = new byte[2];
        char wc = 0;

        for (int i = 0; i < length; i++) {
			// one byte ALPHANUMERIC 
            if (((value.charAt(i) >> 8) == 0) 
					&& ((int)(value.charAt(i)) < 128) ) {
                if (isDBCS) {
                    if(withSOSI) bytes[j++] = SI;
                    isDBCS = false;
                }

                bytes[j++] = (byte) ASCII_TO_EBCDIC_TABLE[(int) value.charAt(i)];
                continue;
            }

            if (!isDBCS) {
            	if(withSOSI) bytes[j++] = SO;
                isDBCS = true;
            }
            
            try {
            	byte[] tmp = value.substring(i, i + 1).getBytes();
            	
            	// start broken character
            	if(tmp.length <2) {
            		logger.warn("broken character change hostspace. broken char["+Integer.toHexString(tmp[0])+"]");
            		if (isDBCS) {
                        if(withSOSI) bytes[j++] = SI;
                        isDBCS = false;
                    }
            		bytes[j++] =  0x40;
            		continue;
            	}
            	// end broken character
            	
            	System.arraycopy(tmp, 0, dbcs, 0, 2);
            }
            catch(Exception ex) {
//            	System.out.println(">>>> ERROR : IConv Internal Error value["+value+"] pos["+i+"] char["+value.substring(i, i + 1)+"]");
            	logger.error(">>>> ERROR : IConv Internal Error value["+value+"] pos["+i+"] char["+value.substring(i, i + 1)+"]", ex);
            	throw new Exception("IConv Internal Error value["+value+"] pos["+i+"] char["+value.substring(i, i + 1)+"]");
            }
            
//            WORD = Integer.parseInt(bytes2Hex(dbcs), 16);
            WORD = getPosition(dbcs);

            if ((WORD < 0x8141) || (WORD > 0xFEFE)) { // Out of range for 2 bytes character set like hangul
                bytes[j++] = (byte) 0xFF;
                bytes[j++] = (byte) 0xFF;

                continue;
            }

            wc = DB_ASCII_EXT_TO_EBC_EXT_TABLE[(WORD >> 8) - 129][(WORD & 0x00FF) - 65];
			bytes[j++] = (byte) (wc >> 8);
            bytes[j++] = (byte) (wc & 0x00FF);
        }

        if (isDBCS) {
            bytes[j++] = SI;
        }

        byte[] _obytes = new byte[j];
        System.arraycopy(bytes, 0, _obytes, 0, j);

        return _obytes;
    }
	
    // 확장형 ASCII로 변환 
	// SOSI는 제거됨
    public static String ebcdicToASCIIEX(byte[] abytes) {
		return ebcdicToASCII(abytes, true, ASC_NOSOSI, false);
	}
	
    //기본형 ASCII로 변환 
	// SOSI는 제거됨
    public static String ebcdicToASCII(byte[] abytes) {
		return ebcdicToASCII(abytes, false, ASC_NOSOSI, false);
	}
	
    // 기본형 ASCII로 변환 
	// SOSI를 그대로 유지
	public static String ebcdicToASCIIWithSOSI(byte[] abytes) {
		return ebcdicToASCII(abytes, false, ASC_WITHSOSI, false);
	}
	
	// 확장형 ASCII로 변환 
	// SOSI를 그대로 유지
	public static String ebcdicToASCIIWithSOSIEX(byte[] abytes) {
		return ebcdicToASCII(abytes, true, ASC_WITHSOSI, false);
	}
	
	// 기본형 ASCII로 변환 
	// SOSI는 제거됨
	// '4040' -> '2020' 으로 변환 : 전자 space 가 반자 space 두개로 
	public static String ebcdicToASCIISingleSpace(byte[] abytes) {
		return ebcdicToASCII(abytes, false, ASC_NOSOSI, true);
	}
	
	// 확장형 ASCII로 변환 
	// SOSI는 제거됨
	// '4040' -> '2020' 으로 변환 : 전자 space 가 반자 space 두개로 
	public static String ebcdicToASCIISingleSpaceEX(byte[] abytes) {
		return ebcdicToASCII(abytes, true, ASC_NOSOSI, true);
	}
	
	// 기본형 ASCII로 변환 
	// SOSI는 '20'으로 치환됨
	public static String ebcdicToASCIISOSISpace(byte[] abytes) {
		return ebcdicToASCII(abytes, false, ASC_SOSISPACE, false);
	}
	
	// 확장형 ASCII로 변환 
	// SOSI는 '20'으로 치환됨
	public static String ebcdicToASCIISOSISpaceEX(byte[] abytes) {
		return ebcdicToASCII(abytes, true, ASC_SOSISPACE, false);
	}
		
	// 기본형 ASCII로 변환 
	// SI를 '2020'으로 치환됨
	public static String ebcdicToASCIISIDoubleSpace(byte[] abytes) {
		return ebcdicToASCII(abytes, false, ASC_SI_DOUBLE_SPACE, false);
	}
	
	// 확장형 ASCII로 변환 
	// SI를 '2020'으로 치환됨
	public static String ebcdicToASCIISIDoubleSpaceEX(byte[] abytes) {
		return ebcdicToASCII(abytes, true, ASC_SI_DOUBLE_SPACE, false);
	}
	
	/**
    * EBCDIC을 ASCII 변환시 추가 기능처리.
    *
    * @param abytes EBCDIC byte array
	* @param isExtend    확장형 한글 사용여부
	* @param sosiSpaceType SOSI를 space로 변환할지 여부( withSoSi가 true여야 한다) 
	*                      - 0(SOSI를 제거), 1 (SOSI를 그대로 유지) , 1(SOSI를 Space로), 2 (SI에 Space 2개)  
	* @param singleSpace EBCDIC Double bytes space를 single byte space 2자로 변경할지 여부
	* @return String 숫자형식의 String
    */ 
    private static String ebcdicToASCII(byte[] abytes, boolean isExtend, int sosiSpaceType, boolean singleSpace) {
        int length = abytes.length;
        int j = 0;
        int WORD = 0;
        boolean isDBCS = false;
        byte[] bytes = new byte[length];
        byte[] dbcs = new byte[2];
        char wc = 0;

        for (int i = 0; i < length; i++) {
            // DBCS start End  SO-SI
            if (abytes[i] == SO) {
                isDBCS = true;
				if(sosiSpaceType == 0) {
					; //skip so 제거
				}
				else if(sosiSpaceType == 1) {
					bytes[j++] = SO;				
				}
				else if(sosiSpaceType == 2) {
					bytes[j++] = (byte)0x20;				
				}
				else if(sosiSpaceType == 3) {
					;				
				}
				else {
					;
				}
			    continue;
            } else if (abytes[i] == SI) {
                isDBCS = false;
				
                if(sosiSpaceType == 0) {
					; //skip so 제거
				}
				else if(sosiSpaceType == 1) {
					bytes[j++] = SI;		
				}
				else if(sosiSpaceType == 2) {
					bytes[j++] = (byte)0x20;
				} else if(sosiSpaceType == 3) {
					bytes[j++] = (byte)0x20;		
					bytes[j++] = (byte)0x20;
				} else {
					;
				}
                
                continue;
            }

            if (((length - i) < 2) && isDBCS) {
                isDBCS = false;
            }

            // one byte ALPHANUMERIC 
            if (!isDBCS) {
                dbcs[0] = 0x00;
                dbcs[1] = abytes[i];
//                bytes[j++] = (byte) EBCDIC_TO_ASCII_TABLE[Integer.parseInt(bytes2Hex(dbcs), 16)];
				bytes[j++] = (byte) EBCDIC_TO_ASCII_TABLE[ getPosition(dbcs) ];

                continue;
            }

            dbcs[0] = abytes[i++];
            dbcs[1] = abytes[i];
//            WORD = Integer.parseInt(bytes2Hex(dbcs), 16);
			WORD = getPosition(dbcs);

            if (WORD == 0x4040) {
                if(singleSpace) {
                	bytes[j++] = (byte) 0x20;
                	bytes[j++] = (byte) 0x20;
                }
                else {
                	bytes[j++] = (byte) 0xA1;
                	bytes[j++] = (byte) 0xA1;
                }
                
                continue;
            }

            if (WORD == 0x0000) {
                bytes[j++] = (byte) 0x00;
                bytes[j++] = (byte) 0x00;

                continue;
            }

            if ((WORD < 0x4141) || (WORD > 0xD5FF) || ((WORD & 0x00FF) < 0x41) ||
                    ((WORD & 0x00FF) > 0xFE)) { // Out of range for 2 bytes character set like hangul
                bytes[j++] = (byte) 0xFF;
                bytes[j++] = (byte) 0xFF;

                continue;
            }

            if(isExtend) {
				wc = DB_EBC_EXT_TO_ASCII_EXT_TABLE[(WORD >> 8) - 65][(WORD & 0x00FF) - 65];
            }
            else {
				wc = DB_EBC_EXT_TO_ASCII_BAS_TABLE[(WORD >> 8) - 65][(WORD & 0x00FF) - 65];
            }
			bytes[j++] = (byte) (wc >> 8);
            bytes[j++] = (byte) (wc & 0x00FF);
        }

        byte[] _obytes = new byte[j];
        System.arraycopy(bytes, 0, _obytes, 0, j);

        return new String(_obytes);
    }
	
    public static String bytes2Hex(byte[] abyte0) {
        StringBuilder buffer = new StringBuilder();

        for (int i = 0; i < abyte0.length; i++) {
            buffer.append(Integer.toHexString((abyte0[i] & 0xf0) >> 4))
                  .append(Integer.toHexString(abyte0[i] & 0xf));
        }
		
		// Performance 를 위해 toUpperCase 제거 :2009.04.03
        //return buffer.toString().toUpperCase();
		return buffer.toString();
    }

	private static void buildExtConvTable() {
		BufferedReader br = null;
		try {
//            String OS = System.getProperty("os.name");

            String className = IConv.class.getName();
            String pathName = className.substring(0, className.lastIndexOf('.'))
                                       .replace('.', '/');

            br = new BufferedReader(new InputStreamReader(
					IConv.class.getClassLoader().getResourceAsStream(pathName +
                            "/code_ext.tab")));
            String lbuff = br.readLine();
            int xpos = 0;
			int ypos = 0;
			String[] codes = null;
			
			int lines = 0;
            while (lbuff != null) {
				lines++;
				if(lbuff.length() == 9) {
					codes = lbuff.split(",");
					if(codes == null || codes.length < 2) continue;
					if(codes[0] != null && codes[0].length() >=4) {
						// DB_EBC_EXT_TO_ASCII_EXT_TABLE
						xpos = Integer.parseInt(codes[0].substring(0,2), 16);
						ypos = Integer.parseInt(codes[0].substring(2,4), 16);
						
						if(xpos < (Integer.MIN_VALUE+65) || ypos < (Integer.MIN_VALUE+65) ) {
							lbuff = br.readLine();
							continue;
						}
							
						xpos = xpos - 65; // 4141 ~
						ypos = ypos - 65;
						
						if((xpos >=0 && xpos < EBC_X_MAX) && (ypos >=0 && ypos < EBC_Y_MAX)) 
						{
							DB_EBC_EXT_TO_ASCII_EXT_TABLE[xpos][ypos] = (char) Integer.parseInt(codes[1], 16);
						}
						
						// DB_ASCII_EXT_TO_EBC_EXT_TABLE
						
//						xpos = Integer.parseInt(codes[1].substring(0,2), 16) - 129; //8141 ~
//						ypos = Integer.parseInt(codes[1].substring(2,4), 16) - 65;
						
						xpos = Integer.parseInt(codes[1].substring(0,2), 16);
						ypos = Integer.parseInt(codes[1].substring(2,4), 16);
						
						if(xpos < (Integer.MIN_VALUE+129) || ypos < (Integer.MIN_VALUE+65) ) {
							lbuff = br.readLine();
							continue;
						}
							
						xpos = xpos - 129; // 4141 ~
						ypos = ypos - 65;
						
						if((xpos >=0 && xpos < ASC_X_MAX) && (ypos >=0 && ypos < ASC_Y_MAX)) 
						{
							DB_ASCII_EXT_TO_EBC_EXT_TABLE[xpos][ypos] = (char) Integer.parseInt(codes[0], 16);
						}
					}
				}
				lbuff = br.readLine();
            }
             // End of while
        } catch (Exception ex) {
        	logger.error(ex);
        }
		finally {
            try { if(br != null) br.close(); } catch(Exception e) {
            	logger.error(e);
            }
		}
    }
	
	private static void buildBasicConvTable() {
		
		String className = IConv.class.getName();
        String pathName = className.substring(0, className.lastIndexOf('.'))
                                   .replace('.', '/');
		try (
			BufferedReader br = new BufferedReader(new InputStreamReader(
					IConv.class.getClassLoader().getResourceAsStream(pathName +
                            "/code_basic.tab")));
			){
            String lbuff = br.readLine();
            int xpos = 0;
			int ypos = 0;
			String[] codes = null;
			
			int lines = 0;
            while (lbuff != null) {
				lines++;
				if(lbuff.length() == 9) {
					codes = lbuff.split(",");
					if(codes == null || codes.length < 2) {
						lbuff = br.readLine();
						continue;
					}
					if(codes[0] != null && codes[0].length() >=4) {
						// DB_EBC_EXT_TO_ASCII_EXT_TABLE
//						xpos = Integer.parseInt(codes[0].substring(0,2), 16) - 65; // 4141 ~
//						ypos = Integer.parseInt(codes[0].substring(2,4), 16) - 65;
						
						xpos = Integer.parseInt(codes[0].substring(0,2), 16);
						ypos = Integer.parseInt(codes[0].substring(2,4), 16);
						
						if(xpos < (Integer.MIN_VALUE+65) || ypos < (Integer.MIN_VALUE+65) ) {
							lbuff = br.readLine();
							continue;
						}
							
						xpos = xpos - 65; // 4141 ~
						ypos = ypos - 65;
						
						if((xpos >=0 && xpos < EBC_X_MAX) && (ypos >=0 && ypos < EBC_Y_MAX)) 
						{
							DB_EBC_EXT_TO_ASCII_BAS_TABLE[xpos][ypos] = (char) Integer.parseInt(codes[1], 16);
						}
					}
				}
				lbuff = br.readLine();
            }
             // End of while
        } catch (Exception ex) {
        	logger.error(ex);
        }
    }
	
	public static String printHexaCode(byte[] abyte) {
		StringBuilder s = new StringBuilder();
        if (abyte == null)
            return s.toString();
        for (int i = 0; i < abyte.length; i++) {
            s.append( Integer.toHexString((abyte[i] & 0xf0) >> 4) )
             .append( Integer.toHexString(abyte[i] & 0xf));
        	//if( ((i+1)%8) == 0) s.append("\n");
        }    
        return s.toString();
    }
	
	public static int getPosition(byte[] b) {
        int high = 0;
		int low  = 0;
		
		if(b.length == 2) {
			high = ((b[0]& 0xf0) >> 4)*16+(b[0]& 0x0f);
			low  = ((b[1]& 0xf0) >> 4)*16+(b[1]& 0x0f);
		}
		else if(b.length == 1) {
			low  = ((b[0]& 0xf0) >> 4)*16+(b[0]& 0x0f);
		}
		
		return (high*16*16+low);
    }
	
	//---------------------------------------------
	// Test 
	//---------------------------------------------
//	public static void inputTest(String input) throws Exception {
//		System.out.println("Input    [" + input +"]");
//		System.out.println("HEXA     [" + printHexaCode(input.getBytes()) +"]");
//
//		byte[] ebc = IConv.asciiToEBCDIC(input);
//		System.out.println("EBC HEXA [" + printHexaCode(ebc) +"]");
//		String asc = IConv.ebcdicToASCIIEX(ebc);
//		System.out.println("ASC EX   [" + asc + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(asc.getBytes()) + "]");
//		
//		String basc = IConv.ebcdicToASCII(ebc);
//		System.out.println("ebcdicToASCII");
//		System.out.println("ASC BAS  [" + basc + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(basc.getBytes()) + "]");
//	}
//	
//	public static void hexaTest() throws Exception {
//		byte[] input = new byte[1];
//		
//		for(int i=0; i<EBCDICH_TO_ASCIIH_TABLE.length; i++) {
//			input[0] = EBCDICH_TO_ASCIIH_TABLE[i];
//			byte[] ebc = IConv.asciiHexaToEBCDICHexa(input);
//			
//			System.out.println("\nTEST [" + i +"]");
//			System.out.println("IN  HEXA [" + printHexaCode(input) +"]");
//			System.out.println("EBC HEXA [" + printHexaCode(ebc) +"]");
//			byte[] asc = IConv.ebcdicHexaToASCIIHexa(ebc);
//			System.out.println("ASC EX   [" + new String(asc) + "]");
//			System.out.println("ASC HEXA [" + printHexaCode(asc) + "]");
//		}
//	}
//	
//	public static void functionTest(String input) throws Exception {
//		System.out.println("Input    [" + input +"]");
//		System.out.println("HEXA     [" + printHexaCode(input.getBytes()) +"]");
//
//		byte[] ebc = IConv.asciiToEBCDIC(input);
//		System.out.println("EBC HEXA [" + printHexaCode(ebc) +"]");
//		
//		String basc = IConv.ebcdicToASCII(ebc);
//		System.out.println("ebcdicToASCII");
//		System.out.println("ASC BAS  [" + basc + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(basc.getBytes()) + "]");
//		
//		String bascSosi = IConv.ebcdicToASCIIWithSOSI(ebc);
//		System.out.println("ebcdicToASCIIWithSOSI");
//		System.out.println("ASC SOSI [" + bascSosi + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi.getBytes()) + "]");
//		
//		String bascSosi2 = IConv.ebcdicToASCIISingleSpace(ebc);
//		System.out.println("ebcdicToASCIISingleSpace");
//		System.out.println("ASC SOSI [" + bascSosi2 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi2.getBytes()) + "]");
//		
//		String bascSosi3 = IConv.ebcdicToASCIISOSISpace(ebc);
//		System.out.println("ebcdicToASCIISOSISpace");
//		System.out.println("ASC SOSI [" + bascSosi3 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi3.getBytes()) + "]");
//		
//		String bascSosi4 = IConv.ebcdicToASCIISIDoubleSpace(ebc);
//		System.out.println("ebcdicToASCIISIDoubleSpace");
//		System.out.println("ASC SOSI [" + bascSosi4 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi4.getBytes()) + "]");
//	}
//	
//	public static void sosiTest(String input) throws Exception {
//		System.out.println("Input    [" + input +"]");
//		System.out.println("HEXA     [" + printHexaCode(input.getBytes()) +"]");
//
//		byte[] ebc = IConv.asciiToEBCDIC(input);
//		System.out.println("EBC HEXA [" + printHexaCode(ebc) +"]");
//		
//		String basc = IConv.ebcdicToASCII(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCII");
//		System.out.println("ASC BAS  [" + basc + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(basc.getBytes()) + "]");
//		
//		String bascEx = IConv.ebcdicToASCIIEX(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCIIEX");
//		System.out.println("ASC BAS  [" + bascEx + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascEx.getBytes()) + "]");
//		
//		String bascSosi = IConv.ebcdicToASCIIWithSOSI(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCIIWithSOSI");
//		System.out.println("ASC SOSI [" + bascSosi + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi.getBytes()) + "]");
//		
//		String bascSosi2 = IConv.ebcdicToASCIISingleSpace(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCIISingleSpace");
//		System.out.println("ASC SOSI [" + bascSosi2 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi2.getBytes()) + "]");
//		
//		String bascSosi3 = IConv.ebcdicToASCIISOSISpace(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCIISOSISpace");
//		System.out.println("ASC SOSI [" + bascSosi3 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi3.getBytes()) + "]");
//		
//		String bascSosi4 = IConv.ebcdicToASCIISIDoubleSpace(ebc);
//		System.out.println("\n");
//		System.out.println("ebcdicToASCIISIDoubleSpace");
//		System.out.println("ASC SOSI [" + bascSosi4 + "]");
//		System.out.println("ASC HEXA [" + printHexaCode(bascSosi4.getBytes()) + "]");
//		
//		
//	}
	
//	   public static void main(String args[]) throws Exception {
////		   byte[] bytes = {(byte) 0xc0, (byte)0xcc,(byte) 0x92,(byte) 0xde};
////		   String data = new String(bytes);
////		   System.out.println("ASC HEXA [" + printHexaCode(data.getBytes()) + "]");
////		   
////		   System.out.println("defaultCharset = " + Charset.defaultCharset());
////		   
////		   data = new String(data.getBytes());
////		   sosiTest(data);
//		   try {
//			   testCode(true);
//		   }
//		   catch(Exception ex) {
//			   ex.printStackTrace();
//		   }
//
//		   try {
//			   testCode(false);
//		   }
//		   catch(Exception ex) {
//			   ex.printStackTrace();
//		   }
//		   
//	   }

//	private static void testCode(boolean fixed) throws Exception {
//		System.out.println("\n######### testCode :  fixed = " + fixed);
//		
////		byte[] bytes = {(byte) 0xA9, (byte)0xB9,(byte) 0x13,(byte) 0x82};
//		
//		String data = "투자-어니스트영";
//		int trimLength = 14;
//		
//		System.out.println("sample data :  " + data + ", length : " + trimLength );
//		byte[] totbytes = data.getBytes();
//		
//		
//		
//		byte[] bytes = new byte[trimLength];
//		System.arraycopy(totbytes, 0, bytes, 0, bytes.length);
//		
//		// 전각으로 변경 후 길이로 다시 자른다.
////		if(fixed) {
////			String sealedAsc = CodeConversion.simpleToSeal(new String(bytes));
////			System.arraycopy(sealedAsc.getBytes(), 0, bytes, 0, bytes.length);
////			System.out.println("seal and trim :  " + sealedAsc + ", trim : " + trimLength );
////		}
//		
//		System.out.println("euc-kr : " + new String(bytes,"euc-kr"));
//		System.out.println("ms949 : " + new String(bytes,"ms949"));
//		
//		
//		String asc = new String(bytes);
//		System.out.println("source : " + asc);
//		
//		byte[] ebc = asciiToEBCDIC(asc);
//		
//		System.out.println("target : " + ebcdicToASCII(ebc));
//	}
//	
//	private static void test(String args) throws Exception {
//		String input;
//		if(args == null) {
//			input = "1각깏뵑ㄱㄴㄷㄹ2";
//		}
//		else {
//			input = args;
//		}
////		inputTest(input);
////		functionTest("한　글");
////		sosiTest("한　글");
////		hexaTest();
//		System.out.println(
//				printHexaCode(asciiToEBCDICBase("나광순　　　　　　　하드케이스（２．５□", false))
//		);
//		
//		byte[] dbcs = new byte[2];
//		
//		try {
//	        byte[] src = "1".substring(0, 1).getBytes();
//	        System.arraycopy(src, 0, dbcs, 0, 2);
//		}
//        catch(Exception e) {
//        	System.out.println("arraycopy Error "+ e.toString());
//        }
//        
//        try {
//        	String nStr = null;
//        	System.arraycopy(nStr.getBytes(), 0, dbcs, 0, 2);
//        }
//        catch(Exception e) {
//        	System.out.println("Null String getBytes Error");        	
//        }
//	}
}
