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

spricoder pushed a commit to branch object_type
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/object_type by this push:
     new e940c15a10f update write interface return to byte[]
e940c15a10f is described below

commit e940c15a10f2b556bc51e1ede276fda8c4cbe02b
Author: spricoder <[email protected]>
AuthorDate: Mon Jul 7 15:10:47 2025 +0800

    update write interface return to byte[]
---
 .../rpc/model/CompressedTsFileModelWriter.java     | 49 ++--------------------
 .../org/apache/iotdb/rpc/model/ModelWriter.java    | 10 ++++-
 .../rpc/model/UnCompressedTiffModelWriter.java     |  4 +-
 .../apache/iotdb/db/utils/model/ModelReader.java   | 14 +++++++
 4 files changed, 29 insertions(+), 48 deletions(-)

diff --git 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/CompressedTsFileModelWriter.java
 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/CompressedTsFileModelWriter.java
index 27468c696af..8d70a5bb7fa 100644
--- 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/CompressedTsFileModelWriter.java
+++ 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/CompressedTsFileModelWriter.java
@@ -19,7 +19,6 @@
 
 package org.apache.iotdb.rpc.model;
 
-import org.apache.thrift.TException;
 import org.apache.tsfile.common.conf.TSFileDescriptor;
 import org.apache.tsfile.enums.ColumnCategory;
 import org.apache.tsfile.enums.TSDataType;
@@ -34,13 +33,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
 import java.util.Collections;
 
 public class CompressedTsFileModelWriter extends ModelWriter {
@@ -48,7 +43,7 @@ public class CompressedTsFileModelWriter extends ModelWriter {
   private static final int DEFAULT_CHUNK_NUMBER = 128 * 128;
 
   @Override
-  void write(String filePath, float[] values, int width, int height) {
+  byte[] write(float[] values, int width, int height) {
     try {
 
       TSFileDescriptor.getInstance().getConfig().setGroupSizeInByte(1);
@@ -87,47 +82,11 @@ public class CompressedTsFileModelWriter extends 
ModelWriter {
           tablet.reset();
         }
       }
-      // SpriCoder write byteBuffer to file
-      ByteBuffer buffer = tsFileOutput.getByteBuffer();
-      createFile(filePath);
-      buffer.position(0); // 重置读取位置(安全措施)
-
-      try (FileChannel channel = FileChannel.open(Paths.get(filePath), 
StandardOpenOption.WRITE)) {
-
-        while (buffer.hasRemaining()) {
-          channel.write(buffer); // 零拷贝直接写入
-        }
-        buffer.flip(); // 恢复原始状态
-
-        // 强制磁盘同步(可靠性要求高的场景使用)
-        channel.force(true); // 强制元数据和内容写入磁盘
-      }
+      return tsFileOutput.getByteBuffer().array();
     } catch (Exception e) {
-      e.printStackTrace();
-    }
-  }
-
-  private void createFile(String filePath) throws TException {
-    File file = new File(filePath);
-    File directory = file.getParentFile();
-
-    if (directory != null && !directory.exists()) {
-      boolean isCreated = directory.mkdirs();
-      if (!isCreated) {
-        LOGGER.error("directory create failed please check");
-        throw new TException("insert Grid error ");
-      }
-    }
-    try {
-      boolean newFile = file.createNewFile();
-      if (!newFile) {
-        LOGGER.error("createNewFile failed please check");
-        throw new TException("insert Grid error ");
-      }
-    } catch (IOException e) {
-      LOGGER.error("createNewFile failed please check");
-      throw new TException("insert Grid error ");
+      LOGGER.error("write tsfile failed", e);
     }
+    return new byte[0];
   }
 
   private static class MemoryTsFileOutput implements TsFileOutput {
diff --git 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/ModelWriter.java
 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/ModelWriter.java
index 09f5f77a278..923c896648e 100644
--- 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/ModelWriter.java
+++ 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/ModelWriter.java
@@ -20,7 +20,15 @@
 package org.apache.iotdb.rpc.model;
 
 public abstract class ModelWriter {
-  abstract void write(String filePath, float[] values, int width, int height);
+  /**
+   * Write float[] to specific type of file, eg. tsfile, tiff
+   *
+   * @param values the float values of image
+   * @param width the width of image
+   * @param height the height of image
+   * @return the byte array of the file
+   */
+  abstract byte[] write(float[] values, int width, int height);
 
   public ModelWriter getInstance(ModelWriterType modelFileType) {
     switch (modelFileType) {
diff --git 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/UnCompressedTiffModelWriter.java
 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/UnCompressedTiffModelWriter.java
index 629dfc8cde6..7276135a70e 100644
--- 
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/UnCompressedTiffModelWriter.java
+++ 
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/model/UnCompressedTiffModelWriter.java
@@ -25,10 +25,10 @@ import ij.process.FloatProcessor;
 
 public class UnCompressedTiffModelWriter extends ModelWriter {
   @Override
-  void write(String filePath, float[] values, int width, int height) {
+  byte[] write(float[] values, int width, int height) {
     FloatProcessor floatProcessor = new FloatProcessor(width, height, values);
     ImagePlus imp = new ImagePlus("first level", floatProcessor);
     FileSaver fs = new FileSaver(imp);
-    fs.saveAsTiff(filePath);
+    return fs.serialize();
   }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/model/ModelReader.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/model/ModelReader.java
index 2dcb4c6834d..f98f9a3d78a 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/model/ModelReader.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/model/ModelReader.java
@@ -22,8 +22,22 @@ package org.apache.iotdb.db.utils.model;
 import java.util.List;
 
 public abstract class ModelReader {
+  /**
+   * Read all float values from a file, eg. tsfile, tiff
+   *
+   * @param filePath the path of the file to read
+   * @return the float array of the image
+   */
   abstract float[] readAll(String filePath);
 
+  /**
+   * Read part of float values from a file, eg. tsfile, tiff
+   *
+   * @param filePath the path of the file to read
+   * @param startAndEndTimeArray a list of start and end time pairs, each pair 
is a list of two
+   *     integers
+   * @return a list of float arrays, each array corresponds to a start and end 
time pair
+   */
   abstract List<float[]> penetrate(String filePath, List<List<Integer>> 
startAndEndTimeArray);
 
   public ModelReader getInstance(ModelReaderType modelFileType) {

Reply via email to