Skip to content

Commit

Permalink
Add compression level
Browse files Browse the repository at this point in the history
  • Loading branch information
nck-mlcnv committed Dec 2, 2024
1 parent dde133c commit cbfcccc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 5 additions & 2 deletions schema/iguana-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@
"path": {
"type": "string"
},
"compression": {
"type": "boolean"
"compressionLevel": {
"type": "integer",
"minimum": 1,
"maximum": 19,
"default": 3
}
},
"required": [
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/aksw/iguana/cc/storage/impl/RDFFileStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.function.Supplier;

public class RDFFileStorage implements Storage {
public record Config(String path, Boolean compression) implements StorageConfig {
public record Config(String path, Integer compressionLevel) implements StorageConfig {
public Config(String path) {
this(path, true);
this(path, null);
}
}

Expand All @@ -43,10 +43,11 @@ public Config(String path) {
private final Lang lang;
private Path path;
private boolean compression;
private int compressionLevel;
private OutputStream outputStream;

public RDFFileStorage(Config config) {
this(config.path(), config.compression());
this(config.path(), config.compressionLevel());
}

/**
Expand All @@ -56,9 +57,13 @@ public RDFFileStorage() {
this("");
}

public RDFFileStorage(String filename, Boolean compression) {
public RDFFileStorage(String filename, Integer compressionLevel) {
this(filename);
this.compression = true;
if (compressionLevel != null && (compressionLevel < 1 || compressionLevel > 19)) {
throw new IllegalArgumentException("Compression level must be between 1 and 19.");
}
this.compression = compressionLevel != null;
this.compressionLevel = compressionLevel != null ? compressionLevel : 0;
}

/**
Expand Down Expand Up @@ -127,7 +132,7 @@ private OutputStream getFileOutputstream() throws IOException {
}

if (compression) {
final var process = new ProcessBuilder("zstd", "-o", path.toString() + ".zstd", "-T0", "-3", "-q", "-").start();
final var process = new ProcessBuilder("zstd", "-o", path.toString() + ".zstd", "-T0", "-" + compressionLevel, "-q", "-").start();
outputStream = process.getOutputStream();
return outputStream;
} else {
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/iguana-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@
"path": {
"type": "string"
},
"compression": {
"type": "boolean"
"compressionLevel": {
"type": "integer",
"minimum": 1,
"maximum": 19,
"default": 3
}
},
"required": [
Expand Down Expand Up @@ -357,7 +360,7 @@
}
},
"required": [
"endpoint"
"endpoint"
],
"title": "Template"
},
Expand Down

0 comments on commit cbfcccc

Please sign in to comment.