private boolean headerSet = false;
public Map<String, Object> encodeAll(OutputStream stream, Iterator<? extends PicardAlignment> alignments) {
SAMFileWriterImpl writer = new SAMTextWriter(stream);
while (alignments.hasNext()) {
PicardAlignment samAl = alignments.next();
if (!headerSet) {
writer.setSortOrder(SAMFileHeader.SortOrder.unsorted, true);
writer.setHeader(samAl.getRecord().getHeader());
headerSet = true;
}
writer.addAlignment(samAl.getRecord());
}
writer.close();
return null;
}