私たちのアプリケーションには C/C++ で書かれたモジュールがあり、ascii ファイルを受け取り、後でメインフレームに ftped される ebcdic ファイルに変換します。
ここで、この C/C++ コードを Java で書き直すよう求められます。通常の文字、パック 10 進数、メインフレーム バイナリ、浮動小数点の 4 つの異なる出力タイプがあります。それぞれに、個別の入力 ascii の長さと、対応する出力 ebcdic の長さが含まれます。
これを行う場合、11 バイトの入力を 4 バイトのメインフレーム バイナリの出力に変換する特定のタイプのメインフレーム バイナリを変換することはできません。1 つのサンプル入力は ' 451841' であり、less コマンドを使用して unix で開いた場合の ebcdic ファイルの出力は '^@^Få^A' です。
C コードは次のようになります。
/* This routine converts UNIX character data into mainframe binary */
/* representation. It is called from the switch statement when */
/* input field type is "6" */
int UNIX_mf_binary( )
{
unsigned char* out_rec;
int out_position;
int int_work_area;
long int long_int_work_area;
int char_work_area;
char temp_area[11]; // This will be having the value of ' 451841'
unsigned char* c_integer_position;
unsigned int i_integer_position;
long_int_work_area = atol(temp_area);
i_integer_position = &long_int_work_area;
c_integer_position = i_integer_position;
out_rec[out_position] = *c_integer_position;
c_integer_position = i_integer_position + 1;
out_position = out_position + 1;
out_rec[out_position] = *c_integer_position;
c_integer_position = i_integer_position + 2;
out_position = out_position + 1;
out_rec[out_position] = *c_integer_position;
c_integer_position = i_integer_position + 3;
out_position = out_position + 1;
out_rec[out_position] = *c_integer_position;
c_integer_position = i_integer_position + 4;
out_position = out_position + 1;
}
そして、この部分を書き直した Java コードは次のようになります。
String bin = " 451841";
int b;
b = Integer.parseInt(bin.trim());
stringBuffer.append((char) (0x000000FF & b));
stringBuffer.append((char) (0x0000FF00 & (b)));
stringBuffer.append((char) (0x00FF0000 & (b)));
stringBuffer.append((char) (0xFF000000 & (b)));
fos.write(stringBuffer.toString().getBytes());
しかし、Java コードでは、値は次のようになります: ^@^@^@^A
jre バージョン 1.5 を使用しています。この C コードを Java バージョン 1.5 で書き直す方法を理解してくれる人はいますか? もう 1 つ、temp_area[11] の長さは 11 文字ですが、最大値は 6 桁です。