Is there a clean cut way of adding NOP records to an AFP file using Java?
I have created an AFP file using embedded FOP Trunk. Since FOP Trunk does not support the no-operation tag dire开发者_Python百科ctly 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?
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.
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. :-(
精彩评论