Пример #1
0
 private void writePropertyBlock(PropertyBlock block) throws IOException {
   byte blockSize = (byte) block.getSize();
   assert blockSize > 0 : blockSize + " is not a valid block size value";
   channel.put(blockSize); // 1
   long[] propBlockValues = block.getValueBlocks();
   for (long propBlockValue : propBlockValues) {
     channel.putLong(propBlockValue);
   }
   /*
    * For each block we need to keep its dynamic record chain if
    * it is just created. Deleted dynamic records are in the property
    * record and dynamic records are never modified. Also, they are
    * assigned as a whole, so just checking the first should be enough.
    */
   if (block.isLight()) {
     /*
      *  This has to be int. If this record is not light
      *  then we have the number of DynamicRecords that follow,
      *  which is an int. We do not currently want/have a flag bit so
      *  we simplify by putting an int here always
      */
     channel.putInt(0); // 4 or
   } else {
     writeDynamicRecords(block.getValueRecords());
   }
 }
Пример #2
0
 private void writePropertyRecord(PropertyRecord record) throws IOException {
   byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue();
   if (record.getRelId() != -1) {
     // Here we add 2, i.e. set the second lsb.
     inUse += Record.REL_PROPERTY.byteValue();
   }
   channel.put(inUse); // 1
   channel.putLong(record.getNextProp()).putLong(record.getPrevProp()); // 8 + 8
   long nodeId = record.getNodeId();
   long relId = record.getRelId();
   if (nodeId != -1) {
     channel.putLong(nodeId); // 8 or
   } else if (relId != -1) {
     channel.putLong(relId); // 8 or
   } else {
     // means this records value has not changed, only place in
     // prop chain
     channel.putLong(-1); // 8
   }
   channel.put((byte) record.numberOfProperties()); // 1
   for (PropertyBlock block : record) {
     assert block.getSize() > 0 : record + " seems kinda broken";
     writePropertyBlock(block);
   }
   writeDynamicRecords(record.getDeletedRecords());
 }
    PropertyBlock readPropertyBlock() throws IOException {
      PropertyBlock toReturn = new PropertyBlock();
      byte blockSize = channel.get(); // the size is stored in bytes // 1
      assert blockSize > 0 && blockSize % 8 == 0 : blockSize + " is not a valid block size value";
      // Read in blocks
      long[] blocks = readLongs(blockSize / 8);
      assert blocks.length == blockSize / 8
          : blocks.length
              + " longs were read in while i asked for what corresponds to "
              + blockSize;
      assert PropertyType.getPropertyType(blocks[0], false).calculateNumberOfBlocksUsed(blocks[0])
              == blocks.length
          : blocks.length
              + " is not a valid number of blocks for type "
              + PropertyType.getPropertyType(blocks[0], false);
      /*
       *  Ok, now we may be ready to return, if there are no DynamicRecords. So
       *  we start building the Object
       */
      toReturn.setValueBlocks(blocks);

      /*
       * Read in existence of DynamicRecords. Remember, this has already been
       * read in the buffer with the blocks, above.
       */
      if (readDynamicRecords(toReturn, PROPERTY_BLOCK_DYNAMIC_RECORD_ADDER) == -1) {
        return null;
      }

      return toReturn;
    }
Пример #4
0
 @Override
 public void processProperty(RecordStore<PropertyRecord> store, PropertyRecord property) {
   int size = 0;
   for (PropertyBlock block : property) {
     update(typeHistogram, block.getType());
     size++;
   }
   update(sizeHistogram, size);
 }