From 3349e5b8989f4d08aa07cc02a9f5ff0581994305 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 24 Nov 2025 13:51:48 -0600 Subject: [PATCH] clean up DhDataInputStream --- .../core/sql/dto/FullDataSourceV1DTO.java | 3 +- .../core/sql/dto/FullDataSourceV2DTO.java | 59 ++----------------- .../core/sql/repo/FullDataSourceV2Repo.java | 10 +++- .../dataStreams/DhDataInputStream.java | 31 +++++++--- core/src/test/java/tests/VarintTest.java | 4 +- 5 files changed, 39 insertions(+), 68 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java index e7db7bcb9..81c886a23 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java @@ -69,8 +69,7 @@ public class FullDataSourceV1DTO implements IBaseDTO /** @return a stream for the data contained in this DTO. */ public DhDataInputStream getInputStream() throws IOException { - InputStream inputStream = new ByteArrayInputStream(this.dataArray); - DhDataInputStream compressedStream = new DhDataInputStream(inputStream, EDhApiDataCompressionMode.LZ4); // LZ4 was used by DH before 2.1.0 and as such must be used until the render data format is changed to record the compressor + DhDataInputStream compressedStream = DhDataInputStream.create(this.dataArray, EDhApiDataCompressionMode.LZ4); // LZ4 was used by DH before 2.1.0 and as such must be used until the render data format is changed to record the compressor return compressedStream; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java index 10284c3a0..b04a1a516 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java @@ -354,17 +354,7 @@ public class FullDataSourceV2DTO ByteArrayList inputCompressedDataByteArray, LongArrayList[] outputDataLongArray, EDhApiDataCompressionMode compressionModeEnum) throws IOException, DataCorruptedException { - ByteArrayInputStream byteArrayInputStream; - if (compressionModeEnum == EDhApiDataCompressionMode.Z_STD) - { - byteArrayInputStream = new ByteArrayInputStream(Zstd.decompress(inputCompressedDataByteArray.toByteArray())); - } - else - { - byteArrayInputStream = new ByteArrayInputStream(inputCompressedDataByteArray.elements()); - } - - try (DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum)) + try (DhDataInputStream compressedIn = DhDataInputStream.create(inputCompressedDataByteArray.toByteArray(), compressionModeEnum)) { // read the data int dataArrayLength = FullDataSourceV2.WIDTH * FullDataSourceV2.WIDTH; @@ -569,17 +559,8 @@ public class FullDataSourceV2DTO maxZ = FullDataSourceV2.WIDTH-1; } - ByteArrayInputStream byteArrayInputStream; - if (compressionModeEnum == EDhApiDataCompressionMode.Z_STD) - { - byteArrayInputStream = new ByteArrayInputStream(Zstd.decompress(inputCompressedDataByteArray.toByteArray())); - } - else - { - byteArrayInputStream = new ByteArrayInputStream(inputCompressedDataByteArray.elements()); - } - try (DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum)) + try (DhDataInputStream compressedIn = DhDataInputStream.create(inputCompressedDataByteArray.toByteArray(), compressionModeEnum)) { // 1. column counts, preallocate for (int x = minX; x < maxX; x++) @@ -725,17 +706,7 @@ public class FullDataSourceV2DTO } private static void readBlobToGenerationSteps(ByteArrayList inputCompressedDataByteArray, ByteArrayList outputByteArray, EDhApiDataCompressionMode compressionModeEnum) throws IOException, DataCorruptedException { - ByteArrayInputStream byteArrayInputStream; - if (compressionModeEnum == EDhApiDataCompressionMode.Z_STD) - { - byteArrayInputStream = new ByteArrayInputStream(Zstd.decompress(inputCompressedDataByteArray.toByteArray())); - } - else - { - byteArrayInputStream = new ByteArrayInputStream(inputCompressedDataByteArray.elements()); - } - - try(DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum)) + try(DhDataInputStream compressedIn = DhDataInputStream.create(inputCompressedDataByteArray.toByteArray(), compressionModeEnum)) { compressedIn.readFully(outputByteArray.elements(), 0, FullDataSourceV2.WIDTH * FullDataSourceV2.WIDTH); } @@ -768,17 +739,7 @@ public class FullDataSourceV2DTO } private static void readBlobToWorldCompressionMode(ByteArrayList inputCompressedDataByteArray, ByteArrayList outputByteArray, EDhApiDataCompressionMode compressionModeEnum) throws IOException, DataCorruptedException { - ByteArrayInputStream byteArrayInputStream; - if (compressionModeEnum == EDhApiDataCompressionMode.Z_STD) - { - byteArrayInputStream = new ByteArrayInputStream(Zstd.decompress(inputCompressedDataByteArray.toByteArray())); - } - else - { - byteArrayInputStream = new ByteArrayInputStream(inputCompressedDataByteArray.elements()); - } - - try(DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum)) + try(DhDataInputStream compressedIn = DhDataInputStream.create(inputCompressedDataByteArray.toByteArray(), compressionModeEnum)) { compressedIn.readFully(outputByteArray.elements(), 0, FullDataSourceV2.WIDTH * FullDataSourceV2.WIDTH); } @@ -808,17 +769,7 @@ public class FullDataSourceV2DTO } private static FullDataPointIdMap readBlobToDataMapping(ByteArrayList inputCompressedDataByteArray, long pos, @NotNull ILevelWrapper levelWrapper, EDhApiDataCompressionMode compressionModeEnum) throws IOException, InterruptedException, DataCorruptedException { - ByteArrayInputStream byteArrayInputStream; - if (compressionModeEnum == EDhApiDataCompressionMode.Z_STD) - { - byteArrayInputStream = new ByteArrayInputStream(Zstd.decompress(inputCompressedDataByteArray.toByteArray())); - } - else - { - byteArrayInputStream = new ByteArrayInputStream(inputCompressedDataByteArray.elements()); - } - - try (DhDataInputStream compressedIn = new DhDataInputStream(byteArrayInputStream, compressionModeEnum)) + try (DhDataInputStream compressedIn = DhDataInputStream.create(inputCompressedDataByteArray.toByteArray(), compressionModeEnum)) { FullDataPointIdMap mapping = FullDataPointIdMap.deserialize(compressedIn, pos, levelWrapper); return mapping; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java index b8af16e75..ba864543f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java @@ -572,9 +572,15 @@ public class FullDataSourceV2Repo extends AbstractDhRepo