()
| 46 | public final TemporaryFolder temp = new TemporaryFolder(); |
| 47 | |
| 48 | @Test |
| 49 | public void testGzip() throws Exception { |
| 50 | try (Path path = new Path()) { |
| 51 | File outFile = temp.newFile("x"); |
| 52 | File expected = new File(Files.getResourcePath(getClass().getResource("/zip-test/large.csv"))); |
| 53 | |
| 54 | final int available = 64 * 1024; |
| 55 | long in = Unsafe.malloc(available, MemoryTag.NATIVE_DEFAULT); |
| 56 | long out = Unsafe.malloc(available / 2, MemoryTag.NATIVE_DEFAULT); |
| 57 | try { |
| 58 | long strm = Zip.deflateInit(); |
| 59 | try { |
| 60 | |
| 61 | long pIn = 0; |
| 62 | long pOut = 0; |
| 63 | long fdIn = Files.openRO(path.of(expected.getAbsolutePath()).$()); |
| 64 | try { |
| 65 | long fdOut = Files.openRW(path.of(outFile.getAbsolutePath()).$()); |
| 66 | try { |
| 67 | // header |
| 68 | Files.write(fdOut, Zip.gzipHeader, Zip.gzipHeaderLen, pOut); |
| 69 | pOut += Zip.gzipHeaderLen; |
| 70 | |
| 71 | int len; |
| 72 | int crc = 0; |
| 73 | while ((len = (int) Files.read(fdIn, in, available, pIn)) > 0) { |
| 74 | pIn += len; |
| 75 | Zip.setInput(strm, in, len); |
| 76 | crc = Zip.crc32(crc, in, len); |
| 77 | do { |
| 78 | int ret; |
| 79 | if ((ret = Zip.deflate(strm, out, available, false)) < 0) { |
| 80 | throw new FatalError("Error in deflator: " + ret); |
| 81 | } |
| 82 | |
| 83 | int have = available - Zip.availOut(strm); |
| 84 | if (have > 0) { |
| 85 | Files.write(fdOut, out, have, pOut); |
| 86 | pOut += have; |
| 87 | } |
| 88 | |
| 89 | } while (Zip.availIn(strm) > 0); |
| 90 | } |
| 91 | |
| 92 | int ret; |
| 93 | do { |
| 94 | if ((ret = Zip.deflate(strm, out, available, true)) < 0) { |
| 95 | throw new FatalError("Error in deflator: " + ret); |
| 96 | } |
| 97 | |
| 98 | int have = available - Zip.availOut(strm); |
| 99 | if (have > 0) { |
| 100 | Files.write(fdOut, out, have, pOut); |
| 101 | pOut += have; |
| 102 | } |
| 103 | } while (ret != 1); |
| 104 | |
| 105 | // write trailer |
nothing calls this directly
no test coverage detected