-
.Q.gz – Not in Gzip format in java
Posted by k-mambo on September 27, 2024 at 5:59 amhttps://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?
code.kx.com
The .Q namespace – tools | Reference | kdb+ and q documentation - kdb+ and q documentation
The .Q namespace contains utility objects for q programming
rocuinneagain replied 4 months, 4 weeks ago 3 Members · 2 Replies -
2 Replies
-
File compression | Database | kdb+ and q documentation – kdb+ and q documentation (kx.com)
- Use set and not gzip: they produce different results.
code.kx.com
File compression | Database | kdb+ and q documentation - kdb+ and q documentation
How to work with compressed files in kdb+
-
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()); } } }
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 4 months, 4 weeks ago by
rocuinneagain.
-
This reply was modified 3 months ago by
supportelearningwp-com.
-
This reply was modified 3 months ago by
supportelearningwp-com.
-
This reply was modified 4 months, 4 weeks ago by
Log in to reply.