java - 如何将两个 AFP 文件连接在一起

标签 java concatenation 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) {

        }
    }
}

最佳答案

Xenos D2e软件生成的AFP默认在页面顶部包含内嵌资源,像这样

AFP file 1 resources       AND        AFP file 2 resources
AFP file 1 content                    AFP file 2 content

但是当我尝试将这两个文件连接在一起时,一些资源将位于连接文件的中间,因此会弄乱结果

AFP file 1 resources
AFP file 1 content
AFP file 2 resources ------> resources should not be in the middle page
AFP file 2 content

所以解决方案是将所有资源导出到外部文件,然后您可以按如下方式连接

AFP file resources
AFP file 1 content
AFP file 2 content

这将解决问题。

关于java - 如何将两个 AFP 文件连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589075/

相关文章:

iphone - 从 iPhone 访问 AFP 共享?

java - 用不同的 4 字节数替换 Long 数中的最后 4 个字节

java - 字符串池内存分配

使用 concat 更新 MySQL 不起作用

Java - 是否有用于连接 String[] 中的字符串的内置函数?

build - 有哪些库可用于构建不同语言的 AFP 文档?

java - Android Studio : doesn't build on simulator after clean install

java - 检查特定日期后收到的传真

video - 将许多 mp4 文件标准化为相同的分辨率

java - AFP 查看器 TLE 浏览器中的组编号在 AFP 合并后不会按顺序增加