1919
2020package org .apache .iotdb .rpc .model ;
2121
22- import org .gdal .VsiGdalNative ;
2322import org .gdal .gdal .Band ;
2423import org .gdal .gdal .Dataset ;
2524import org .gdal .gdal .Driver ;
2827
2928public class CompressedTiffModelProcessor extends ModelProcessor {
3029 private static final Driver DRIVER ;
30+ private static final String VIRTUAL_FILE_PATH_PREFIX = "/vsimem" ;
31+ private static final String VIRTUAL_FILE_PATH_SUFFIX = ".tif" ;
3132 // Specifying compression options
3233 private static String compressOption = "COMPRESS=LZW" ;
3334 // Specifying block x size options
@@ -46,7 +47,11 @@ public class CompressedTiffModelProcessor extends ModelProcessor {
4647 @ Override
4748 public byte [] write (float [] values , int width , int height ) {
4849 String virtualFilePath = getVirtualFilePath ();
49- return write (virtualFilePath , values , width , height );
50+ try {
51+ return write (virtualFilePath , values , width , height );
52+ } finally {
53+ gdal .Unlink (virtualFilePath );
54+ }
5055 }
5156
5257 private byte [] write (String filePath , float [] values , int width , int height ) {
@@ -71,7 +76,7 @@ private byte[] write(String filePath, float[] values, int width, int height) {
7176 }
7277 band .FlushCache ();
7378 dataset .FlushCache ();
74- return VsiGdalNative . vsiGetMemFileBuffer (filePath , true );
79+ return gdal . GetMemFileBuffer (filePath );
7580 } finally {
7681 if (dataset != null ) {
7782 dataset .delete ();
@@ -81,10 +86,13 @@ private byte[] write(String filePath, float[] values, int width, int height) {
8186
8287 @ Override
8388 public float [] readAll (byte [] fileBytes ) {
84- // TODO @spricoder
8589 String virtualFilePath = getVirtualFilePath ();
86- VsiGdalNative .writeVsiMemFile (virtualFilePath , fileBytes );
87- return readAll (virtualFilePath );
90+ try {
91+ gdal .FileFromMemBuffer (virtualFilePath , fileBytes );
92+ return readAll (virtualFilePath );
93+ } finally {
94+ gdal .Unlink (virtualFilePath );
95+ }
8896 }
8997
9098 @ Override
@@ -110,6 +118,9 @@ public float[] readAll(String filePath) {
110118 }
111119
112120 private String getVirtualFilePath () {
113- return "" ;
121+ long tid = Thread .currentThread ().getId ();
122+ long timestamp = System .currentTimeMillis ();
123+ return String .format (
124+ "%s/%d_%d%s" , VIRTUAL_FILE_PATH_PREFIX , tid , timestamp , VIRTUAL_FILE_PATH_SUFFIX );
114125 }
115126}
0 commit comments