首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xodus VFS无法持久存储字节

Xodus VFS无法持久存储字节
EN

Stack Overflow用户
提问于 2019-12-03 16:20:22
回答 1查看 49关注 0票数 0

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

代码语言:javascript
复制
  @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];
  }

下面是日志:

代码语言:javascript
复制
[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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-03 21:42:58

vfs.writeFile(txn, file)方法返回一个OutputStream实例,应该关闭该实例以保存写入的数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59152765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档