package org.jeecg.modules.dnc.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public class CompressionUtils { public static byte[] gzipCompress(byte[] data) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bos)) { gzip.write(data); gzip.finish(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException("GZIP压缩失败", e); } } public static byte[] gzipDecompress(byte[] compressed) { try (ByteArrayInputStream bis = new ByteArrayInputStream(compressed); GZIPInputStream gzip = new GZIPInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream()) { byte[] buffer = new byte[1024]; int len; while ((len = gzip.read(buffer)) > 0) { bos.write(buffer, 0, len); } return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException("GZIP解压失败", e); } } }