Class GzipUtil

java.lang.Object
com.sure.tool.io.GzipUtil

public class GzipUtil extends Object
GZIP 压缩工具类:字符串/字节数组/文件压缩与解压,基于 JDK 内置 GZIP 实现,零依赖。
Since:
0.2.0
Author:
suretool
  • Method Details

    • gzip

      public static byte[] gzip(byte[] data) throws IOException
      压缩字节数组。
      Parameters:
      data - 原始字节
      Returns:
      GZIP 压缩后字节
      Throws:
      IOException - IO 异常
    • ungzip

      public static byte[] ungzip(byte[] data) throws IOException
      解压 GZIP 字节数组。
      Parameters:
      data - GZIP 压缩字节
      Returns:
      原始字节
      Throws:
      IOException - IO 异常
    • gzip

      public static byte[] gzip(String content) throws IOException
      压缩字符串为 GZIP 字节(UTF-8)。
      Parameters:
      content - 字符串
      Returns:
      GZIP 字节
      Throws:
      IOException - IO 异常
    • gzip

      public static byte[] gzip(String content, Charset charset) throws IOException
      压缩字符串为 GZIP 字节(指定字符集)。
      Parameters:
      content - 字符串
      charset - 字符集
      Returns:
      GZIP 字节
      Throws:
      IOException - IO 异常
    • ungzipString

      public static String ungzipString(byte[] data) throws IOException
      解压 GZIP 字节为字符串(UTF-8)。
      Parameters:
      data - GZIP 字节
      Returns:
      原始字符串
      Throws:
      IOException - IO 异常
    • ungzipString

      public static String ungzipString(byte[] data, Charset charset) throws IOException
      解压 GZIP 字节为字符串(指定字符集)。
      Parameters:
      data - GZIP 字节
      charset - 字符集
      Returns:
      原始字符串
      Throws:
      IOException - IO 异常
    • gzipFile

      public static void gzipFile(Path src, Path dest) throws IOException
      压缩文件为 GZIP 文件。
      Parameters:
      src - 源文件
      dest - 目标 .gz 文件
      Throws:
      IOException - IO 异常
    • ungzipFile

      public static void ungzipFile(Path src, Path dest) throws IOException
      解压 GZIP 文件为普通文件。
      Parameters:
      src - .gz 源文件
      dest - 目标文件
      Throws:
      IOException - IO 异常