欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

求助:Hadoop解压缩报错 java.io.IOException: incorrect header check

程序员文章站 2022-07-09 17:13:28
...

若有大佬路过,烦请留下只言片语,小白不胜感激~
源代码如下:

package com.psy.mr.compress;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionCodecFactory;
import org.apache.hadoop.io.compress.CompressionInputStream;
import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.util.ReflectionUtils;

import java.io.*;

public class TestCompress {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 压缩
//        compress("e:/hello.txt","org.apache.hadoop.io.compress.DefaultCodec");
        deCompresses("e:/hello.txt.deflate");
    }

    private static void deCompresses(String fileName) throws IOException {
        // 1.压缩方式检查
        CompressionCodecFactory factory = new CompressionCodecFactory(new Configuration());
        CompressionCodec codec = factory.getCodec(new Path(fileName));
        if (codec == null){
            System.out.println("cannot process this kind of compression method");
            return;
        }
        // 获取输入流
        CompressionInputStream cis = codec.createInputStream(new FileInputStream(new File(fileName)));
        // 获取输出流
        FileOutputStream fos = new FileOutputStream(new File(fileName + ".decode"));
        // 流的对拷
        IOUtils.copyBytes(cis,fos,1024*1024*5,false);
        // 关闭资源
        IOUtils.closeStream(fos);
        IOUtils.closeStream(cis);

    }

    private static void compress(String fileName, String method) throws IOException, ClassNotFoundException {
        //获取输入流
        FileInputStream fis = new FileInputStream(new File(fileName));
        //获取输出流
        Class<?> classCodec = Class.forName(method);
        CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(classCodec, new Configuration());
        FileOutputStream fos = new FileOutputStream(new File(fileName + codec.getDefaultExtension()));
        CompressionOutputStream cos = codec.createOutputStream(fos);
        //流的对拷
        IOUtils.copyBytes(fis,fos,1024*1024*5,false);
        //关闭资源
        IOUtils.closeStream(cos);
        IOUtils.closeStream(fos);
        IOUtils.closeStream(fis);
    }
}

然后报错如下:
求助:Hadoop解压缩报错 java.io.IOException: incorrect header check

相关标签: 错误总结