使用压缩池对读取自标准的谁的数据进行压缩,然后将其写到标准输出,谁的写到


//使用压缩池对读取自标准的谁的数据进行压缩,然后将其写到标准输出
package com;


import java.io.IOException;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.compress.CodecPool;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.util.ReflectionUtils;




public class PooledStreamCompressor {


/**
* @param args
* @throws IOException 
* @throws ClassNotFoundException 
*/
public static void main(String[] args) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
String codecClassname = args[0];
Class<?> codecClass = Class.forName(codecClassname);
Configuration conf = new Configuration();

CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance(codecClass, conf);
Compressor compressor = null;
try{
compressor = CodecPool.getCompressor(codec);
CompressionOutputStream out = codec.createOutputStream(System.out, compressor);
IOUtils.copyBytes(System.in, out, 4096, false);
out.finish();
}finally{
CodecPool.returnCompressor(compressor);
}
}


}

相关内容

    暂无相关文章