DynamicRecord readDynamicRecord() throws IOException {
      // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long)
      long id = channel.getLong();
      assert id >= 0 && id <= (1l << 36) - 1 : id + " is not a valid dynamic record id";
      int type = channel.getInt();
      byte inUseFlag = channel.get();
      boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0;

      DynamicRecord record = new DynamicRecord(id);
      record.setInUse(inUse, type);
      if (inUse) {
        record.setStartRecord((inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0);
        int nrOfBytes = channel.getInt();
        assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1)
            : nrOfBytes + " is not valid for a number of bytes field of " + "a dynamic record";
        long nextBlock = channel.getLong();
        assert (nextBlock >= 0 && nextBlock <= (1l << 36 - 1))
                || (nextBlock == Record.NO_NEXT_BLOCK.intValue())
            : nextBlock + " is not valid for a next record field of " + "a dynamic record";
        record.setNextBlock(nextBlock);
        byte data[] = new byte[nrOfBytes];
        channel.get(data, nrOfBytes);
        record.setData(data);
      }
      return record;
    }
 void writeDynamicRecord(DynamicRecord record) throws IOException {
   // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long)
   if (record.inUse()) {
     byte inUse = Record.IN_USE.byteValue();
     if (record.isStartRecord()) {
       inUse |= Record.FIRST_IN_CHAIN.byteValue();
     }
     channel
         .putLong(record.getId())
         .putInt(record.getType())
         .put(inUse)
         .putInt(record.getLength())
         .putLong(record.getNextBlock());
     byte[] data = record.getData();
     assert data != null;
     channel.put(data, data.length);
   } else {
     byte inUse = Record.NOT_IN_USE.byteValue();
     channel.putLong(record.getId()).putInt(record.getType()).put(inUse);
   }
 }