我最近一直在阅读有关巴拿马项目的信息。
我知道它将成为 JNI 的下一代替代品——它将允许 Java 开发人员使用 Java 在本机层上进行编码(恕我直言)。
从我可以看出jnr-posix 来看,用法很简单,例如:
public class FileTest {
private static POSIX posix;
@BeforeClass
public static void setUpClass() throws Exception {
posix = POSIXFactory.getPOSIX(new DummyPOSIXHandler(), true);
}
@Test
public void utimesTest() throws Throwable {
// FIXME: On Windows this is working but providing wrong numbers and therefore getting wrong results.
if (!Platform.IS_WINDOWS) {
File f = File.createTempFile("utimes", null);
int rval = posix.utimes(f.getAbsolutePath(), new long[]{800, 200}, new long[]{900, 300});
assertEquals("utimes did not return 0", 0, rval);
FileStat stat = posix.stat(f.getAbsolutePath());
assertEquals("atime seconds failed", 800, stat.atime());
assertEquals("mtime seconds failed", 900, stat.mtime());
// The nano secs part is available in other stat implementations. We really just want to verify that the
// nsec portion of the timeval is passed through to the POSIX call.
// Mac seems to fail this test sporadically.
if (stat instanceof NanosecondFileStat && !Platform.IS_MAC) {
NanosecondFileStat linuxStat = (NanosecondFileStat) stat;
assertEquals("atime useconds failed", 200000, linuxStat.aTimeNanoSecs());
assertEquals("mtime useconds failed", 300000, linuxStat.mTimeNanoSecs());
}
f.delete();
}
}
// ....
// ....
// ....
}
我的问题是 - 与 JNI 合作过,并且知道它有多麻烦,是否有将现有 JNI 解决方案移植到巴拿马格式的解决方案?
IE - 检查生成的(通过已弃用的 javah)C 头文件和在 C 中给出的头文件实现,识别可以被巴拿马 API 替换的函数,然后生成 java 输出文件?
还是需要手动重构现有的 JNI 解决方案?
附加链接: