• Hadoop文件压缩放到远程centos调试


    文件压缩

    1、准备代码

    package com.cr.compress;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.io.IOUtils;
    import org.apache.hadoop.io.compress.*;
    import org.apache.hadoop.util.ReflectionUtils;
    
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class compressTest {
        public static void main(String[] args) throws IOException {
            Class[] zipclass = {
                    DeflateCodec.class,
                    GzipCodec.class,
                    BZip2Codec.class,
            };
            for(Class c : zipclass){
                commonCompress(c);
            }
        }
        
        public static void commonCompress(Class codecClass) throws IOException {
            //获取当前系统毫秒数
            long start = System.currentTimeMillis();
            //实例化
            CompressionCodec codec =  (CompressionCodec) ReflectionUtils.newInstance(codecClass,new Configuration());
            //创建文件输出流,
            FileOutputStream fos =  new FileOutputStream("/home/xiaoqiu/zip" + codec.getDefaultExtension());
            //得到文件压缩流
            CompressionOutputStream zipout = codec.createOutputStream(fos);
            IOUtils.copyBytes(new FileInputStream("/home/xiaoqiu/compress/hello.txt"),zipout,1024);
            zipout.close();
            System.out.println(codecClass.getSimpleName() + " : " + (System.currentTimeMillis()-start) + "ms");
    
        }
    
        public static void unzip(Class codecClass) throws IOException {
            //获取当前系统毫秒数
            long start = System.currentTimeMillis();
            //实例化
            CompressionCodec codec =  (CompressionCodec) ReflectionUtils.newInstance(codecClass,new Configuration());
            //创建文件输入流,
            FileInputStream fis  =  new FileInputStream("/home/xiaoqiu/zip" + codec.getDefaultExtension());
            //得到文件压缩流
            CompressionInputStream zipIn = codec.createInputStream(fis);
            IOUtils.copyBytes(zipIn,new FileOutputStream("/home/xiaoqiu/compress/unzip" + codec.getDefaultExtension() + ".txt"),1024);
            zipIn.close();
            System.out.println(codecClass.getSimpleName() + " : " + (System.currentTimeMillis()-start) + "ms");
        }
    
    }
    

    2、生成jar包










    3、远程调试

    [xiaoqiu@s150 /home/xiaoqiu]$ hadoop jar compress.jar com.cr.compress.compressTest
    

    报错:
    Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
            at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:284)
            at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:238)
            at java.util.jar.JarVerifier.processEntry(JarVerifier.java:316)
            at java.util.jar.JarVerifier.update(JarVerifier.java:228)
            at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
            at java.util.jar.JarFile.getInputStream(JarFile.java:450)
            at org.apache.hadoop.util.RunJar.unJar(RunJar.java:101)
            at org.apache.hadoop.util.RunJar.unJar(RunJar.java:81)
            at org.apache.hadoop.util.RunJar.run(RunJar.java:209)
            at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
    

    解决:
    删除MET-INF下面的.SF文件




    4、调试成功

    [xiaoqiu@s150 /home/xiaoqiu]$ hadoop jar compress.jar com.cr.compress.compressTest
    17/12/30 14:05:07 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
    17/12/30 14:05:08 INFO compress.CodecPool: Got brand-new compressor [.deflate]
    DeflateCodec : 2470ms
    17/12/30 14:05:08 INFO compress.CodecPool: Got brand-new compressor [.gz]
    GzipCodec : 62ms
    17/12/30 14:05:08 WARN bzip2.Bzip2Factory: Failed to load/initialize native-bzip2 library system-native, will use pure-Java version
    17/12/30 14:05:08 INFO compress.CodecPool: Got brand-new compressor [.bz2]
    BZip2Codec : 145ms
    



    文件解压缩

    1、准备代码

    改变main函数
    public static void main(String[] args) throws IOException {
            Class[] zipclass = {
                    DeflateCodec.class,
                    GzipCodec.class,
                    BZip2Codec.class,
            };
            for(Class c : zipclass){
    //            commonCompress(c);
                unzip(c);
            }
        }

    2、重新生成jar包

    这里生成artifact的时候,选择all modules,否则找不到类,因为我的类是在Java模块里面的


    查看类路径是否存在类




    3、远程调试

    [xiaoqiu@s150 /home/xiaoqiu]$ hadoop jar compress.jar com.cr.compress.compressTest
    17/12/30 15:12:25 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
    17/12/30 15:12:26 INFO compress.CodecPool: Got brand-new decompressor [.deflate]
    DeflateCodec : 2666ms
    17/12/30 15:12:26 INFO compress.CodecPool: Got brand-new decompressor [.gz]
    GzipCodec : 78ms
    17/12/30 15:12:26 WARN bzip2.Bzip2Factory: Failed to load/initialize native-bzip2 library system-native, will use pure-Java version
    17/12/30 15:12:26 INFO compress.CodecPool: Got brand-new decompressor [.bz2]
    BZip2Codec : 97ms
    
    [xiaoqiu@s150 /home/xiaoqiu/compress]$ ll
    total 16
    -rw-rw-r--. 1 xiaoqiu xiaoqiu 18 Dec 30 09:51 hello.txt
    -rw-rw-r--. 1 xiaoqiu xiaoqiu 18 Dec 30 15:12 unzip.bz2.txt
    -rw-rw-r--. 1 xiaoqiu xiaoqiu 18 Dec 30 15:12 unzip.deflate.txt
    -rw-rw-r--. 1 xiaoqiu xiaoqiu 18 Dec 30 15:12 unzip.gz.txt
    [xiaoqiu@s150 /home/xiaoqiu/compress]$
    





    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    zepto源码--插入节点--学习笔记
    zepto源码--width,height--学习笔记
    zepto源码--$.map,$.each,$.grep--学习笔记
    zepto源码--isEmptyObject,isNumeric,inArray,trim--学习笔记
    zepto源码--filtered, contains,funcArg,setAttribute,className,deserializeVale--学习笔记
    zepto源码--qsa--学习笔记
    webstorm开发微信小程序
    第三方博客
    git最基础操作一
    vue-输入框change事件并获取值
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326984.html
Copyright © 2020-2023  润新知