如何将两个 AFP 文件连接在一起
我有两个 AFP 文件,我想将它们连接在一起,我该如何完成这。我已经编写了 java 代码来使用 BufferedInputStream 和 BufferedOutputStream 连接它们,但结果 AFP 的格式不正确。我什至尝试使用 linux cat 但产生了相同的错误结果。请帮忙。我不认为问题出在我的java代码上,但我发布了下面的代码以防万一。
注意:一件奇怪的事情是,如果我切换串联的顺序,则会产生正确的格式输出。例如,如果我连接 A.afp,然后连接 B.afp,则输出会混乱,但如果我连接 B.afp,然后连接 A.afp,则它会产生正确的格式结果。但我需要 A.afp 出现在 B.afp 之前
public static void main(String[] args) {
String filePath1 = "C:\\dev\\harry\\ETCC_data\\3199_FI_20_20110901143009.afp";
String filePath2 = "C:\\dev\\harry\\ETCC_data\\3643_FI_49_20110901143006.afp";
ConcatenateMain cm = new ConcatenateMain();
cm.concate(filePath1, filePath2);
}
private void concate(String filePath1, String filePath2){
BufferedInputStream bis1 = null;
BufferedInputStream bis2 = null;
FileInputStream inputStream1 = null;
FileInputStream inputStream2 = null;
FileOutputStream outputStream = null;
BufferedOutputStream output = null;
try{
inputStream1 = new FileInputStream(filePath1);
inputStream2 = new FileInputStream(filePath2);
bis1 = new BufferedInputStream(inputStream1);
bis2 = new BufferedInputStream(inputStream2);
List<BufferedInputStream> inputStreams = new ArrayList<BufferedInputStream>();
inputStreams.add(bis1);
inputStreams.add(bis2);
outputStream = new FileOutputStream("C:\\dev\\harry\\ETCC_data\\output.afp");
output = new BufferedOutputStream(outputStream);
byte [] buffer = new byte[BUFFER_SIZE];
for(BufferedInputStream input : inputStreams){
try{
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1)
{
output.write(buffer, 0, bytesRead);
}
}finally{
input.close();
}
}
}catch(IOException e){
}finally{
try {
output.close();
} catch (IOException e) {
}
}
}
I have two AFP files and I want to concatenate them together, how can I accomplish this. I have written java code to concatenate them, using BufferedInputStream and BufferedOutputStream and the result AFP is not correctly format. I even try to use linux cat but yield the same incorrect result. Please help. I dont think the problem is my java code, but I post the code below just in case.
NOTE: One strange thing is that if I switch the order of the concatenation then it yield the right format output. For example if I concatenate A.afp then B.afp, then the output is messed up, but if I concatenate B.afp, then A.afp then it yield correct format result. But I need A.afp to appear before B.afp
public static void main(String[] args) {
String filePath1 = "C:\\dev\\harry\\ETCC_data\\3199_FI_20_20110901143009.afp";
String filePath2 = "C:\\dev\\harry\\ETCC_data\\3643_FI_49_20110901143006.afp";
ConcatenateMain cm = new ConcatenateMain();
cm.concate(filePath1, filePath2);
}
private void concate(String filePath1, String filePath2){
BufferedInputStream bis1 = null;
BufferedInputStream bis2 = null;
FileInputStream inputStream1 = null;
FileInputStream inputStream2 = null;
FileOutputStream outputStream = null;
BufferedOutputStream output = null;
try{
inputStream1 = new FileInputStream(filePath1);
inputStream2 = new FileInputStream(filePath2);
bis1 = new BufferedInputStream(inputStream1);
bis2 = new BufferedInputStream(inputStream2);
List<BufferedInputStream> inputStreams = new ArrayList<BufferedInputStream>();
inputStreams.add(bis1);
inputStreams.add(bis2);
outputStream = new FileOutputStream("C:\\dev\\harry\\ETCC_data\\output.afp");
output = new BufferedOutputStream(outputStream);
byte [] buffer = new byte[BUFFER_SIZE];
for(BufferedInputStream input : inputStreams){
try{
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1)
{
output.write(buffer, 0, bytesRead);
}
}finally{
input.close();
}
}
}catch(IOException e){
}finally{
try {
output.close();
} catch (IOException e) {
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Xenos D2e 软件生成的 AFP 默认情况下在页面顶部包含内联资源,如下所示
但是当我尝试将这两个文件连接在一起时,某些资源将位于连接文件的中间,因此会弄乱结果,
因此解决方案是将所有资源导出到外部文件,然后您可以按如下方式连接
这将解决问题。
AFP generated by Xenos D2e software by default contain inline resources at the top of the pages, like this
However when I try to concatenate these two file together, some resources will be at the middle of the concatenated file, hence mess up the result
so the solution is to export all resources to an external file, then you can concatenated as follow
This will fix the problem.
从示例仓库中,这是一个从文件中获取字节的快速函数:
然后只需加载它们并将其写入文件
From example depot, here's a quick function to get the bytes from a file:
Then just load them both and write it out to a file
为了借鉴上面关于重新排序文件内容的答案,这里是我在 DST Output(一家非常大的打印和邮件公司)工作时制作的建议工具。
我制作了一个名为“afp_dd”的实用程序,它的工作方式类似于 unix“dd”命令,允许我在命令行上指定记录跳过和计数值,以提取超出记录边界的子文件(标准 dd 程序需要固定大小)记录,而不是在每个记录开头附近带有长度指示符的可变大小)。我可以通过 AFP 转储程序传输子文件来检查它们,然后使用输出子文件作为输入来创建更改的文件。
To piggyback off the answer above about re-ordering the contents of the files, here is a suggested tool I made back when I worked at DST Output (a very large print & mail company).
I made a utility called "afp_dd", which worked like the unix "dd" command, allowing me to specify record skip and count values on the command line to extract sub-files which broke on record boundaries (the standard dd program expects fixed size records, rather than variable size with a length indicator near the beginning of each record). I could pipe the sub-files through our AFP dump program to check them, then use the output subfiles as input to create altered files.