Hadoop Compression解压缩架构的学习

           Hadoop的Compressor解压缩模块是Hadoop Common IO模块中又一大的模块。虽然说在现实生活中,我们使用压缩工具等的使用场景并不是那么多。或许在我们潜在的意识里,压缩的概念就停留在一些压缩种类上,zip,gzip,bizp等等不同类型的压缩,分别具有不同的压缩比,效率比等等。也许当你看完本篇本人对于Hadoop的压缩框架的学习之后,你一定会有所收获。

          压缩对于数据的传输室至关重要的,同样对于存储来说也大大的提高了效率,在Hadoop系统中目前支持的压缩算法包括1,gzip 2.bzip 3.snappy4.default系统默认算法。这些压缩工具的体现都是通过一个叫CompressionCodec的对象来体现的。先来看看这个类:

/**
 * This class encapsulates a streaming compression/decompression pair.
 */
public interface CompressionCodec {
  CompressionOutputStream createOutputStream(OutputStream out) throws IOException;
  
  CompressionOutputStream createOutputStream(OutputStream out, 
                                             Compressor compressor) throws IOException;

  Class<? extends Compressor> getCompressorType();
  
  Compressor createCompressor();
  
  CompressionInputStream createInputStream(InputStream in) throws IOException;
  
  CompressionInputStream createInputStream(InputStream in, 
                                           Decompressor decompressor) throws IOException;

  Class<? extends Decompressor> getDecompressorType();
  
  Decompressor createDecompressor();
  
  String getDefaultExtension();
}
这是一个接口,里面定义了很多的方法,我主要把他归为2类,

1个是Compressor和Decompressor解压缩的构造,

1个是CompressionInputStream,CompressionOutputStream压缩输入输出流。

其实2者很像,因为压缩输入输出流的很多操作也是基于上面的压缩器,解压器的操作实现的。具体压缩算法的表现都是继承与这个基类。看一下比较庞大的结构图:


可以看到在每种Codec子类中,都会有解压缩器的实现和压缩输入输出流的构造。然后把这种压缩算法类保存在了一个Codec的工厂中,通过统一的接口调用。

public class CompressionCodecFactory {

  public static final Log LOG =
    LogFactory.getLog(CompressionCodecFactory.class.getName());

  /**
   * A map from the reversed filename suffixes to the codecs.
   * This is probably overkill, because the maps should be small, but it 
   * automatically supports finding the longest matching suffix.
   * 所有的解压缩编码类放入 codecs Map图中,CompressionCodec是一个基类,
   * 允许添加上其所继承的子类
   */
  private SortedMap<String, CompressionCodec> codecs = null;
初始化的时候,可以根据配置加入自己希望的压缩算法种类:

/**
   * Find the codecs specified in the config value io.compression.codecs 
   * and register them. Defaults to gzip and zip.
   * 根据配置初始化压缩编码工厂,默认添加的是gzip和zip编码类
   */
  public CompressionCodecFactory(Configuration conf) {
    codecs = new TreeMap<String, CompressionCodec>();
    List<Class<? extends CompressionCodec>> codecCl
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值