code: public static BufferedWriter newBufferedWriter(Path path) throws IOException {
          FileUtils.checkDirectory(path.getParent());
          BufferedWriter bufferedWriter;
          if (path.toFile().getName().endsWith(".gz")) {
              bufferedWriter = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(path.toFile()))));
          } else {
              bufferedWriter = Files.newBufferedWriter(path, Charset.defaultCharset());
          }
          return bufferedWriter;
      }
docs: This method is able to determine whether a file is GZipped and return a {@link BufferedWriter} in any case.
  
  @param path to be write
  @return BufferedWriter object
  @throws java.io.IOException IOException