You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2020/02/25 12:34:31 UTC

[incubator-iotdb] branch FileClosedDebug updated: add reopen operation

This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch FileClosedDebug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/FileClosedDebug by this push:
     new 8413a61  add reopen operation
8413a61 is described below

commit 8413a613ff20dbfd37ea88f5297b9ee1eae0d5fe
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Tue Feb 25 20:34:18 2020 +0800

    add reopen operation
---
 .../org/apache/iotdb/tsfile/read/reader/DefaultTsFileInput.java  | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/DefaultTsFileInput.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/DefaultTsFileInput.java
index 471d89f..0bdb408 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/DefaultTsFileInput.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/DefaultTsFileInput.java
@@ -37,11 +37,11 @@ public class DefaultTsFileInput implements TsFileInput {
 
   FileChannel channel;
 
-  private String path;
+  private Path path;
 
   public DefaultTsFileInput(Path file) throws IOException {
     channel = FileChannel.open(file, StandardOpenOption.READ);
-    path = file.toString();
+    path = file;
   }
 
   @Override
@@ -67,10 +67,13 @@ public class DefaultTsFileInput implements TsFileInput {
 
   @Override
   public int read(ByteBuffer dst, long position) throws IOException {
+    if (!channel.isOpen()) {
+      channel = FileChannel.open(path, StandardOpenOption.READ);
+    }
     try {
       return channel.read(dst, position);
     } catch (ClosedChannelException e) {
-      LOGGER.error("File is closed while reading {}", path);
+      LOGGER.error("File is closed while reading {}", path.toString());
       throw e;
     }
   }