ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(baos);
BufferedOutputStream bos = new BufferedOutputStream(gos) ;
ExternalByteArrayCodec c = new ExternalByteArrayCodec(
bos, null);
int maxRecords = 100000;
int counter = 0;
long writeNanos = 0;
java.util.List<SAMRecord> records = new ArrayList<SAMRecord>(2*maxRecords) ;
while (iterator.hasNext() && counter++ <= maxRecords) {
SAMRecord r = iterator.next();
records.add(r) ;
byte[] scores = r.getBaseQualities();
long time1 = System.nanoTime();
c.write(null, scores);
writeNanos += System.nanoTime() - time1;
}
bos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
GZIPInputStream gis = new GZIPInputStream(bais);
c = new ExternalByteArrayCodec(null, new BufferedInputStream(gis));
long bases = 0;
long readNanos = 0 ;
for (counter = 0; counter < records.size(); counter++) {
SAMRecord record = records.get(counter) ;
long time4 = System.nanoTime();
bases += c.read(null, record.getReadLength()).length;
readNanos += System.nanoTime() - time4 ;
}
System.out.printf("ExternalByteArrayCodec: bases %d, %d ms, %d ms.\n", bases,
(writeNanos) / 1000000, (readNanos) / 1000000);