public SAMRecord decode(final int recordLength) { if (recordLength < BAMFileConstants.FIXED_BLOCK_SIZE) { throw new SAMFormatException("Invalid record length: " + recordLength); } final int referenceID = this.binaryCodec.readInt(); final int coordinate = this.binaryCodec.readInt() + 1; final short readNameLength = this.binaryCodec.readUByte(); final short mappingQuality = this.binaryCodec.readUByte(); final int bin = this.binaryCodec.readUShort(); final int cigarLen = this.binaryCodec.readUShort(); final int flags = this.binaryCodec.readUShort(); final int readLen = this.binaryCodec.readInt(); final int mateReferenceID = this.binaryCodec.readInt(); final int mateCoordinate = this.binaryCodec.readInt() + 1; final int insertSize = this.binaryCodec.readInt(); final byte[] restOfRecord = new byte[recordLength - BAMFileConstants.FIXED_BLOCK_SIZE]; this.binaryCodec.readBytes(restOfRecord); final BAMRecord ret = this.samRecordFactory.createBAMRecord( header, referenceID, coordinate, readNameLength, mappingQuality, bin, cigarLen, flags, readLen, mateReferenceID, mateCoordinate, insertSize, restOfRecord); if (null != header) { // don't reset a null header as this will clobber the reference and mate reference indices ret.setHeader(header); } return ret; } }