Java Xodus VFS无法保存字节

Java Xodus VFS无法保存字节,java,xodus,Java,Xodus,下面代码的问题是VFS似乎无法持久化字节数组。 当Xodus VFS写入零字节时: @Override public FileModel put( String appId, String namespace, String name, InputStream is) { final FileModel[] createdFile = {null}; final Environment env = manager.getEnvironment(xodusRoo

下面代码的问题是VFS似乎无法持久化字节数组。 当Xodus VFS写入零字节时:

  @Override
  public FileModel put(
      String appId, String namespace, String name, InputStream is) {
    final FileModel[] createdFile = {null};
    final Environment env = manager.getEnvironment(xodusRoot, appId);
    final VirtualFileSystem vfs  = new VirtualFileSystem(env);
    env.executeInTransaction(
        new TransactionalExecutable() {
          @Override
          public void execute(@NotNull final Transaction txn) {
            final File file = vfs.openFile(txn, name, true);;
            try {
              byte[] ba = ByteStreams.toByteArray(is);
              LOG.info("Byte array size: " + ba.length); // Size: 3466
              vfs.writeFile(txn, file).write(ba, 0, ba.length);
            } catch (IOException e) {
              e.printStackTrace();
            }
            long fileSize = vfs.getFileLength(txn, file);
            LOG.info("File Size: " + fileSize); // Size: 0 <----
            createdFile[0] = new FileModel();
            createdFile[0].setDescriptor(file.getDescriptor());
            createdFile[0].setName(name);
            createdFile[0].setCreated(file.getCreated());
            createdFile[0].setModified(file.getLastModified());
          }
        });
    vfs.shutdown();
    return createdFile[0];
  }
@覆盖
公共文件模型put(
字符串appId、字符串命名空间、字符串名称、InputStream is){
最终文件模型[]createdFile={null};
最终环境env=manager.getEnvironment(xodusRoot,appId);
最终虚拟文件系统vfs=新的虚拟文件系统(env);
环境执行导入(
新的TransactionalExecutable(){
@凌驾
public void execute(@NotNull final Transaction txn){
final File=vfs.openFile(txn,name,true);;
试一试{
字节[]ba=ByteStreams.toByteArray(is);
LOG.info(“字节数组大小:+ba.length);//大小:3466
writeFile(txn,file).write(ba,0,ba.length);
}捕获(IOE异常){
e、 printStackTrace();
}
long fileSize=vfs.getFileLength(txn,文件);

LOG.info(“文件大小:”+fileSize);//大小:0方法
vfs.writeFile(txn,文件)
返回一个
OutputStream
实例,该实例应关闭以保存写入的数据。

如果将
executeInTransaction
替换为
executeInExclusiveTransaction
?@VyacheslavLukianov相同的结果,
getFileLength
的大小为零,文件大小为
0
的可能原因是什么
writeFile
方法中有缺陷吗?VFS的问题还在于,当您试图覆盖一个文件时,比如
file file=VFS.openFile(txn,name,true)
它附加流并损坏文件。似乎写入文件的新字节比文件中的其他字节短。为了解决这个问题,`
txn->{vfs.deleteFile(txn,name);file file=vfs.openFile(txn,name,true);}
但我觉得这不是正确的方法。它不应该附加。它在写入之前不清除文件的内容,它从一开始就写入现有内容。是的,我的意思是它写入但不删除现有字节,实现正常覆盖的正确方法是什么?
[qtp1007568224-16] WARN jetbrains.exodus.io.FileDataWriter - Can't open directory channel. Log directory fsync won't be performed.
[qtp1007568224-16] WARN jetbrains.exodus.io.FileDataWriter - Can't open directory channel. Log directory fsync won't be performed.
[qtp1007568224-16] INFO jetbrains.exodus.env.EnvironmentImpl - Exodus environment created: \tmp\xodus\master
[qtp1007568224-16] WARN jetbrains.exodus.io.FileDataWriter - Can't open directory channel. Log directory fsync won't be performed.
[qtp1007568224-16] INFO jetbrains.exodus.env.EnvironmentImpl - Exodus environment created: \tmp\xodus\ab5b92099ad443259b4deaf8df6facc4
[qtp1007568224-16] INFO com.backend.repository.jee.JeeXodusVFSRepository - Byte array size: 3466
[qtp1007568224-16] INFO com.backend.repository.jee.JeeXodusVFSRepository - File Size: 0
[qtp1007568224-16] INFO com.backend.resource.jee.JeeFileServerResource - File size=3466; File.created=1575274836678; File.name="index.html"; File.modified=1575274836678; File.etag=<null>; File.descriptor=261; File.url=<null>