当前位置:网站首页>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.
边栏推荐
- [Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)
- shell脚本专题(07):文件由cfs到bos
- explain each field introduction
- #yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list
- WinRAR | Generate multiple installers into one installer
- 哈哈!一个 print 函数,还挺会玩啊!
- 面试必问的HashCode技术内幕
- GZIPOutputStream 类源码分析
- 亚马逊云科技Build On2022技能提升计划第二季——揭秘出海爆款新物种背后的黑科技
- 英国伦敦大学|眼科强化学习:潜在应用和实施挑战
猜你喜欢
随机推荐
mysql函数的作用有哪些
A simple Flask PIN
Map by value
腾讯云主机安全 x 轻量应用服务器|强强联合主机安全普惠版重磅发布
MySQL关系型数据库事务的ACID特性与实现方法
COS 用户实践征文
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
How opencv implements image skew correction
ExcelPatternTool: Excel表格-数据库互导工具
Go GORM事务实例分析
行业沙龙第二期丨如何通过供应链数字化业务协同,赋能化工企业降本增效?
Redis的内存淘汰策略和过期删除策略的区别是什么
#yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list
请你说说多线程
在GBase 8c数据库后台,使用什么样的命令来对gtm、dn节点进行主备切换的操作?
2022年 PHP面试问题记录
Break the performance ceiling!AsiaInfo database supports more than 1 billion users, with a peak of one million transactions per second
突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
用VS2013编译带boost库程序时提示 fatal error C1001: 编译器中发生内部错误
塔防海岸线用户协议