code: private void validateHeader(boolean validateRecordSize) throws IOException {
      int readmagic = file.readInt();
      // Validate magic number
      if (readmagic != this.magic) {
        file.close();
        throw new IOException("Magic in LinearDiskCache does not match: " + readmagic + " instead of " + this.magic);
      }
      // Validate header size
      if (file.readInt() != this.headersize) {
        file.close();
        throw new IOException("Header size in LinearDiskCache does not match.");
      }
  
      if (validateRecordSize) {
        // Validate record size
        if (file.readInt() != this.recordsize) {
          file.close();
          throw new IOException("Recordsize in LinearDiskCache does not match.");
        }
      } else {
        // or just read it from file
        this.recordsize = file.readInt();
      }
  
      // read the number of records and validate with file size.
      if (file.getFilePointer() != HEADER_POS_SIZE) {
        throw new IOException("Incorrect file position when reading header.");
      }
      this.numrecs = file.readInt();
      if (numrecs < 0 || file.length() != indexToFileposition(numrecs)) {
        throw new IOException("File size and number of records do not agree.");
      }
      // yet another sanity check. We should have read all of our internal header
      // now.
      if (file.getFilePointer() != INTERNAL_HEADER_SIZE) {
        throw new IOException("Incorrect file position after reading header.");
      }
    }
docs: Validates the header and throws an IOException if the header is invalid. If
  validateRecordSize is set to true the record size must match exactly the
  stored record size within the files header, else the record size is read
  from the header and used.
  
  @param validateRecordSize
  @throws IOException