当前位置:网站首页>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.
边栏推荐
- Leetcode73. Matrix Zeroing
- el-form-item prop属性动态绑定不生效如何解决
- log factory (detail)
- LeetCode 1374.生成每种字符都是奇数个的字符串
- Zabbix6.0钉钉机器人告警
- Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
- Go iota关键字与枚举类型实现原理是什么
- Redis的内存淘汰策略和过期删除策略的区别是什么
- 【木棉花】#夏日挑战赛# 鸿蒙小游戏项目——数独Sudoku(3)
- 钳形万用表使用方法,如何测量电压、电流、电阻?
猜你喜欢
随机推荐
MySQL数据库————存储过程和函数
LeetCode 0151.颠倒字符串中的单词
TestNG多个xml进行自动化测试
mysql函数的作用有哪些
Map by value
SQL函数 TO_DATE(二)
MySQL关系型数据库事务的ACID特性与实现方法
odoo+物联网
MySQL数据库————流程控制
XML配置
无需破解,官网安装Visual Studio 2013社区版
ExcelPatternTool: Excel表格-数据库互导工具
AntDB数据库亮相24届高速展,助力智慧高速创新应用
How to use the Golang coroutine scheduler scheduler
屏:全贴合工艺之GFF、OGS、Oncell、Incell
如何记录分析你的炼丹流程—可视化神器Wandb使用笔记【1】
LeetCode 0151. Reverse a string of words
ExcelPatternTool: Excel表格-数据库互导工具
Summer vacation second week wrap-up blog
opencv如何实现图像倾斜校正