code: private static Record createRecord(ByteBuffer data, int bytesToBlockEnd, Record lastRecord) {
      int bytesToDataEnd = data.remaining();
      RecordType type = RecordType.UNKNOWN;
      int bytes = -1;
      if ((lastRecord.getType() == RecordType.NONE)
          && ((bytesToDataEnd + LevelDbConstants.HEADER_LENGTH) <= bytesToBlockEnd)) {
        // Can write entire record in current block
        type = RecordType.FULL;
        bytes = bytesToDataEnd;
      } else if (lastRecord.getType() == RecordType.NONE) {
        // On first write but can't fit in current block
        type = RecordType.FIRST;
        bytes = bytesToBlockEnd - LevelDbConstants.HEADER_LENGTH;
      } else if (bytesToDataEnd + LevelDbConstants.HEADER_LENGTH <= bytesToBlockEnd) {
        // At end of record
        type = RecordType.LAST;
        bytes = bytesToDataEnd;
      } else {
        // In middle somewhere
        type = RecordType.MIDDLE;
        bytes = bytesToBlockEnd - LevelDbConstants.HEADER_LENGTH;
      }
      return new Record(type, bytes);
    }
docs: Fills a {@link Record} object with data about the physical record to write.
  
  @param data the users data.
  @param bytesToBlockEnd remaining bytes in the current block.
  @param lastRecord a {@link Record} representing the last physical record written.
  @return the {@link Record} with new write data.