Module bus.core

Class GzipSink

java.lang.Object
org.miaixz.bus.core.io.sink.GzipSink
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Sink

public class GzipSink extends Object implements Sink
GZIP 格式压缩接收器,使用 Deflater 进行压缩,仅在必要时调用 flush 以优化性能。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
    GzipSink(Sink sink)
    构造方法,初始化 GZIP 接收器。
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    关闭接收器,完成压缩并释放资源。
    final Deflater
    获取压缩器以访问统计信息、字典、压缩级别等。
    void
    刷新缓冲区,推送压缩数据到目标。
    获取接收器的超时配置。
    void
    write(Buffer source, long byteCount)
    从源缓冲区读取指定字节数并写入压缩数据。

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GzipSink

      public GzipSink(Sink sink)
      构造方法,初始化 GZIP 接收器。
      Parameters:
      sink - 底层接收器
      Throws:
      IllegalArgumentException - 如果 sink 为 null
  • Method Details

    • write

      public void write(Buffer source, long byteCount) throws IOException
      从源缓冲区读取指定字节数并写入压缩数据。
      Specified by:
      write in interface Sink
      Parameters:
      source - 数据源缓冲区
      byteCount - 要读取的字节数
      Throws:
      IOException - 如果写入失败
      IllegalArgumentException - 如果 byteCount 小于 0
    • flush

      public void flush() throws IOException
      刷新缓冲区,推送压缩数据到目标。
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface Sink
      Throws:
      IOException - 如果刷新失败
    • timeout

      public Timeout timeout()
      获取接收器的超时配置。
      Specified by:
      timeout in interface Sink
      Returns:
      超时对象
    • close

      public void close() throws IOException
      关闭接收器,完成压缩并释放资源。
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Sink
      Throws:
      IOException - 如果关闭失败
    • deflater

      public final Deflater deflater()
      获取压缩器以访问统计信息、字典、压缩级别等。
      Returns:
      压缩器对象