<>Gzip Decompression code implementation

1. Running virtual machines
2. stay Idea of Maven Package code in
3. Drag the packaged file into the virtual machine
4. implement jar package

stay Idea of Maven Package code in :

take xml File compressed into gzip file :
/** * @Time : 2021/10/23 15:24 * @Auther : Carapace * @File :
DeflateCodeDemo.java * Software: IntelliJ IDEA */ package com.GzipCodeDemo;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.IOUtils
; import org.apache.hadoop.io.compress.CompressionCodec; import org.apache.
hadoop.io.compress.CompressionOutputStream; import org.apache.hadoop.util.
ReflectionUtils; import java.io.FileInputStream; import java.io.FileOutputStream
; public class GzipCodeDemo { public static void main(String[] args) throws
Exception { String inpath="/home/atguigu/comments.xml"; // Choose the original file path by yourself String
outpath="/home/atguigu/comments.gzip"; // Choose the compressed file path by yourself Configuration conf = new
Configuration(); // Compression type String codecClassname =
"org.apache.hadoop.io.compress.GzipCodec"; Class<?> codecClass = Class.forName(
codecClassname); // The first way to create an instance of compression type CompressionCodec codec = (CompressionCodec)
ReflectionUtils.newInstance(codecClass,conf); // basis outoath Output path and output stream packaging , Generate a new compressed stream
FileOutputStream fos = new FileOutputStream(outpath); // Create output compression class
CompressionOutputStream comOut = codec.createOutputStream(fos);
// According to compression path inpath And write to the stream IOUtils.copyBytes(new FileInputStream(inpath),comOut,1024,
false); comOut.finish(); } }
decompression gzip Decompress the file into xml file :
/** * @Time : 2021/10/23 18:20 * @Auther : Carapace * @File :
DeflateCodeDemo2.java * Software: IntelliJ IDEA */ package com.GzipCodeDemo;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.IOUtils
; import org.apache.hadoop.io.compress.CompressionInputStream; import org.apache
.hadoop.io.compress.GzipCodec; import org.apache.hadoop.util.ReflectionUtils;
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.
IOException; public class GzipCodeDemo2 { public static void main(String[] args)
throws IOException { String inputpath = "/home/atguigu/comments.gzip";
// Choose the original file path by yourself String outputpath = "/home/atguigu/gzip_comments.xml";
// Choose the path of the extracted file by yourself Configuration conf = new Configuration(); // Direct instantiation codec object
GzipCodec codec = new GzipCodec(); // Check and set conf object ReflectionUtils.setConf(codec,
conf); // Create compressed stream CompressionInputStream comIn = codec.createInputStream(new
FileInputStream(inputpath)); // Write stream IOUtils.copyBytes(comIn, new FileOutputStream
(outputpath), 1024); comIn.close(); } }
Then in Idea Package in , stay Maven Middle first clean, then package

stay target Generate files in , File location found , Load into virtual machine

In virtual machine function code :
hadoop jar + Package name + copy Reference( Package name class name )
notes : If the package name feels long , You can change it yourself
How to obtain package name and class name :

Technology
©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage MySQL Basics Commonly used sentence ( Add / delete / modify query )C Language of a Gobang game implementation QT5.9 Use of learning notes QSqlQuery Method of Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control java Polymorphic array of web Front end signature plug-in _signature_pad Plug in implements electronic signature function centos7 install RabbitMqspringboot use redis Experiment 4 Automated test tools - software test