diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java b/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java index 6064136f..47df58ef 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java @@ -57,8 +57,8 @@ public void setLevel(int level) { result.setLevel(level); return result; } - case Header.Compression.XZ: { - 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.UNSUPPORTED_XZ: { + throw new UnsupportedOperationException("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); @@ -74,8 +74,8 @@ public static InputStream wrapStream(InputStream raw, int algorithm) throws IOEx return raw; case Header.Compression.GZIP: return new GZIPInputStream(raw); - case Header.Compression.XZ: - 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.UNSUPPORTED_XZ: + throw new UnsupportedOperationException("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()) { diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java b/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java index 6e9f58ee..7ca9ed79 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java @@ -17,8 +17,8 @@ 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; + /** Never officially available, but still reserved */ + public static final byte UNSUPPORTED_XZ = 2; public static final byte ZSTD = 3; } diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java index 4abac8f0..376bec90 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java @@ -51,7 +51,7 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier t 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?"); + throw new IOException("Incorrect file header, expected: [" + toHex(Header.MAIN) + "] but found: [" + toHex(currentHeader) + "]"); } int compression = in.read(); @@ -60,6 +60,15 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier t } + private String toHex(byte[] main) { + String result = ""; + for (byte b : main) { + result += String.format("%#04x ", b); + } + return result.trim(); + } + + public IValueInputStream(FileChannel channel, IValueFactory vf, Supplier typeStoreSupplier) throws IOException { this(new FileChannelDirectInputStream(channel), vf, typeStoreSupplier); }