Home › Forums › kdb+ › .Q.gz – Not in Gzip format in java › Reply To: .Q.gz – Not in Gzip format in java
-
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 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 7 months, 2 weeks ago by
rocuinneagain.
-
This reply was modified 5 months, 3 weeks ago by
Carey.
-
This reply was modified 5 months, 3 weeks ago by
Carey.
-
This reply was modified 7 months, 2 weeks ago by