Here you can find the source of getBufferedWriterOnFile(File file, String format)
public static BufferedWriter getBufferedWriterOnFile(File file, String format) throws FileNotFoundException, IOException
//package com.java2s; /**//from w w w .j ava 2s .co m * Copyright (C) 2016 the Knime4NGS contributors. * Website: http://ibisngs.github.io/knime4ngs * * This file is part of the KNIME4NGS KNIME extension. * * The KNIME4NGS extension is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.zip.GZIPOutputStream; public class Main { public static BufferedWriter getBufferedWriterOnFile(File file, String format) throws FileNotFoundException, IOException { BufferedWriter bw; if (format.toLowerCase().equals("auto")) { format = file.getName(); } if (format.toLowerCase().endsWith("gz")) { bw = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))); } // else if(format.toLowerCase().endsWith("bz2")) // { // bw = new BufferedWriter(new OutputStreamWriter( // new BZip2OutputStream(new FileOutputStream(file)))); // } else { bw = new BufferedWriter(new FileWriter(file)); } return bw; } }