Skip to content

Commit

Permalink
Improved error messages for header and xz
Browse files Browse the repository at this point in the history
  • Loading branch information
DavyLandman committed Apr 3, 2024
1 parent 060b304 commit 0c4c69b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier<TypeStore> 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();
Expand All @@ -60,6 +60,15 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier<TypeStore> t
}


private static 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<TypeStore> typeStoreSupplier) throws IOException {
this(new FileChannelDirectInputStream(channel), vf, typeStoreSupplier);
}
Expand Down

0 comments on commit 0c4c69b

Please sign in to comment.