当前位置:网站首页>Source code analysis of GZIPOutputStream class
Source code analysis of GZIPOutputStream class
2022-08-01 18:55:00 【51CTO】
这是 《水煮 JDK 源码》系列 的第5篇文章,计划撰写100篇关于JDK源码相关的文章
GZIPOutputStream 类位于 java.util.zip 包下,继承于 DeflaterOutputStream 类,它实现了一个流式过滤器,主要用于以GZIPfile format to write compressed data,其UML类图如下:

类声明如下:
1、成员变量
GZIPOutputStream 定义了1个成员变量,如下:
CRC32 Is a computational data flow CRC-32 Checksum class,Mainly used to verify the integrity of compressed data.
2、构造函数
创建 GZIPOutputStream The compressed output streams are mainly4种方式,如下:
GZIPOutputStream The class is mainly used for writingGZIPoutput stream of compressed data,Hence the need for a compressor Deflater.
3、写入数据方法
GZIPOutputStream The class provides a method to write data,其定义如下:
在创建 GZIPOutputStream When compressing the output stream,会使用 writeHeader() 方法写入GZIPmember header,So what header information will be written??You can look at the definition of this method:
从代码实现可以看出,will write in total10个字节的头信息,Include header information magic number、Compression method and various flags, etc.,These header information also need to be checked one by one when decompressing.
Have write head information method,There will naturally be a way to write tail information,about writing tail information writeTrailer() 方法定义如下:
上面调用的 writeInt() 方法定义如下:
4、其他方法
When all compressed data is written to the output stream,This time you can call to complete finish() 方法,如下:
5、测试应用
GZIPOutputStream Classes can be used to compress data,Then a sample code for compressing a string is given below:
运行程序后,Since it is a compressed string,So the output print is garbled.
边栏推荐
- A simple Flask PIN
- Leetcode74. Search 2D Matrix
- 三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.
- 【服务器数据恢复】服务器Raid5阵列mdisk组中多块磁盘离线的数据恢复案例
- 【LeetCode】Day109-最长回文串
- 【pyqt5】自定义控件 实现能够保持长宽比地缩放子控件
- COS User Practice Call for Papers
- Screen: GFF, OGS, Oncell, Incell of full lamination process
- Library website construction source code sharing
- SQL function TO_DATE (2)
猜你喜欢
随机推荐
TestNG多个xml进行自动化测试
Prometheus's Recording rules practice
483-82(23、239、450、113)
MySQL关系型数据库事务的ACID特性与实现方法
Industry Salon Phase II丨How to enable chemical companies to reduce costs and increase efficiency through supply chain digital business collaboration?
No need to crack, install Visual Studio 2013 Community Edition on the official website
暑假第一周总结博客
哈哈!一个 print 函数,还挺会玩啊!
How to use the Golang coroutine scheduler scheduler
突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
Library website construction source code sharing
Keras深度学习实战——交通标志识别
Use of message template placeholders
选择合适的 DevOps 工具,从理解 DevOps 开始
【木棉花】#夏日挑战赛# 鸿蒙小游戏项目——数独Sudoku(3)
The life cycle and scope
国标GB28181协议EasyGBS平台兼容老版本收流端口的功能实现
LeetCode 1374. Generate an odd number of each character string
modbus bus module DAM-8082
AntDB数据库亮相24届高速展,助力智慧高速创新应用








