Skip to content

Commit

Permalink
Removed XZ compression feature of serialized IValues
Browse files Browse the repository at this point in the history
Fixes #252
  • Loading branch information
DavyLandman committed Apr 3, 2024
1 parent 4164405 commit 060b304
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@
<artifactId>capsule</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.XZInputStream;
import org.tukaani.xz.XZOutputStream;
import com.github.luben.zstd.ZstdInputStream;
import com.github.luben.zstd.ZstdOutputStream;
import com.github.luben.zstd.util.Native;
Expand Down Expand Up @@ -61,7 +58,7 @@ public void setLevel(int level) {
return result;
}
case Header.Compression.XZ: {
return new XZOutputStream(rawStream, new LZMA2Options(level));
throw new IOException("XZ compression is not supported anymore, please use an older version of rascal/vallang to open the file and store it with a different level of compression");
}
case Header.Compression.ZSTD: {
return new ZstdOutputStream(rawStream, level);
Expand All @@ -78,7 +75,7 @@ public static InputStream wrapStream(InputStream raw, int algorithm) throws IOEx
case Header.Compression.GZIP:
return new GZIPInputStream(raw);
case Header.Compression.XZ:
return new XZInputStream(raw);
throw new IOException("XZ compression is not supported anymore, please use an older version of rascal/vallang to open the file and store it with a different level of compression");
case Header.Compression.ZSTD:
if (Compressor.zstdAvailable()) {
if (raw instanceof ByteBufferInputStream && ((ByteBufferInputStream)raw).getByteBuffer().isDirect()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public static final class Compression {
public static final byte NONE = 0;
public static final byte GZIP = 1;
/** Not used anymore, it was never used, and we're cutting down on dependencies */
public static final byte XZ = 2;
public static final byte ZSTD = 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.function.Supplier;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -49,6 +50,9 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier<TypeStore> t
while (read < currentHeader.length) {
read += in.read(currentHeader, read, currentHeader.length - read);
}
if (!Arrays.equals(currentHeader, Header.MAIN)) {
throw new IOException("Incorrect file header, are you sure this is a valid file containing a serialized value?");
}

int compression = in.read();
in = Compressor.wrapStream(in, compression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum CompressionRate {
Light(Header.Compression.ZSTD, 1),
Normal(Header.Compression.ZSTD, 5),
Strong(Header.Compression.ZSTD, 13),
Extreme(Header.Compression.XZ, 6),
Extreme(Header.Compression.ZSTD, 19),
XML(Compression.NONE, 0)
;

Expand Down

0 comments on commit 060b304

Please sign in to comment.