private int compress(String argv[], Configuration conf) throws IOException {
    int i = 0;
    String cmd = argv[i++];
    String srcf = argv[i++];
    String dstf = argv[i++];

    Path srcPath = new Path(srcf);
    FileSystem srcFs = srcPath.getFileSystem(getConf());
    Path dstPath = new Path(dstf);
    FileSystem dstFs = dstPath.getFileSystem(getConf());

    // Create codec
    CompressionCodecFactory factory = new CompressionCodecFactory(conf);
    CompressionCodec codec = factory.getCodec(dstPath);
    if (codec == null) {
      System.err.println(cmd.substring(1) + ": cannot find compression codec for "
          + dstf);
      return 1;
    }

    // open input stream
    InputStream in = srcFs.open(srcPath);

    // Create compression stream
    OutputStream out = dstFs.create(dstPath);
    out = codec.createOutputStream(out);

    IOUtils.copyBytes(in, out, conf, true);

    return 0;
  }
private int compress ( String argv [ ] , Configuration conf ) throws IOException { int i = 0 ; String cmd = argv [ i ++ ] ; String srcf = argv [ i ++ ] ; String dstf = argv [ i ++ ] ; Path srcPath = new Path ( srcf ) ; FileSystem srcFs = srcPath . getFileSystem ( getConf ( ) ) ; Path dstPath = new Path ( dstf ) ; FileSystem dstFs = dstPath . getFileSystem ( getConf ( ) ) ; CompressionCodecFactory factory = new CompressionCodecFactory ( conf ) ; CompressionCodec codec = factory . getCodec ( dstPath ) ; if ( codec == null ) { System . err . println ( cmd . substring ( 1 ) + ": cannot find compression codec for " + dstf ) ; return 1 ; } InputStream in = srcFs . open ( srcPath ) ; OutputStream out = dstFs . create ( dstPath ) ; out = codec . createOutputStream ( out ) ; IOUtils . copyBytes ( in , out , conf , true ) ; return 0 ; }
Compress a file.