是否有一种简洁的方法可以使用 Java 将 NOP 记录添加到 AFP 文件中?
我使用嵌入式 FOP Trunk 创建了一个 AFP 文件。由于FOP Trunk不支持直接在root下的无操作标签,因此我需要修改创建的文件以添加NOP记录作为文件中的第一条记录。如何做到这一点?
I have created an AFP file using embedded FOP Trunk. Since FOP Trunk does not support the no-operation tag directly under root I need to modify the created file to add a NOP record as the first record in the file. How does one do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将此作为向 FOP 提出的增强请求。这很可能是完成此任务的最现实的地方。
除了 FOP 中的库之外,我不知道有任何 Java AFP 处理库。
I would suggest raising this as an enhancement request with FOP. This is most likely the most realistic place to get this done.
I am not aware of any Java AFP processing libraries except that in FOP.
如果您只需要在文件的开头有一个记录,您可以单独生成它,然后将两个文件连接在一起。 (我假设“裸”AFP 记录,没有任何“变量块”/VB 包装)
请注意,AFP 记录具有如下结构:
1字节:x5a(校验字节); 2字节:16位长度指示符,包括其自身,但不包括“5a”字节; 3字节:记录类型指示符;剩余字节:记录特定数据。
记录类型代码位于此文档中: http://afpcinc.org/site/assets /files/1073/ha3l3r04.pdf
这是 NOP 记录的布局(我想——已经有一段时间了):
x5a + (大端/网络顺序长度) + xD3 xEE xEE + (EBCDIC)字符串数据
例如,要将字符串“FOO=BAR”(ASCII 中的十六进制 [46 4f 4f 3d 42 41 52],EBCDIC 中的十六进制 [c6 d6 d6 7e c2 c1 d9])编码为 NOP:
字符串长度为 7 ,所以我们想要的总长度为 2 + 3 + 7 = 12 (十六进制 0c)
所以,写:
x5a + [00 0c] + [d3 ee ee] + [c6 d6 d6 7e c2 c1 d9]
最后,我知道这是错误的语言,但这里有一个非常好的 AFP 解析器: http://metacpan.org/pod/Parse::AFP,它提供了工作记录布局定义,以防我忘记NOP 记录中的字段。 :-(
If you only need one, single, record at the very beginning of the file, you can probably generate it separately, then just concatenate the two files together. (I am assuming "naked" AFP records, WITHOUT any "variable block"/VB wrapping)
Note that AFP records have a structure like this:
1 byte: x5a (check byte); 2 bytes: 16 bit length indicator, which includes itself, but not the "5a" byte; 3 bytes: record type indicator; remaining bytes: record-specific data.
Record type codes are in this doc: http://afpcinc.org/site/assets/files/1073/ha3l3r04.pdf
Here is the layout for a NOP record (I think -- it's been a while):
x5a + (big-endian/network order length) + xD3 xEE xEE + (EBCDIC) string data
For example, to encode the string "FOO=BAR" (hex [46 4f 4f 3d 42 41 52] in ASCII, hex [c6 d6 d6 7e c2 c1 d9] in EBCDIC) as a NOP:
The string length is 7, so we want a total length of 2 + 3 + 7 = 12 (hex 0c)
So, write:
x5a + [00 0c] + [d3 ee ee] + [c6 d6 d6 7e c2 c1 d9]
Finally, I know it's the wrong language, but there is a pretty good AFP parser available here: http://metacpan.org/pod/Parse::AFP, which provides working record layout defininitions, in case I forgot a field in the NOP record. :-(