public static OutputStream createCompressedStream(JobConf jc, OutputStream out,
      boolean isCompressed) throws IOException {
    if (isCompressed) {
      Class<? extends CompressionCodec> codecClass = FileOutputFormat.getOutputCompressorClass(jc,
          DefaultCodec.class);
      CompressionCodec codec = ReflectionUtil.newInstance(codecClass, jc);
      return codec.createOutputStream(out);
    } else {
      return (out);
    }
  }
Convert an output stream to a compressed output stream based on codecs codecs in the Job
Configuration. Caller specifies directly whether file is compressed or not

@param jc
         Job Configuration
@param out
         Output Stream to be converted into compressed output stream
@param isCompressed
         whether the output stream needs to be compressed or not
@return compressed output stream
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java