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

标签 java afp

我使用 java 实用程序合并了三个 AFP 文件,该实用程序从文件中读取字节并使用 FileOutputStream Java 类写入输出流。 合并的 AFP 文件看起来不错,但是打开 AFP 文件后,在强制代码 AFPViewer(在 TLE 浏览器中)中检查 TLE(标签逻辑元素)信息时,所有合并到 GRP 的文件的组编号保持相同: PGP00001

请告诉我如何合并文件,以便 GRP 编号在 AFP 合并后开始按顺序增加。 结果应为 GRP:PGP00001、GRP:PGP00002 和 GRP:PGP00003

使用以下代码合并使用 Apache FOP XSL-FO 生成的每个 AFP 文件:

public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);

// Get the size of the file
long length = file.length();

// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];

// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
       && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
    offset += numRead;
}

// Ensure all the bytes have been read in
if (offset < bytes.length) {
    throw new IOException("Could not completely read file "+file.getName());
}

// Close the input stream and return bytes
is.close();
return bytes;
}

主要功能:

public static void main(String[] args) {
try {
    FileOutputStream fos = new FileOutputStream("C:\\dev\\harry\\ETCC_data\\output.afp");
    byte[] bytes1 = getBytesFromFile(new File(filePath1));
    byte[] bytes2 = getBytesFromFile(new File(filePath2));
    fos.write(bytes1);
    fos.write(bytes2);
    fos.flush(); 
    fos.close(); 
}
catch(FileNotFoundException ex) { System.out.println("FileNotFoundException : " + ex); }
catch(IOException ioe) { System.out.println("IOException : " + ioe); }
}

最佳答案

afplib 确实有一些关于如何正确地将多个 AFP 文件合并为一个的示例代码:

https://github.com/yan74/afplib/wiki/Samples#afpcombinejava https://github.com/yan74/afplib/blob/master/org.afplib.samples/src/main/java/org/afplib/samples/AfpCombine.java

package org.afplib.samples;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

public class AfpCombineTest {

    @Test
    public void testRun() throws IOException {
        new File("tmp").mkdirs();
        AfpCombine combine = new AfpCombine("tmp/out.afp", new String[] { "testdata/start.afp", "testdata/start.afp" , "testdata/ende.afp" , "testdata/ende.afp"});
        combine.run();
    }

}

关于java - AFP 查看器 TLE 浏览器中的组编号在 AFP 合并后不会按顺序增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37809969/

相关文章:

macos - OSX 上的 bash : How to determine if network file (AFP) is in use?

macos - 如何从命令行 (MacOS) 列出 AFP 共享?

java - 根据不同布局中的条目检查 editText 条目

java - 读取和替换 java 中的行

cocoa - 从文件 URL 确定 AFP 共享

objective-c - 在 Objective-C/Carbon 中与 AFP 合作

objective-c - Cocoa 中的文件共享发现

java - 启动过滤器 springSecurityFilterChain java.lang.NoClassDefFoundError 异常

java - 在可序列化对象上获取 NotSerializableException

java - openGL 中的 VBO