从IBM i系列(AS400)转换为Java文本文件的分隔字符生成

huangapple go评论65阅读模式
英文:

Separated Character Generation convert from IBM i series (AS400) to Java text file

问题

我试图创建一个“XLS”文件,但它将以txt文件的形式可用(这意味着在Windows中右键单击并选择“打开方式”并选择记事本时,它将显示为制表符分隔的文本文件)。

这是我试图创建的示例文件(我不得不删除一些条目,因为它很大)。当您在Notepad++中打开文件并选择UTF-8编码时,您会看到像下面的图片中的“隐藏字符”:
从IBM i系列(AS400)转换为Java文本文件的分隔字符生成

如果您能看到xA0,那是IBM I Series(AS400)的COBOL程序生成的隐藏字符之一。

然而,如果您看到这些黄色高亮部分,那也是AS400的一个字符。它是这样声明的:

DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')

现在,我能够使用以下测试代码生成xA0:

List<Object[]> data = new ArrayList<>();
data.add(new Object[] { "AS1", "185914", "NETHERLANDS", "NL", "", "202023714", "2023714", "27-AUG-2022",
"03-FEB-2023", "", "", "00000000", "IF-ADAMAS", "", "PTF166091NL00",
"P166091NL00", "", "", "", "", "IF ADAMAS B V" });
data add(new Object[] { "AS1", "20200893", "GERMANY", "DE", "", "13801864.3", "2915188",
"05-NOV-2022", "22-FEB-2023", "R80049", "10", "00000434", "MICRONIT M", "",
"PTF124241DEEP", "P118354DEEP", "", "", "", "",
"MICRONIT MICROFLUIDICS B.V." });

OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("output.XLS"),"windows-1252");

writer.write(
"\\"Client\\"\\t\\"Case Number\\"\\t\\"Country\\"\\t\\"WIPO\\"\\t\\"Subcase\\"\\t\\"Application Number\\"\\t\\"Patent Number\\"\\t\\"Due Date\\"\\t\\"Paid Date\\"\\t\\"Invoice Number\\"\\t\\"Annuity Number\\"\\t\\"Invoice Amount\\"\\t\\"Client/Division\\"\\t\\"Client Ref(Inv)\\"\\t\\"Client Ref#1(Ctry)\\"\\t\\"Client Ref#2(Ctry)\\"\\t\\"Attorney(Inv)\\"\\t\\"Attorney(Ctry)\\"\\t\\"Remarks\\"\\t\\"Local Title\\"\\t\\"Title Holder\\"\\n");

for (Object[] row : data) {
for (int i = 0; i < row.length; i++) {
writer.write("\\"\"" + "\\u00a0" + row[i].toString() + "\\""");
if (i < row.length - 1) {
writer.write("\\t");
}
}
writer.write("\\n");
}

writer.close();
System.out.println("Done");
}

我必须在FileOutputStream("output.XLS"),"windows-1252"中加入"windows-1252",以便生成像上面图片中看到的xA0,就像您在图片中看到的那样。

然而,

DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')

我在

if (i < row.length - 1) {
writer.write("	");
}

中使用了"\u0005"而不是简单的"\t",它给我带来了ENQ,就像下面的图片一样:

从IBM i系列(AS400)转换为Java文本文件的分隔字符生成

这不是我想要的。我想要像第一张图片一样的效果。因此,有人能告诉我X'05'字段分隔符的等效项是什么吗?我应该做什么改变?

有人能帮助我吗?

非常感谢!

英文:

I'm trying to create an "XLS" file, but it will be available as a txt file. (It means when you right click and select open with in windows and choose notepad it will show as tab separated text file.)

This is the sample file that I'm trying to create (I have to remove some entry because it is big). When you open the file in notepad++ and choose encoding in UTF-8, you will see "hidden characters" like the picture below:
从IBM i系列(AS400)转换为Java文本文件的分隔字符生成

If you can see xA0 that is one of the hidden characters that is generated by a COBOL program of the IBM I Series (AS400).

However, if you see those yellow highlighted part, that is also a character of the AS400. It was declared like this below:

DCL VAR(&amp;FLDDLM)     TYPE(*CHAR) LEN(1)    VALUE(X&#39;05&#39;)

Now I was able to generate the xA0 with these test code below:

List&lt;Object[]&gt; data = new ArrayList&lt;&gt;();
data.add(new Object[] { &quot;AS1&quot;, &quot;185914&quot;, &quot;NETHERLANDS&quot;, &quot;NL&quot;, &quot;&quot;, &quot;202023714&quot;, &quot;2023714&quot;, &quot;27-AUG-2022&quot;,
		&quot;03-FEB-2023&quot;, &quot;&quot;, &quot;&quot;, &quot;00000000&quot;, &quot;IF-ADAMAS&quot;, &quot;&quot;, &quot;PTF166091NL00&quot;,
		&quot;P166091NL00&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;IF ADAMAS B V&quot; });
data.add(new Object[] { &quot;AS1&quot;, &quot;20200893&quot;, &quot;GERMANY&quot;, &quot;DE&quot;, &quot;&quot;, &quot;13801864.3&quot;, &quot;2915188&quot;,
		&quot;05-NOV-2022&quot;, &quot;22-FEB-2023&quot;, &quot;R80049&quot;, &quot;10&quot;, &quot;00000434&quot;, &quot;MICRONIT M&quot;, &quot;&quot;,
		&quot;PTF124241DEEP&quot;, &quot;P118354DEEP&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;,
		&quot;MICRONIT MICROFLUIDICS B.V.&quot; });

OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(&quot;output.XLS&quot;),&quot;windows-1252&quot;);

writer.write(
		&quot;\&quot;Client\&quot;\t\&quot;Case Number\&quot;\t\&quot;Country\&quot;\t\&quot;WIPO\&quot;\t\&quot;Subcase\&quot;\t\&quot;Application Number\&quot;\t\&quot;Patent Number\&quot;\t\&quot;Due Date\&quot;\t\&quot;Paid Date\&quot;\t\&quot;Invoice Number\&quot;\t\&quot;Annuity Number\&quot;\t\&quot;Invoice Amount\&quot;\t\&quot;Client/Division\&quot;\t\&quot;Client Ref(Inv)\&quot;\t\&quot;Client Ref#1(Ctry)\&quot;\t\&quot;Client Ref#2(Ctry)\&quot;\t\&quot;Attorney(Inv)\&quot;\t\&quot;Attorney(Ctry)\&quot;\t\&quot;Remarks\&quot;\t\&quot;Local Title\&quot;\t\&quot;Title Holder\&quot;\n&quot;);

for (Object[] row : data) {
	for (int i = 0; i &lt; row.length; i++) {
		writer.write(&quot;\&quot;&quot; + &quot;\u00a0&quot; + row[i].toString() + &quot;\&quot;&quot;);
		if (i &lt; row.length - 1) {
			writer.write(&quot;\t&quot;);
		}
	}
	writer.write(&quot;\n&quot;);
}

writer.close();
System.out.println(&quot;Done&quot;);

}

I must put in the &quot;windows-1252&quot; in FileOutputStream(&quot;output.XLS&quot;),&quot;windows-1252&quot;); to generate the xA0 with &quot;\u00a0&quot; like you see in the picture above. However,

DCL VAR(&FLDDLM) TYPE(*CHAR) LEN(1) VALUE(X'05')

I put in the &quot;\u0005&quot; instead of simple &quot;\t&quot; in the

            if (i &lt; row.length - 1) {
				writer.write(&quot;\t&quot;);
			}

It gives me ENQ like this picture below

从IBM i系列(AS400)转换为Java文本文件的分隔字符生成

That is not what I want to achieve. I want to achieve like the first picture.
Thus, can someone tell me what is the equivalent of X&#39;05&#39; field separator? What should I change?
Can someone help me with this please?

I would be very appreciated!

答案1

得分: 2

你可以查看ASCII表和EBCDIC表,这样你可以自己确定这些映射关系。但无论如何,你可以在这里找到EBCDIC表,以及在这里找到ASCII表。如果你要查找TAB或水平制表符,你会发现在EBCDIC中它是x05,在ASCII中是x09。由于windows-1252是ASCII编码,你应该将\u0009加载到文件中。

英文:

You might want to Google ASCII table, and EBCDIC table. That way you can determine these mappings yourself. But anyway, you can find an EBCDIC table here and an ASCII table here. If you look for TAB or horizontal tab, you will find that it is x05 in EBCDIC, and x09 in ASCII. Since windows-1252 is an ASCII code, you should be loading \u0009 into the file.

huangapple
  • 本文由 发表于 2023年3月31日 22:21:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定