crBlock.setRecordCount(records.size());
ByteArrayOutputStream bhBAOS = new ByteArrayOutputStream();
CramRecordBlockWriter w = new CramRecordBlockWriter(bhBAOS);
w.write(crBlock);
Block block = new Block();
block.contentType = ContentType.HEADER.getContentType();
block.contentId = 0;
block.data = bhBAOS.toByteArray();
block.method = CompressionMethod.GZIP.byteValue();
blocks.add(block);
CramRecordCodec codec = buildCodec(cramHeader, crBlock, provider);
List<Short> tagCodes = new ArrayList<Short>();
tagCodes.add(SAMTagUtil.getSingleton().makeBinaryTag("OQ"));
HashMap<Integer, MyDataOutputStream> osMap = new HashMap<Integer, MyDataOutputStream>();
osMap.put((int)ContentType.QUAL.getContentType(), new MyDataOutputStream());
for (short code : tagCodes)
osMap.put((int) code, new MyDataOutputStream());
codec.osMap = osMap;
int counter = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BitOutputStream bos = new DefaultBitOutputStream(baos);
Iterator<CramRecord> iterator = records.iterator();
long time1 = System.nanoTime();
while (iterator.hasNext()) {
for (int i = 0; i < recordsPerSlice; i++) {
if (!iterator.hasNext())
break;
CramRecord record = iterator.next();
codec.write(bos, record);
counter++;
}
bos.close();
block = new Block();
block.contentType = ContentType.CORE.getContentType();
block.contentId = 0;
block.data = baos.toByteArray();
block.method = CompressionMethod.GZIP.byteValue();
blocks.add(block);
baos.reset();
for (Integer key : osMap.keySet()) {
block = new Block();
if (key > ContentType.TAG.getContentType()) {
block.contentType = ContentType.TAG.getContentType();
block.contentId = key.shortValue();
} else {
block.contentType = key.byteValue();