hadoop文件压缩和解压缩的一个简单测试程序:
package org.myorg;
import java.io.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.util.ReflectionUtils;
public class StreamCompressor {
public static void main(String[] args) throws Exception{
String codecClassname = args[0];
Class<?> codecClass = Class.forName(codecClassname);
Configuration conf = new Configuration();
CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance(codecClass, conf);
//把str里到数据压缩后放到text文件里
CompressionOutputStream out = codec.createOutputStream(new FileOutputStream(new File("text")));
String str = "try compress and decompress";
byte[] bytes = new byte[1024];
bytes = str.getBytes();
// IOUtils.copyBytes(new ByteArrayInpu