package io.compgen.ngsutils.vcf;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class VCFWriter {
	final private VCFHeader header;
	protected boolean headerWritten = false;
	protected OutputStream out;
	
	public VCFWriter(String filename, VCFHeader header) throws FileNotFoundException {
		this.header = header;
		out = new FileOutputStream(filename);
	}

	public VCFWriter(OutputStream stream, VCFHeader header) throws FileNotFoundException {
		this.header = header;
		out = stream;
	}

	public void close() throws IOException {
		out.flush();
		out.close();
	}
	
	public void write(VCFRecord record) throws IOException {
		if (!headerWritten) {
			header.write(out, true);
			headerWritten = true;
		}
		
		record.write(out);
	}
}

@@ -613,16 +613,97 @@
 ption %7B%0A
+%09%09if (!headerWritten) %7B%0A%09%09%09header.write(out, true);%0A%09%09%09headerWritten = true;%0A%09%09%7D%0A
 %09%09out.fl

write a VCF header if there aren't any records written