diff --git a/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java b/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java index 764f3eea..dd0dcc33 100644 --- a/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java +++ b/afs-cassandra/src/main/java/com/powsybl/afs/cassandra/CassandraAppStorage.java @@ -864,7 +864,7 @@ private DecompressOnceBinaryDataInputStream(UUID nodeUuid, String name, Row firs ByteArrayInputStream bais = new ByteArrayInputStream(tmp.toByteArray()); gzis = new GZIPInputStream(bais); } catch (IOException e) { - e.printStackTrace(); + throw new UncheckedIOException(e); } } diff --git a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraDataSplitTest.java b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraDataSplitTest.java index 11f3a57d..0941ffe9 100644 --- a/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraDataSplitTest.java +++ b/afs-cassandra/src/test/java/com/powsybl/afs/cassandra/CassandraDataSplitTest.java @@ -67,13 +67,8 @@ public void test() throws IOException { assertTrue(storage.removeData(nodeInfo.getId(), "a")); assertTrue(storage.getDataNames(nodeInfo.getId()).isEmpty()); assertFalse(storage.readBinaryData(nodeInfo.getId(), "a").isPresent()); -// } -// -// @Test -// public void testGzipOnce() throws IOException { + String data = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddddddddddeeeeeeeeeeeeeeeeeeeeefffffffffffffffffffffffff"; -// CassandraAppStorage storage = new CassandraAppStorage("test", () -> new CassandraTestContext(cassandraCQLUnit), -// new CassandraAppStorageConfig().setBinaryDataChunkSize(10), new InMemoryEventsBus()); NodeInfo rootNodeId2 = storage.createRootNodeIfNotExists("test", "folder"); NodeInfo nodeInfo2 = storage.createNode(rootNodeId2.getId(), "test1", "folder", "", 0, new NodeGenericMetadata()); try (OutputStream os = storage.writeBinaryData(nodeInfo2.getId(), "gzipOnce", AppStorage.CompressionMode.ONCE)) { diff --git a/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java b/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java index c1dca707..2560d525 100644 --- a/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java +++ b/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java @@ -56,6 +56,8 @@ public class ImportedCaseBuilder implements ProjectFileBuilder { private Importer importer; + private AppStorage.CompressionMode mode = AppStorage.CompressionMode.MULTI; + private final Properties parameters = new Properties(); public ImportedCaseBuilder(ProjectFileBuildContext context, ImportersLoader importersLoader, ImportConfig importConfig) { @@ -122,6 +124,11 @@ public ImportedCaseBuilder withParameters(Map parameters) { return this; } + public ImportedCaseBuilder setCompressMode(AppStorage.CompressionMode mode) { + this.mode = Objects.requireNonNull(mode); + return this; + } + @Override public ImportedCase build() { if (dataSource == null) { @@ -140,7 +147,7 @@ public ImportedCase build() { new NodeGenericMetadata().setString(ImportedCase.FORMAT, importer.getFormat())); // store case data - importer.copy(dataSource, new AppStorageDataSource(context.getStorage(), info.getId(), info.getName())); + importer.copy(dataSource, new AppStorageDataSource(context.getStorage(), info.getId(), info.getName(), mode)); // store parameters try (Writer writer = new OutputStreamWriter(context.getStorage().writeBinaryData(info.getId(), ImportedCase.PARAMETERS), StandardCharsets.UTF_8)) { diff --git a/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageDataSource.java b/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageDataSource.java index 836c351b..4fb33c2a 100755 --- a/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageDataSource.java +++ b/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageDataSource.java @@ -6,6 +6,10 @@ */ package com.powsybl.afs.storage; +import com.powsybl.commons.datasource.DataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,11 +19,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.powsybl.commons.datasource.DataSource; - /** * A datasource corresponding to a data blob stored in the file system. * A data blob is associated to a node and a name identifying it among data blobs of this node. @@ -30,6 +29,10 @@ public class AppStorageDataSource implements DataSource { private static final String SEPARATOR = "__"; + private static final AppStorage.CompressionMode DEFAULT_COMPRESS_MODE = AppStorage.CompressionMode.MULTI; + + private final AppStorage.CompressionMode compressMode; + public interface Name { static Name parse(String text) { @@ -132,9 +135,14 @@ public String toString() { private final String nodeName; public AppStorageDataSource(AppStorage storage, String nodeId, String nodeName) { + this(storage, nodeId, nodeName, DEFAULT_COMPRESS_MODE); + } + + public AppStorageDataSource(AppStorage storage, String nodeId, String nodeName, AppStorage.CompressionMode mode) { this.storage = Objects.requireNonNull(storage); this.nodeId = Objects.requireNonNull(nodeId); this.nodeName = Objects.requireNonNull(nodeName); + this.compressMode = Objects.requireNonNull(mode); } @Override @@ -147,7 +155,7 @@ public OutputStream newOutputStream(final String suffix, final String ext, boole if (append) { throw new UnsupportedOperationException("Append mode not supported"); } - return storage.writeBinaryData(nodeId, new SuffixAndExtension(suffix, ext).toString()); + return storage.writeBinaryData(nodeId, new SuffixAndExtension(suffix, ext).toString(), compressMode); } @Override @@ -156,7 +164,7 @@ public OutputStream newOutputStream(String fileName, boolean append) { if (append) { throw new UnsupportedOperationException("Append mode not supported"); } - return storage.writeBinaryData(nodeId, new FileName(fileName).toString()); + return storage.writeBinaryData(nodeId, new FileName(fileName).toString(), compressMode); } @Override