private void writeHeader(long capacityInBytes) throws StoreException {
    CRC32 crc = new CRC32();
    ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE);
    buffer.putShort(VERSION);
    buffer.putLong(capacityInBytes);
    crc.update(buffer.array(), 0, HEADER_SIZE - CRC_SIZE);
    buffer.putLong(crc.getValue());
    buffer.flip();
    appendFrom(buffer);
    // Sync header data to disk so we won't have malformed header if there is a power outage.
    try {
      flush();
    } catch (IOException e) {
      StoreErrorCodes errorCode = StoreException.resolveErrorCode(e);
      throw new StoreException(errorCode.toString() + " while flushing log segment header", e, errorCode);
    }
  }
Writes a header describing the segment.
@param capacityInBytes the intended capacity of the segment.
@throws StoreException if there is any store exception while writing to the file.
ambry-store/src/main/java/com/github/ambry/store/LogSegment.java