我试图用Xodus实现一个包装好的"move“函数,但是有些事情没有得到正确的解决:
@Override
public boolean move(String appId, String name, String targetName) {
final boolean[] success = new boolean[1];
final Environment env = manager.getEnvironment(xodusRoot, appId);
final VirtualFileSystem vfs = manager.getVirtualFileSystem(env);
env.executeInTransaction(
new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
File file = vfs.openFile(txn, name, false);
InputStream input = vfs.readFile(txn, file);
if(input != null) {
File targetFile = vfs.openFile(txn, targetName, true);
DataOutputStream output = new DataOutputStream(vfs.writeFile(txn, targetFile));
try {
output.write(ByteStreams.toByteArray(input));
} catch (IOException e) {
e.printStackTrace();
}
vfs.deleteFile(txn, name);
success[0] = true;
}
}
});
// vfs.shutdown();
// env.close();
return success[0];
}问题是文件被移动,但字节数组没有被复制,不确定问题是否是由于同一个事务中的多个VFS操作造成的。有人能告诉我为什么源文件中的字节没有被正确复制吗?
发布于 2019-11-28 13:51:38
看起来您正在尝试实现另一个版本的VirtualFileSystem.renameFile(..)。
https://stackoverflow.com/questions/59084013
复制相似问题