.Q.gz - Not in Gzip format in java

https://learninghub.kx.com/forums/topic/q-gz-not-in-gzip-format-in-java

https://code.kx.com/q/ref/dotq/#gz-gzip

Unexpected exception thrown: java.util.zip.ZipException: Not in GZIP format

Is the compression result of .Q.gz different from the GZIP format?

File compression | Database | kdb+ and q documentation - kdb+ and q documentation (kx.com)

  • Use set and not gzip: they produce different results.

The question is vague on what you are trying to do and how (no example code etc.)

Below is an example which when run results in:

HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello

Java can decompress the data which kdb+ compressed with .Q.gz without issue:

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.zip.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.lang.String;
import com.kx.c;
public class Main {
    public static String decompress(final byte[] bytes) throws IOException {
        if (bytes == null || bytes.length == 0) {
            return "";
        }
        try (final GZIPInputStream ungzip = new GZIPInputStream(new ByteArrayInputStream(bytes))) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            final byte[] data = new byte[8192];
            int nRead;
            while ((nRead = ungzip.read(data)) != -1) {
                out.write(data, 0, nRead);
            }
            return out.toString();
        }
    }
    public static void main(String[] args) {
        c c = null;
        Object result = null;
        byte[] bytes = null;
        try {
            c = new c("localhost", 5001);
            String query="`byte$.Q.gz(9;400#"Hello")";
            result = c.k(query);
            bytes = ((byte[]) result);
            System.out.println(decompress(bytes));
        } catch (Exception e){
            System.err.println(e.toString());
        }
    }
}