SAMFileWriterFactory factoryOrNull, OutputStream os,
SAMFileHeader header, boolean printHeader) throws IOException {
SAMFileWriter writer = null;
if (printHeader) {
if (factoryOrNull == null)
factoryOrNull = new SAMFileWriterFactory();
writer = factoryOrNull.makeSAMWriter(header, true, os);
} else {
SwapOutputStream sos = new SwapOutputStream();
final SAMTextWriter ret = new SAMTextWriter(sos);