Ebc编码与asc编码转换

Ebc编码与asc编码转换


publicclassTestUtil {

	privatestaticbyte[] ASCII2EBCDIC = newbyte[256];
	privatestaticbyte[] EBCDIC2ASCII = newbyte[256];

	static {
		ASCII2EBCDIC[0x00] = (byte)0x00;		ASCII2EBCDIC[0x01] = (byte)0x01;
		ASCII2EBCDIC[0x02] = (byte)0x02;		ASCII2EBCDIC[0x03] = (byte)0x03;
		ASCII2EBCDIC[0x04] = (byte)0x37;		ASCII2EBCDIC[0x05] = (byte)0x2D;
		ASCII2EBCDIC[0x06] = (byte)0x2E;		ASCII2EBCDIC[0x07] = (byte)0x2F;
		ASCII2EBCDIC[0x08] = (byte)0x16;		ASCII2EBCDIC[0x09] = (byte)0x05;
		ASCII2EBCDIC[0x0A] = (byte)0x25;		ASCII2EBCDIC[0x0B] = (byte)0x0B;
		ASCII2EBCDIC[0x0C] = (byte)0x0C;		ASCII2EBCDIC[0x0D] = (byte)0x0D;
		ASCII2EBCDIC[0x0E] = (byte)0x0E;		ASCII2EBCDIC[0x0F] = (byte)0x0F;
		ASCII2EBCDIC[0x10] = (byte)0x10;		ASCII2EBCDIC[0x11] = (byte)0x11;
		ASCII2EBCDIC[0x12] = (byte)0x12;		ASCII2EBCDIC[0x13] = (byte)0x13;
		ASCII2EBCDIC[0x14] = (byte)0x3C;		ASCII2EBCDIC[0x15] = (byte)0x3D;
		ASCII2EBCDIC[0x16] = (byte)0x32;		ASCII2EBCDIC[0x17] = (byte)0x26;
		ASCII2EBCDIC[0x18] = (byte)0x18;		ASCII2EBCDIC[0x19] = (byte)0x19;
		ASCII2EBCDIC[0x1A] = (byte)0x3F;		ASCII2EBCDIC[0x1B] = (byte)0x27;
		ASCII2EBCDIC[0x1C] = (byte)0x1C;		ASCII2EBCDIC[0x1D] = (byte)0x1D;
		ASCII2EBCDIC[0x1E] = (byte)0x1E;		ASCII2EBCDIC[0x1F] = (byte)0x1F;
		ASCII2EBCDIC[0x20] = (byte)0x40;		ASCII2EBCDIC[0x21] = (byte)0x5A;
		ASCII2EBCDIC[0x22] = (byte)0x7F;		ASCII2EBCDIC[0x23] = (byte)0x7B;
		ASCII2EBCDIC[0x24] = (byte)0xE0;		ASCII2EBCDIC[0x25] = (byte)0x6C;
		ASCII2EBCDIC[0x26] = (byte)0x50;		ASCII2EBCDIC[0x27] = (byte)0x7D;
		ASCII2EBCDIC[0x28] = (byte)0x4D;		ASCII2EBCDIC[0x29] = (byte)0x5D;
		ASCII2EBCDIC[0x2A] = (byte)0x5C;		ASCII2EBCDIC[0x2B] = (byte)0x4E;
		ASCII2EBCDIC[0x2C] = (byte)0x6B;		ASCII2EBCDIC[0x2D] = (byte)0x60;
		ASCII2EBCDIC[0x2E] = (byte)0x4B;		ASCII2EBCDIC[0x2F] = (byte)0x61;
		ASCII2EBCDIC[0x30] = (byte)0xF0;		ASCII2EBCDIC[0x31] = (byte)0xF1;
		ASCII2EBCDIC[0x32] = (byte)0xF2;		ASCII2EBCDIC[0x33] = (byte)0xF3;
		ASCII2EBCDIC[0x34] = (byte)0xF4;		ASCII2EBCDIC[0x35] = (byte)0xF5;
		ASCII2EBCDIC[0x36] = (byte)0xF6;		ASCII2EBCDIC[0x37] = (byte)0xF7;
		ASCII2EBCDIC[0x38] = (byte)0xF8;		ASCII2EBCDIC[0x39] = (byte)0xF9;
		ASCII2EBCDIC[0x3A] = (byte)0x7A;		ASCII2EBCDIC[0x3B] = (byte)0x5E;
		ASCII2EBCDIC[0x3C] = (byte)0x4C;		ASCII2EBCDIC[0x3D] = (byte)0x7E;
		ASCII2EBCDIC[0x3E] = (byte)0x6E;		ASCII2EBCDIC[0x3F] = (byte)0x6F;
		ASCII2EBCDIC[0x40] = (byte)0x7C;		ASCII2EBCDIC[0x41] = (byte)0xC1;
		ASCII2EBCDIC[0x42] = (byte)0xC2;		ASCII2EBCDIC[0x43] = (byte)0xC3;
		ASCII2EBCDIC[0x44] = (byte)0xC4;		ASCII2EBCDIC[0x45] = (byte)0xC5;
		ASCII2EBCDIC[0x46] = (byte)0xC6;		ASCII2EBCDIC[0x47] = (byte)0xC7;
		ASCII2EBCDIC[0x48] = (byte)0xC8;		ASCII2EBCDIC[0x49] = (byte)0xC9;
		ASCII2EBCDIC[0x4A] = (byte)0xD1;		ASCII2EBCDIC[0x4B] = (byte)0xD2;
		ASCII2EBCDIC[0x4C] = (byte)0xD3;		ASCII2EBCDIC[0x4D] = (byte)0xD4;
		ASCII2EBCDIC[0x4E] = (byte)0xD5;		ASCII2EBCDIC[0x4F] = (byte)0xD6;
		ASCII2EBCDIC[0x50] = (byte)0xD7;		ASCII2EBCDIC[0x51] = (byte)0xD8;
		ASCII2EBCDIC[0x52] = (byte)0xD9;		ASCII2EBCDIC[0x53] = (byte)0xE2;
		ASCII2EBCDIC[0x54] = (byte)0xE3;		ASCII2EBCDIC[0x55] = (byte)0xE4;
		ASCII2EBCDIC[0x56] = (byte)0xE5;		ASCII2EBCDIC[0x57] = (byte)0xE6;
		ASCII2EBCDIC[0x58] = (byte)0xE7;		ASCII2EBCDIC[0x59] = (byte)0xE8;
		ASCII2EBCDIC[0x5A] = (byte)0xE9;		ASCII2EBCDIC[0x5B] = (byte)0xBA;
		ASCII2EBCDIC[0x5C] = (byte)0xB2;		ASCII2EBCDIC[0x5D] = (byte)0xBB;
		ASCII2EBCDIC[0x5E] = (byte)0xB0;		ASCII2EBCDIC[0x5F] = (byte)0x6D;
		ASCII2EBCDIC[0x60] = (byte)0x79;		ASCII2EBCDIC[0x61] = (byte)0x81;
		ASCII2EBCDIC[0x62] = (byte)0x82;		ASCII2EBCDIC[0x63] = (byte)0x83;
		ASCII2EBCDIC[0x64] = (byte)0x84;		ASCII2EBCDIC[0x65] = (byte)0x85;
		ASCII2EBCDIC[0x66] = (byte)0x86;		ASCII2EBCDIC[0x67] = (byte)0x87;
		ASCII2EBCDIC[0x68] = (byte)0x88;		ASCII2EBCDIC[0x69] = (byte)0x89;
		ASCII2EBCDIC[0x6A] = (byte)0x91;		ASCII2EBCDIC[0x6B] = (byte)0x92;
		ASCII2EBCDIC[0x6C] = (byte)0x93;		ASCII2EBCDIC[0x6D] = (byte)0x94;
		ASCII2EBCDIC[0x6E] = (byte)0x95;		ASCII2EBCDIC[0x6F] = (byte)0x96;
		ASCII2EBCDIC[0x70] = (byte)0x97;		ASCII2EBCDIC[0x71] = (byte)0x98;
		ASCII2EBCDIC[0x72] = (byte)0x99;		ASCII2EBCDIC[0x73] = (byte)0xA2;
		ASCII2EBCDIC[0x74] = (byte)0xA3;		ASCII2EBCDIC[0x75] = (byte)0xA4;
		ASCII2EBCDIC[0x76] = (byte)0xA5;		ASCII2EBCDIC[0x77] = (byte)0xA6;
		ASCII2EBCDIC[0x78] = (byte)0xA7;		ASCII2EBCDIC[0x79] = (byte)0xA8;
		ASCII2EBCDIC[0x7A] = (byte)0xA9;		ASCII2EBCDIC[0x7B] = (byte)0xC0;
		ASCII2EBCDIC[0x7C] = (byte)0x4F;		ASCII2EBCDIC[0x7D] = (byte)0xD0;
		ASCII2EBCDIC[0x7E] = (byte)0xA0;		ASCII2EBCDIC[0x7F] = (byte)0x07;
		
		for (int i = 0; i < 256; ++i) {
			EBCDIC2ASCII[ASCII2EBCDIC[i] & 0xFF] = (byte) i;
		}
	}

	privatestaticbyte convertByteA2E(byte in) {
		returnASCII2EBCDIC[in & 0xFF];
	}

	privatestaticbyte convertByteE2A(byte in) {
		returnEBCDIC2ASCII[in & 0xFF];
	}

	//将asc转为ebc
	publicstaticbyte[] convertStrToEBCDIC(byte[] in) {
		if (in != null) {
			byte[] out = newbyte[in.length];
			for (int i = 0; i 

你可能感兴趣的:(Loadrunner,java)