code: public static DataOutputStream getDataOutputStream(Configuration conf,Path file, Progressable progress, boolean compressed, Class<? extends CompressionCodec> compressorClass) throws IOException {
  if (!compressed) { // uncompressed
  	FileSystem fs = file.getFileSystem(conf);
          return fs.create(file, progress);
  } else { // compressed (note partially adapted from TextOutputFormat)
        Class<? extends CompressionCodec> codecClass = compressorClass;
        // create the named codec
        CompressionCodec codec = ReflectionUtils.newInstance(codecClass, conf);
        // provide proper file extension
        Path compressedFile = file.suffix(codec.getDefaultExtension());
        // build the filename including the extension
        FileSystem fs = compressedFile.getFileSystem(conf);
        return new DataOutputStream(codec.createOutputStream(fs.create(compressedFile, progress)));
  }
  }
docs: /*
  Creates for the file to be written and outputstream and takes - depending on the configuration - take of compression. Set for compression the following options:
  mapreduce.output.fileoutputformat.compress true/false
  mapreduce.output.fileoutputformat.compress.codec java class of compression codec
  
  Note that some formats may use already internal compression so that additional compression does not lead to many benefits
  
  @param conf Configuration of Job
  @param file file to be written
  
  @return outputstream of the file