int blkId = (block==null) ? NoId : block.getId().intValue() ;
header.putInt(blkId) ;
header.flip() ;
channel.write(header) ;
Adler32 adler = new Adler32() ;
adler.update(header.array()) ;
if ( len > 0 )
{
// Make buffer include it's full length.
// [TxDEV:TODO] This is the full buffer, junk and all.
// This makes the system able to check block sizes (BlockAccess checking).
int bufferLimit = buffer.limit() ;
int bufferPosition = buffer.position() ;
buffer.position(0) ;
buffer.limit(bufferCapacity) ;
// Clear top.
for ( int i = len ; i < bufferCapacity ; i++ )
buffer.put(i, (byte)0) ;
// Write all bytes
channel.write(buffer) ;
adler.update(buffer.array()) ;
buffer.position(bufferPosition) ;
buffer.limit(bufferLimit) ;
}
// checksum
crcTrailer.clear() ;
Bytes.setInt((int)adler.getValue(), crcTrailer.array()) ;
channel.write(crcTrailer) ;
position += Overhead + len + SizeofCRC ; // header + payload + checksum
return posn ;
}